Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Jul 23, 2024
1 parent 839798d commit b2f2855
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
3 changes: 1 addition & 2 deletions server/features/assignments_delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Feature: Assignments Delete
"workflow_status": "active"
}],
"related_events": [
{"_id": "#events._id#", "link_type": "primary"}
{"_id": "#events._id#"}
]
}
"""
Expand Down Expand Up @@ -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#"
Expand Down
2 changes: 1 addition & 1 deletion server/features/combined_export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down
28 changes: 14 additions & 14 deletions server/features/events_cancel.feature
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ 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"
},
{
"_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"
}]
Expand Down Expand Up @@ -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"
}]
"""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}]
Expand Down Expand Up @@ -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"
"""
Expand All @@ -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"}
]}
]}
"""
6 changes: 3 additions & 3 deletions server/features/events_post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions server/planning/planning/planning_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@
},
"link_type": {
"type": "string",
"required": True,
"default": "primary",
"allowed": ["primary", "secondary"],
},
},
Expand Down
3 changes: 3 additions & 0 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import json
from urllib.parse import urlparse
from typing import Literal


def env(variable, fallback_value=None):
Expand Down Expand Up @@ -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"

0 comments on commit b2f2855

Please sign in to comment.