diff --git a/client/controllers/AddToPlanningController.tsx b/client/controllers/AddToPlanningController.tsx index dfc249374..161dc905e 100644 --- a/client/controllers/AddToPlanningController.tsx +++ b/client/controllers/AddToPlanningController.tsx @@ -4,13 +4,12 @@ import React from 'react'; import ReactDOM from 'react-dom'; import {Provider} from 'react-redux'; import {ModalsContainer} from '../components'; -import {locks} from '../actions'; import {planning} from '../actions'; import {get, isEmpty, isNumber} from 'lodash'; import {registerNotifications, getErrorMessage, isExistingItem} from '../utils'; import {WORKSPACE, MODALS, MAIN} from '../constants'; import {GET_LABEL_MAP} from 'superdesk-core/scripts/apps/workspace/content/constants'; -import {planningApi} from '../superdeskApi'; +import {planningApi, superdeskApi} from '../superdeskApi'; const DEFAULT_PLANNING_SCHEMA = { anpa_category: {required: true}, @@ -193,11 +192,14 @@ export class AddToPlanningController { } loadArchiveItem() { - return this.api.find('archive', this.item._id) - .then((newsItem) => { + return Promise.all([ + superdeskApi.entities.contentProfile.get(this.item.profile), + this.api.find('archive', this.item._id), + ]) + .then(([contentProfile, newsItem]) => { const errMessages = []; const profile = planningProfile(this.store.getState()); - const schema = get(profile, 'schema') || DEFAULT_PLANNING_SCHEMA; + const planningSchema = profile.schema || DEFAULT_PLANNING_SCHEMA; const requiredError = (field) => this.gettext('[{{ field }}] is a required field') .replace('{{ field }}', field); const labels = GET_LABEL_MAP(this.gettext); @@ -206,10 +208,13 @@ export class AddToPlanningController { errMessages.push(this.gettext('Item already linked to a Planning item')); } - Object.keys(schema) - .filter((field) => get(schema[field], 'required') && - isEmpty(get(newsItem, field)) && - !isNumber(get(newsItem, field))) + Object.keys(planningSchema) + .filter((field) => ( + contentProfile.schema[field] != null && + planningSchema[field]?.required === true && + isEmpty(newsItem[field]) && + !isNumber(newsItem[field]) + )) .forEach((field) => { errMessages.push(requiredError(labels[field] || field)); }); diff --git a/client/utils/testApi.ts b/client/utils/testApi.ts index 6e2374ab8..6df65e757 100644 --- a/client/utils/testApi.ts +++ b/client/utils/testApi.ts @@ -42,7 +42,35 @@ Object.assign(superdeskApi, { }, components: { SelectUser: sinon.stub().returns('
Stubbed SelectUser Component
'), - } + }, + entities: { + contentProfile: { + get: sinon.stub().returns(Promise.resolve({ + schema: { + slugline: {maxlength: 24, type: 'string', required: true}, + relatedItems: {}, + genre: {type: 'list'}, + anpa_take_key: {type: 'string'}, + place: {type: 'list'}, + priority: {type: 'integer'}, + urgency: {type: 'integer'}, + anpa_category: {type: 'list', required: true}, + subject: {type: 'list', required: true}, + company_codes: {type: 'list'}, + ednote: {type: 'string'}, + headline: {maxlength: 42, type: 'string', required: true}, + sms: {maxlength: 160, type: 'string'}, + abstract: {maxlength: 160, type: 'string'}, + body_html: {required: true, type: 'string'}, + byline: {type: 'string'}, + dateline: {type: 'dict', required: true}, + sign_off: {type: 'string'}, + footer: {}, + body_footer: {type: 'string'}, + }, + })), + }, + }, }); Object.assign(planningApi, {