diff --git a/scripts/api/article.ts b/scripts/api/article.ts index 1c07b756a8..db86468547 100644 --- a/scripts/api/article.ts +++ b/scripts/api/article.ts @@ -16,7 +16,14 @@ import {notify} from 'core/notify/notify'; import ng from 'core/services/ng'; import {gettext} from 'core/utils'; import {flatMap, trim} from 'lodash'; -import {IArticle, IDangerousArticlePatchingOptions, IDesk, IStage, onPublishMiddlewareResult} from 'superdesk-api'; +import { + IArticle, + IAuthoringActionType, + IDangerousArticlePatchingOptions, + IDesk, + IStage, + onPublishMiddlewareResult, +} from 'superdesk-api'; import {duplicateItems} from './article-duplicate'; import {fetchItems, fetchItemsToCurrentDesk} from './article-fetch'; import {patchArticle} from './article-patch'; @@ -378,6 +385,12 @@ function get(id: IArticle['_id']): Promise { return dataApi.findOne('archive', id); } +function itemAction(_article: IArticle): {[key in IAuthoringActionType]: boolean} { + const authoring = ng.get('authoring'); + + return authoring.itemAction(_article); +} + function isEditable(_article: IArticle): boolean { const itemState: ITEM_STATE = _article.state; const authoring = ng.get('authoring'); @@ -424,6 +437,7 @@ interface IArticleApi { */ isPublished(article: IArticle, includeScheduled?: boolean): boolean; + itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean}; isKilled(article: IArticle): boolean; isIngested(article: IArticle): boolean; isPersonal(article: IArticle): boolean; @@ -491,6 +505,7 @@ export const article: IArticleApi = { rewrite, isLocked, isEditable, + itemAction, isLockedInCurrentSession, isLockedInOtherSession, isLockedByCurrentUser, diff --git a/scripts/apps/authoring/authoring/authoring-topbar-react.tsx b/scripts/apps/authoring/authoring/authoring-topbar-react.tsx index 8eb6f525b1..d5402978c7 100644 --- a/scripts/apps/authoring/authoring/authoring-topbar-react.tsx +++ b/scripts/apps/authoring/authoring/authoring-topbar-react.tsx @@ -1,14 +1,13 @@ import React from 'react'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {flatMap} from 'lodash'; import {extensions} from 'appConfig'; -import {IAuthoringAction} from './services/AuthoringWorkspaceService'; import {registerToReceivePatches, unregisterFromReceivingPatches} from 'apps/authoring-bridge/receive-patches'; import {dataApi} from 'core/helpers/CrudManager'; interface IProps { article: IArticle; - action: IAuthoringAction; + action: IAuthoringActionType; onChange(article: IArticle): void; } diff --git a/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx b/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx index a8bdcbeee5..aef425f97e 100644 --- a/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx +++ b/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx @@ -1,8 +1,7 @@ import React from 'react'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {flatMap} from 'lodash'; import {extensions} from 'appConfig'; -import {IAuthoringAction} from './services/AuthoringWorkspaceService'; import {dataApi} from 'core/helpers/CrudManager'; import {CreatedInfo} from './created-info'; import {ModifiedInfo} from './modified-info'; @@ -11,7 +10,7 @@ const defaultToolbarItems: Array> = [Cr interface IProps { article: IArticle; - action: IAuthoringAction; + action: IAuthoringActionType; onChange(article: IArticle): void; } diff --git a/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts b/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts index 69a5f769b1..6e82484013 100644 --- a/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts +++ b/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts @@ -1,11 +1,9 @@ import {includes} from 'lodash'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {appConfig, extensions} from 'appConfig'; import {sdApi} from 'api'; import {notNullOrUndefined} from 'core/helpers/typescript-helpers'; -export type IAuthoringAction = 'view' | 'edit' | 'kill' | 'takedown' | 'correct'; - /** * @ngdoc service * @module superdesk.apps.authoring @@ -24,7 +22,7 @@ export class AuthoringWorkspaceService { private $window: any; item: any; - action: IAuthoringAction; + action: IAuthoringActionType; state: any; widgetVisibilityCheckerFuntions: Array<(arg) => Promise>; @@ -102,7 +100,7 @@ export class AuthoringWorkspaceService { */ edit( item: {_id: IArticle['_id'], _type?: IArticle['_type'], state?: IArticle['state']}, - action?: IAuthoringAction, + action?: IAuthoringActionType, ) { if (item) { // disable edit of external ingest sources that are not editable (editFeaturedImage false or not available) @@ -320,7 +318,7 @@ export class AuthoringWorkspaceService { /** * Fetch item by id and start editing it */ - private authoringOpen(itemId, action: IAuthoringAction, repo?, state?) { + private authoringOpen(itemId, action: IAuthoringActionType, repo?, state?) { return this.authoring.open(itemId, action === 'view', repo, action, state) .then((item: IArticle) => { this.item = item; diff --git a/scripts/core/get-superdesk-api-implementation.tsx b/scripts/core/get-superdesk-api-implementation.tsx index cb644addfa..b7abd14f29 100644 --- a/scripts/core/get-superdesk-api-implementation.tsx +++ b/scripts/core/get-superdesk-api-implementation.tsx @@ -283,6 +283,7 @@ export function getSuperdeskApiImplementation( patch: patchArticle, isArchived: sdApi.article.isArchived, isPublished: (article) => sdApi.article.isPublished(article), + itemAction: (article) => sdApi.article.itemAction(article), }, desk: { getStagesOrdered: (deskId: string) => diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index c9be4cf1b3..5d14664bf0 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -2328,6 +2328,34 @@ declare module 'superdesk-api' { type IResponseHandler = (res: IRestApiResponse) => any; + export type IAuthoringActionType = + 'view' + | 'kill' + | 'correct' + | 'deschedule' + | 'unlinkUpdate' + | 'cancelCorrection' + | 'export' + | 'unspike' + | 'mark_item_for_desks' + | 'mark_item_for_highlight' + | 'new_take' + | 're_write' + | 'save' + | 'edit' + | 'mark_item' + | 'duplicate' + | 'duplicateTo' + | 'copy' + | 'package_item' + | 'multi_edit' + | 'send' + | 'create_broadcast' + | 'add_to_current' + | 'resend' + | 'set_label' + | 'takedown'; + export interface IDataProvider { update: () => void; stop: () => void; @@ -2691,6 +2719,7 @@ declare module 'superdesk-api' { isArchived(article: IArticle): boolean; isPublished(article: IArticle): boolean; + itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean}; }; contentProfile: { get(id: string): Promise;