Skip to content

Commit

Permalink
Merge pull request #2236 from navikt/unpublish-old-news
Browse files Browse the repository at this point in the history
Funksjonalitet for avpublisering av gamle nyheter og pressemeldinger
  • Loading branch information
anders-nom authored Oct 31, 2024
2 parents 01d7fae + 273b3f2 commit 86977db
Show file tree
Hide file tree
Showing 65 changed files with 525 additions and 142 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
'@typescript-eslint/no-unused-vars': [
'warn',
{
'varsIgnorePattern': '^_',
'varsIgnorePattern': '^_$',
'argsIgnorePattern': '^_$',
},
],
'@typescript-eslint/no-var-requires': 'off',
Expand Down
4 changes: 4 additions & 0 deletions .xp-codegen/tasks/archive-old-news/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// WARNING: This file was automatically generated by "no.item.xp.codegen". You may lose your changes if you edit it.
export type ArchiveOldNews = {

};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRepoConnection } from '../../../../lib/utils/repo-utils';
import { getRepoConnection } from '../../../../lib/repos/repo-utils';
import thymeleafLib from '/lib/thymeleaf';
import { sanitize } from '/lib/xp/common';
import { Content } from '/lib/xp/content';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NON_LOCALIZED_QUERY_FILTER } from '../../../lib/localization/layers-rep
import { contentTypesRenderedByEditorFrontend } from '../../../lib/contenttype-lists';
import dayjs from '/assets/dayjs/1.11.9/dayjs.min.js';
import utc from '/assets/dayjs/1.11.9/plugin/utc.js';
import { getContentProjectIdFromRepoId, getRepoConnection } from '../../../lib/utils/repo-utils';
import { getContentProjectIdFromRepoId, getRepoConnection } from '../../../lib/repos/repo-utils';
import { notNullOrUndefined } from '../../../lib/utils/mixed-bag-of-utils';
import { DashboardContentInfo } from './utils/types';
import { ContentDescriptor } from '../../../types/content-types/content-config';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryDsl, RangeDslExpression } from '/lib/xp/node';
import { UserKey } from '/lib/xp/auditlog';
import { getRepoConnection } from '../../../../../lib/utils/repo-utils';
import { getRepoConnection } from '../../../../../lib/repos/repo-utils';
import { AuditLogArchived, AuditLogPublished, AuditLogUnpublished } from '../types';
import { Dayjs } from '/assets/dayjs/1.11.9/dayjs.min.js';
import { forceArray } from '../../../../../lib/utils/array-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as contentLib from '/lib/xp/content';
import { Content } from '/lib/xp/content';
import { ContentLogData, DashboardContentInfo } from './types';
import dayjs from '/assets/dayjs/1.11.9/dayjs.min.js';
import { getContentProjectIdFromRepoId, getRepoConnection } from '../../../../lib/utils/repo-utils';
import { getContentProjectIdFromRepoId, getRepoConnection } from '../../../../lib/repos/repo-utils';
import { fixDateFormat } from '../../../../lib/utils/datetime-utils';
import { APP_DESCRIPTOR } from '../../../../lib/constants';
import { stripPathPrefix } from '../../../../lib/paths/path-utils';
Expand All @@ -29,7 +29,8 @@ const contentTypeNameMap = contentTypesToShow.reduce<Record<string, string>>((ac
return acc;
}, {});

export const layerStr = (repo: string) => (repo !== 'default' ? ` [${repo.replace('navno-', '')}]` : '');
export const layerStr = (repo: string) =>
repo !== 'default' ? ` [${repo.replace('navno-', '')}]` : '';

const transformToContentData = (
contentWithLog: ContentWithLog,
Expand Down
90 changes: 90 additions & 0 deletions src/main/resources/lib/archiving/archive-old-news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { QueryDsl } from '/lib/xp/node';
import { createOrUpdateSchedule } from '../scheduling/schedule-job';
import { APP_DESCRIPTOR } from '../constants';
import { ContentDescriptor } from '../../types/content-types/content-config';
import { MainArticle } from '@xp-types/site/content-types';
import { runInContext } from '../context/run-in-context';
import { findAndArchiveOldContent } from './batch-archiving';

const ONE_YEAR_MS = 1000 * 3600 * 24 * 365;
const TWO_YEARS_MS = ONE_YEAR_MS * 2;

const MONDAY_0700_CRON = '0 7 * * 1';

const pressReleasesQuery: QueryDsl = {
boolean: {
must: [
{
term: {
field: 'type',
value: 'no.nav.navno:main-article' satisfies ContentDescriptor,
},
},
{
term: {
field: 'data.contentType',
value: 'pressRelease' satisfies MainArticle['contentType'],
},
},
],
},
} as const;

const newsQuery: QueryDsl = {
boolean: {
should: [
{
boolean: {
must: [
{
term: {
field: 'type',
value: 'no.nav.navno:main-article' satisfies ContentDescriptor,
},
},
{
term: {
field: 'data.contentType',
value: 'news' satisfies MainArticle['contentType'],
},
},
],
},
},
{
term: {
field: 'type',
value: 'no.nav.navno:current-topic-page' satisfies ContentDescriptor,
},
},
],
},
} as const;

export const archiveOldNews = () =>
runInContext({ asAdmin: true }, () => {
findAndArchiveOldContent({
query: pressReleasesQuery,
maxAgeMs: TWO_YEARS_MS,
jobName: 'pressReleases',
});

findAndArchiveOldContent({
query: newsQuery,
maxAgeMs: ONE_YEAR_MS,
jobName: 'news',
});
});

export const activateArchiveNewsSchedule = () => {
createOrUpdateSchedule({
jobName: 'archive-old-news',
jobSchedule: {
type: 'CRON',
value: MONDAY_0700_CRON,
timeZone: 'GMT+2:00',
},
taskDescriptor: `${APP_DESCRIPTOR}:archive-old-news`,
taskConfig: {},
});
};
Loading

0 comments on commit 86977db

Please sign in to comment.