diff --git a/server/features/assignments_delete.feature b/server/features/assignments_delete.feature index 1b6e279e0..b7c6cffac 100644 --- a/server/features/assignments_delete.feature +++ b/server/features/assignments_delete.feature @@ -292,7 +292,7 @@ Feature: Assignments Delete "workflow_status": "active" }], "related_events": [ - {"_id": "#events._id#", "link_type": "primary"} + {"_id": "#events._id#"} ] } """ @@ -351,7 +351,6 @@ Feature: Assignments Delete }], "related_events": [{ "_id": "#EVENT2._id#", - "link_type": "primary", "recurrence_id": "#EVENT2.recurrence_id#" }], "recurrence_id": "#EVENT2.recurrence_id#" diff --git a/server/features/combined_export.feature b/server/features/combined_export.feature index 58fa80efd..2bca192aa 100644 --- a/server/features/combined_export.feature +++ b/server/features/combined_export.feature @@ -59,7 +59,7 @@ Feature: Export combined Planning and Event items with default template "slugline": "planning-1", "description_text": "desc", "related_events": [ - {"_id": "#events._id#", "link_type": "primary"} + {"_id": "#events._id#"} ], "ednote": "Ed. note 1", "coverages": [{ diff --git a/server/features/events_cancel.feature b/server/features/events_cancel.feature index bb2bcfe7f..e15131abd 100644 --- a/server/features/events_cancel.feature +++ b/server/features/events_cancel.feature @@ -164,7 +164,7 @@ Feature: Events Cancel "_id": "plan1", "guid": "plan1", "slugline": "TestPlan 1", - "related_events": [{"_id": "event1", "link_type": "primary"}], + "related_events": [{"_id": "event1"}], "state": "draft", "planning_date": "2016-01-02" }, @@ -172,7 +172,7 @@ Feature: Events Cancel "_id": "plan2", "guid": "plan2", "slugline": "TestPlan 2", - "related_events": [{"_id": "event1", "link_type": "primary"}], + "related_events": [{"_id": "event1"}], "state": "draft", "planning_date": "2016-01-02" }] @@ -311,7 +311,7 @@ Feature: Events Cancel [{ "slugline": "Weekly Meetings", "headline": "Friday Club", - "related_events": [{"_id": "#EVENT3._id#", "link_type": "primary"}], + "related_events": [{"_id": "#EVENT3._id#"}], "planning_date": "2016-01-02" }] """ @@ -394,7 +394,7 @@ Feature: Events Cancel "guid": "plan1", "slugline": "TestPlan 1", "related_events": [ - {"_id": "event1", "link_type": "primary"} + {"_id": "event1"} ], "ednote": "We're covering this Event", "state": "draft", @@ -870,7 +870,7 @@ Feature: Events Cancel "slugline": "Weekly Meetings", "headline": "Friday Club", "related_events": [ - {"_id": "#EVENT3._id#", "link_type": "primary"} + {"_id": "#EVENT3._id#"} ], "planning_date": "2016-01-02" }] @@ -904,6 +904,10 @@ Feature: Events Cancel @auth @vocabulary Scenario: Cancelling an Event does not cancel Planning item with secondary link + Given config update + """ + {"PLANNING_EVENT_LINK_METHOD": "secondary"} + """ Given we have sessions "/sessions" And "events" """ @@ -924,24 +928,20 @@ Feature: Events Cancel And "planning" """ [{ - "guid": "plan1", - "slugline": "test-plan", - "planning_date": "2029-05-29T12:00:00+0000", - "related_events": [{"_id": "event1", "link_type": "primary"}] - }, { "guid": "plan2", "slugline": "test-plan", "planning_date": "2029-05-29T12:00:00+0000", - "related_events": [{"_id": "event1", "link_type": "secondary"}] + "related_events": [{"_id": "event1"}] }] """ When we perform cancel on events "event1" Then we get OK response When we get "/planning" - Then we get list with 2 items + Then we get list with 1 items """ {"_items": [ - {"_id": "plan1", "state": "cancelled"}, - {"_id": "plan2", "state": "draft"} + {"_id": "plan2", "state": "draft", "related_events": [ + {"_id": "event1", "link_type": "secondary"} + ]} ]} """ diff --git a/server/features/events_post.feature b/server/features/events_post.feature index 74e2b260f..40bde4979 100644 --- a/server/features/events_post.feature +++ b/server/features/events_post.feature @@ -297,7 +297,7 @@ Feature: Events Post "headline": "test headline", "slugline": "test slugline", "planning_date": "2016-01-02", - "related_events": [{"_id": "#events._id#", "link_type": "primary"}] + "related_events": [{"_id": "#events._id#"}] } """ Then we get OK response @@ -439,7 +439,7 @@ Feature: Events Post "headline": "test headline", "slugline": "test slugline", "planning_date": "2016-01-02", - "related_events": [{"_id": "#events._id#", "link_type": "primary"}] + "related_events": [{"_id": "#events._id#"}] } """ Then we get OK response @@ -580,7 +580,7 @@ Feature: Events Post "headline": "test headline", "slugline": "test slugline", "planning_date": "2016-01-02", - "related_events": [{"_id": "#events._id#", "link_type": "primary"}] + "related_events": [{"_id": "#events._id#"}] } """ Then we get OK response diff --git a/server/planning/planning/planning.py b/server/planning/planning/planning.py index 343e3f153..3e6a5c060 100644 --- a/server/planning/planning/planning.py +++ b/server/planning/planning/planning.py @@ -319,8 +319,19 @@ def validate_planning(self, updates, original=None): sanitize_input_data(updates) - if len(get_related_event_ids_for_planning(updates, "primary")) > 1: - raise SuperdeskApiError.badRequestError("Only 1 primary linked event is allowed") + if updates.get("related_events"): + related_events_links = updates.get("related_events") + if app.config.get("PLANNING_EVENT_LINK_METHOD") == "one_primary": + assert 1 == len(related_events_links), "Only 1 primary linked event is allowed" + for link in related_events_links: + link.setdefault("link_type", "primary") + assert link["link_type"] == "primary", "Only primary event links are allowed" + elif app.config.get("PLANNING_EVENT_LINK_METHOD") == "secondary": + for link in related_events_links: + link.setdefault("link_type", "secondary") + assert link["link_type"] == "secondary", "Only secondary event links are allowed" + else: + assert False, "Invalid configuration for PLANNING_EVENT_LINK_METHOD" # Validate if agendas being added are enabled agendas agenda_service = get_resource_service("agenda") diff --git a/server/planning/planning/planning_schema.py b/server/planning/planning/planning_schema.py index 4d7442662..041ff46e3 100644 --- a/server/planning/planning/planning_schema.py +++ b/server/planning/planning/planning_schema.py @@ -194,8 +194,6 @@ }, "link_type": { "type": "string", - "required": True, - "default": "primary", "allowed": ["primary", "secondary"], }, }, diff --git a/server/settings.py b/server/settings.py index 3518d27a4..06779fcf1 100644 --- a/server/settings.py +++ b/server/settings.py @@ -13,6 +13,7 @@ import os import json from urllib.parse import urlparse +from typing import Literal def env(variable, fallback_value=None): @@ -189,3 +190,5 @@ def env(variable, fallback_value=None): ELASTICSEARCH_AUTO_AGGREGATIONS = False PLANNING_DEFAULT_COVERAGE_STATUS_ON_INGEST = "ncostat:int" + +PLANNING_EVENT_LINK_METHOD: Literal["one_primary", "secondary"] = "one_primary" \ No newline at end of file