Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverages created via Event creation form should be directly posted alongside with the associated Planning item [SDESK-7051] #1849

Merged
merged 12 commits into from
Sep 11, 2023
4 changes: 4 additions & 0 deletions client/api/editor/item_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export function getEventsInstance(type: EDITOR_TYPE): IEditorAPI['item']['events
return;
}

if (updates && original?.version == original?.posted_version) {
original['version'] = original?.version ? original['version'] + 1 : 1;
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
}

plans[index] = {
...original,
...updates,
Expand Down
2 changes: 2 additions & 0 deletions client/components/ContentProfiles/FieldTab/FieldEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class FieldEditor extends React.Component<IProps, IState> {
const fieldProps = {
'schema.required': {enabled: !(this.props.disableRequired || this.props.systemRequired)},
'schema.read_only': {enabled: this.props.item.name === 'related_plannings'},
'schema.planning_auto_publish': {enabled: this.props.item.name === 'related_plannings'},
'schema.field_type': {enabled: fieldType != null},
'schema.minlength': {enabled: !disableMinMax},
'schema.maxlength': {enabled: !disableMinMax},
Expand Down Expand Up @@ -187,6 +188,7 @@ export class FieldEditor extends React.Component<IProps, IState> {
'schema.multilingual': {enabled: true, index: 11},
'schema.languages': {enabled: true, index: 12},
'schema.default_language': {enabled: true, index: 13},
'schema.planning_auto_publish': {enabled: true, index: 14},
},
{
item: this.props.item,
Expand Down
11 changes: 11 additions & 0 deletions client/components/fields/resources/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ registerEditorField(
true
);

registerEditorField(
'schema.planning_auto_publish',
EditorFieldCheckbox,
() => ({
label: superdeskApi.localization.gettext('Post planning items with Event'),
field: 'schema.planning_auto_publish',
}),
null,
true
);

registerEditorField(
'schema.format_options',
SelectEditor3FormattingOptions,
Expand Down
3 changes: 3 additions & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ export interface IPlanningItem extends IBaseRestApiResponse {
reason: string;
_time_to_be_confirmed: boolean;
_cancelAllCoverage: boolean;
version:number;
posted_version:number;

// Used when showing Associated Planning item for Events
_agendas: Array<IAgenda>;
Expand Down Expand Up @@ -983,6 +985,7 @@ export interface IProfileSchemaTypeList extends IBaseProfileSchemaType<'list'> {
schema?: {[key: string]: any};
mandatory_in_list?: {[key: string]: any};
vocabularies?: Array<IVocabulary['_id']>;
planning_auto_publish?:boolean;
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IProfileSchemaTypeInteger extends IBaseProfileSchemaType<'integer'> {}
Expand Down
1 change: 1 addition & 0 deletions server/planning/content_profiles/profiles/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class EventSchema(BaseSchema):
custom_vocabularies = schema.ListField()
related_plannings = schema.ListField()
related_plannings.schema["read_only"] = False
related_plannings.schema["planning_auto_publish"] = False
registration_details = TextField(field_type="multi_line")
invitation_details = TextField(field_type="multi_line")
accreditation_info = TextField(field_type="single_line")
Expand Down
18 changes: 14 additions & 4 deletions server/planning/events/events_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,23 @@ def publish_event(self, event, version):
logger.error("Failed to save planning version for event item id {}".format(event["_id"]))

def post_related_plannings(self, plannings, new_post_state):
# Check to see if we are un-posting, we need to unpost it's planning item
if new_post_state != POST_STATE.CANCELLED:
return

planning_post_service = get_resource_service("planning_post")
planning_spike_service = get_resource_service("planning_spike")
event_profile_schema = get_resource_service("planning_types").find_one(req=None, name="event").get("schema", {})
docs = []
if new_post_state != POST_STATE.CANCELLED:
if event_profile_schema.get("related_plannings", {}).get("planning_auto_publish"):
docs = [
{
"planning": planning[config.ID_FIELD],
"etag": planning.get("etag"),
"pubstatus": POST_STATE.USABLE,
}
for planning in plannings if planning.get("version") != planning.get("posted_version")
]
if len(docs) > 0:
planning_post_service.post(docs)
return
for planning in plannings:
if not planning.get("pubstatus") and planning.get("state") in [
WORKFLOW_STATE.INGESTED,
Expand Down
3 changes: 3 additions & 0 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,9 @@ def duplicate_xmp_file(self, coverage):
TO_BE_CONFIRMED_FIELD: TO_BE_CONFIRMED_FIELD_SCHEMA,
"_type": {"type": "string", "mapping": None},
"extra": metadata_schema["extra"],
# Added fields for post planning item with events
"posted_version" : {"type": "number", "nullable": False},
"version" : {"type": "number", "default": 1},
} # end planning_schema


Expand Down
1 change: 1 addition & 0 deletions server/planning/planning/planning_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def post_planning(self, plan, new_post_state, assignments_to_delete):
updates = {
"state": get_item_post_state(plan, new_post_state),
"pubstatus": new_post_state,
"posted_version": plan.get("version")
}
if updates["state"] in [WORKFLOW_STATE.SCHEDULED, WORKFLOW_STATE.KILLED]:
updates["state_reason"] = None
Expand Down
6 changes: 6 additions & 0 deletions server/planning/validate/planning_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def _validate_read_only(self, read_only, field, value):
# Ignore this profile as it's for the front-end editor
pass

def _validate_planning_auto_publish(self, planning_auto_publish, field, value):
"""
{'type': 'boolean', 'nullable': True}
"""
pass


class PlanningValidateResource(Resource):
endpoint_name = "planning_validator"
Expand Down
Loading