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
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
1 change: 1 addition & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,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;
}

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
19 changes: 15 additions & 4 deletions server/planning/events/events_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,24 @@ 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
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
if not planning.get("versionposted")
]
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
105 changes: 105 additions & 0 deletions server/planning/events/events_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,108 @@ def generate_recurring_events(num_events):
)
days += 1
return events


class EventsRelatedPlanningAutoPublish(TestCase):
def test_planning_item_is_published_with_events(self):
with self.app.app_context():
events_service = get_resource_service("events")
planning_service = get_resource_service("planning")
event = {
"type": "event",
"_id": "123",
"occur_status": {
"qcode": "eocstat:eos5",
"name": "Planned, occurs certainly",
"label": "Planned, occurs certainly",
},
"dates": {
"start": datetime(2099, 11, 21, 11, 00, 00, tzinfo=pytz.UTC),
"end": datetime(2099, 11, 21, 12, 00, 00, tzinfo=pytz.UTC),
"tz": "Asia/Calcutta",
},
"calendars": [],
"state": "draft",
"language": "en",
"languages": ["en"],
"place": [],
"_time_to_be_confirmed": False,
"name": "Demo ",
"update_method": "single",
}
event_id = events_service.post([event])
planning = {
"planning_date": datetime(2099, 11, 21, 12, 00, 00, tzinfo=pytz.UTC),
"name": "Demo 1",
"place": [],
"language": "en",
"type": "planning",
"agendas": [],
"languages": ["en"],
"user": "12234553",
"event_item": event_id[0],
"coverages": [
{
"coverage_id": "urn:newsml:localhost:5000:2023-09-08T17:40:56.290922:e264a179-5b1a-4b52-b73b-332660848cae",
"planning": {
"scheduled": datetime(2099, 11, 21, 12, 00, 00, tzinfo=pytz.UTC),
"g2_content_type": "text",
"language": "en",
"genre": "None",
},
"news_coverage_status": {
"qcode": "ncostat:int",
"name": "coverage intended",
"label": "Planned",
},
"workflow_status": "draft",
"assigned_to": {},
"firstcreated": datetime(2099, 11, 21, 12, 00, 00, tzinfo=pytz.UTC),
}
],
}
planning_id = planning_service.post([planning])
schema = {
"language": {
"languages": ["en", "de"],
"default_language": "en",
"multilingual": True,
"required": True,
},
"name": {"multilingual": True},
"slugline": {"multilingual": True},
"definition_short": {"multilingual": True},
"related_plannings": {"planning_auto_publish": True},
}
self.app.data.insert(
"planning_types",
[
{
"_id": "event",
"name": "event",
"editor": {
"language": {"enabled": True},
"related_plannings": {"enabled": True},
},
"schema": schema,
}
],
)
get_resource_service("events_post").post(
[
{
"event": event_id[0],
"pubstatus": "usable",
"update_method": "single",
}
]
)

event_item = events_service.find_one(req=None, _id=event_id[0])
self.assertEqual(len([event_item]), 1)
self.assertEqual(event_item.get("state"), "scheduled")

planning_item = planning_service.find_one(req=None, _id=planning_id[0])
self.assertEqual(len([planning_item]), 1)
self.assertEqual(planning_item.get("state"), "scheduled")
self.assertEqual(planning_item.get("versionposted"), utcnow())
1 change: 1 addition & 0 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ def duplicate_xmp_file(self, coverage):
TO_BE_CONFIRMED_FIELD: TO_BE_CONFIRMED_FIELD_SCHEMA,
"_type": {"type": "string", "mapping": None},
"extra": metadata_schema["extra"],
"versionposted": {"type": "datetime", "nullable": False},
} # end planning_schema


Expand Down
2 changes: 2 additions & 0 deletions server/planning/planning/planning_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from superdesk.resource import Resource
from superdesk.services import BaseService
from superdesk.notification import push_notification
from superdesk.utc import utcnow
from copy import deepcopy
import logging

Expand Down Expand Up @@ -125,6 +126,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,
"versionposted": utcnow(),
}
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