Skip to content

Commit

Permalink
Merge pull request #790 from digirati-co-uk/feature/configurable-expo…
Browse files Browse the repository at this point in the history
…rt-reviews

Added ability to configure exports to include reviews
  • Loading branch information
stephenwf authored Sep 29, 2023
2 parents 5989bf3 + 463834c commit 68b0a5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const canvasModelExport: ExportConfig = {
filePerProject: true,
defaultValues: {
format: 'json',
reviews: false,
},
editor: {
project_id: {
Expand All @@ -34,6 +35,12 @@ export const canvasModelExport: ExportConfig = {
{ value: 'capture-model-with-pages-resolved', text: 'capture-model-with-pages-resolved' },
],
} as any,
reviews: {
type: 'checkbox-field',
label: 'Submission filter',
inlineLabel: 'Include reviews',
description: 'Include submissions being reviewed in the export.',
} as any,
},
},
hookConfig(subject, options, config) {
Expand All @@ -58,6 +65,7 @@ export const canvasModelExport: ExportConfig = {
const resp = await options.api.getSiteCanvasPublishedModels(subject.id, {
project_id: project?.id,
format: options.config?.format || 'json',
reviews: !!options.config?.reviews,
});

// @todo it would be better if getSiteCanvasPublishedModels returned a project-id if known.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const projectCsvSimpleExport: ExportConfig = {
outputIdAsString: true,
clearable: true,
},
reviews: {
type: 'checkbox-field',
label: 'Submission filter',
inlineLabel: 'Include reviews',
description: 'Include submissions being reviewed in the export.',
} as any,
},
};
}
Expand All @@ -44,7 +50,7 @@ export const projectCsvSimpleExport: ExportConfig = {
// This will probably be a pretty long-running task.

const allPublished = await options.api.getProjectFieldsRaw(subject.id, {
status: 'approved',
status: options.config.reviews ? 'all' : 'approved',
entity: options.config.entity,
});

Expand Down
9 changes: 7 additions & 2 deletions services/madoc-ts/src/routes/site/site-published-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export type SitePublishedModelsQuery = {
selectors?: boolean;
derived_from?: string;
version?: 'source' | '3.0' | '2.1';
reviews?: boolean;
m?: string;
};

export const sitePublishedModels: RouteMiddleware<{ slug: string; id: string }> = async context => {
const { site, siteApi } = context.state;
const { site, siteApi, jwt } = context.state;
const {
derived_from,
format,
Expand All @@ -43,6 +44,8 @@ export const sitePublishedModels: RouteMiddleware<{ slug: string; id: string }>
} = context.query as SitePublishedModelsQuery;
const selectors = castBool(context.query.selectors);

const isAdmin = jwt?.scope.indexOf('site.admin') !== -1;

if (version !== 'source' && !manifestId) {
throw new RequestError('Cannot request models with version and no manifest ID');
}
Expand Down Expand Up @@ -102,8 +105,10 @@ export const sitePublishedModels: RouteMiddleware<{ slug: string; id: string }>

const ms = [];

const published = isAdmin ? !castBool(context.query.reviews) : true;

for (const model of models) {
ms.push(siteApi.getCaptureModel(model.id, { published: true }));
ms.push(siteApi.getCaptureModel(model.id, { published }));
}

const defaultOptions = {
Expand Down

0 comments on commit 68b0a5f

Please sign in to comment.