Skip to content

Commit

Permalink
add config for different linking methods
Browse files Browse the repository at this point in the history
STT-30
  • Loading branch information
petrjasek committed Jul 24, 2024
1 parent f022b48 commit 706491f
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 32 deletions.
1 change: 0 additions & 1 deletion client/actions/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export function convertEventToPlanningItem(event: IEventItem): Partial<IPlanning
const defaultValues = planningUtils.defaultPlanningValues(null, defaultPlace);
const eventLink: IPlanningRelatedEventLink = {
_id: event._id,
link_type: 'primary',
};

if (event.recurrence_id != null) {
Expand Down
1 change: 0 additions & 1 deletion client/actions/tests/agenda_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ describe('agenda', () => {
coverages: [],
related_events: [{
_id: events[0]._id,
link_type: 'primary',
}],
planning_date: events[0].dates.start,
slugline: events[0].slugline,
Expand Down
1 change: 0 additions & 1 deletion client/api/planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ function createFromEvent(event: IEventItem, updates: Partial<IPlanningItem>): Pr

const eventLink: IPlanningRelatedEventLink = {
_id: event._id,
link_type: 'primary',
};

if (event.recurrence_id != null) {
Expand Down
2 changes: 1 addition & 1 deletion client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ export type IPlanningRelatedEventLinkType = 'primary' | 'secondary';

export interface IPlanningRelatedEventLink {
_id: string;
link_type: IPlanningRelatedEventLinkType;
link_type?: IPlanningRelatedEventLinkType;
recurrence_id?: string;
}

Expand Down
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
89 changes: 88 additions & 1 deletion server/features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ Feature: Events

@auth
Scenario: Link new Event as secondary to a Planning item
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
Given "planning"
"""
[{
Expand Down Expand Up @@ -1667,4 +1671,87 @@ Feature: Events
"lock_session": "#SESSION_ID#"
}
"""
Then we get OK response
Then we get OK response

@auth
Scenario: Link new Event with many_secondary link method
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "many_secondary"}
"""
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"slugline": "TestEvent",
"state": "draft",
"lock_user": "#CONTEXT_USER_ID#",
"lock_session": "#SESSION_ID#",
"lock_action": "add_as_event",
"lock_time": "#DATE#",
"planning_date": "2016-01-02"
}]
"""
When we post to "events"
"""
{
"guid": "event_1",
"name": "Primary Event 1",
"slugline": "event-1",
"_planning_item": "plan1",
"dates": {
"start": "2029-11-21T12:00:00.000Z",
"end": "2029-11-21T14:00:00.000Z",
"tz": "Australia/Sydney"
}
}
"""
Then we get OK response
When we get "/planning/plan1"
Then we get existing resource
"""
{"related_events": [{"_id": "#events._id#", "link_type": "secondary"}]}
"""

@auth
Scenario: Link new Event with one_primary link method
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary"}
"""
Given "planning"
"""
[{
"_id": "plan1",
"guid": "plan1",
"slugline": "TestEvent",
"state": "draft",
"lock_user": "#CONTEXT_USER_ID#",
"lock_session": "#SESSION_ID#",
"lock_action": "add_as_event",
"lock_time": "#DATE#",
"planning_date": "2016-01-02"
}]
"""
When we post to "events"
"""
{
"guid": "event_1",
"name": "Primary Event 1",
"slugline": "event-1",
"_planning_item": "plan1",
"dates": {
"start": "2029-11-21T12:00:00.000Z",
"end": "2029-11-21T14:00:00.000Z",
"tz": "Australia/Sydney"
}
}
"""
Then we get OK response
When we get "/planning/plan1"
Then we get existing resource
"""
{"related_events": [{"_id": "#events._id#", "link_type": "primary"}]}
"""

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": "many_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"}
]}
]}
"""
10 changes: 7 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 Expand Up @@ -1262,6 +1262,10 @@ Feature: Events Post

@auth
Scenario: Posting an Event will not post Planning item with secondary link
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
# Configure auto-posting of primary linked Events
Given "planning_types"
"""
Expand Down
4 changes: 4 additions & 0 deletions server/features/events_postpone.feature
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ Feature: Events Postpone
@auth
@vocabulary
Scenario: Postponing an Event does not postpone Planning item with secondary link
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
Given we have sessions "/sessions"
And "events"
"""
Expand Down
4 changes: 4 additions & 0 deletions server/features/events_reschedule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,10 @@ Feature: Events Reschedule
@auth
@vocabulary
Scenario: Rescheduling an Event does not modify Planning item with secondary link
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
Given we have sessions "/sessions"
And "events"
"""
Expand Down
4 changes: 4 additions & 0 deletions server/features/events_spike.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ Feature: Events Spike
@auth
@vocabulary
Scenario: Spiking an Event does not spike Planning item with secondary link
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
Given we have sessions "/sessions"
And "events"
"""
Expand Down
4 changes: 4 additions & 0 deletions server/features/planning_lock.feature
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ Feature: Planning Item Locking

@auth
Scenario: Can lock Planning while related secondary Event is locked
Given config update
"""
{"PLANNING_EVENT_LINK_METHOD": "one_primary_many_secondary"}
"""
Given "events"
"""
[{
Expand Down
1 change: 0 additions & 1 deletion server/planning/commands/export_to_newsroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def run(self, resource_url, assets_url, size=None):
logger.info("Completed export events and planning.")

def _fetch_items(self, fetch_callback):
""""""
query = {
"query": {
"bool": {
Expand Down
12 changes: 10 additions & 2 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
update_ingest_on_patch,
TEMP_ID_PREFIX,
)
from planning.utils import get_related_planning_for_events, get_related_event_ids_for_planning
from planning.utils import (
get_planning_event_link_method,
get_related_planning_for_events,
get_related_event_ids_for_planning,
)
from .events_base_service import EventsBaseService
from .events_schema import events_schema
from .events_sync import sync_event_metadata_with_planning_items
Expand Down Expand Up @@ -751,8 +755,12 @@ def _link_to_planning(event: Event):
raise SuperdeskApiError.badRequestError("Planning item not found")

updates = {"related_events": planning_item.get("related_events") or []}
event_link_method = get_planning_event_link_method()
link_type: PLANNING_RELATED_EVENT_LINK_TYPE = (
"primary" if not len(get_related_event_ids_for_planning(planning_item, "primary")) else "secondary"
"primary"
if not len(get_related_event_ids_for_planning(planning_item, "primary"))
and event_link_method in ("one_primary", "one_primary_many_secondary")
else "secondary"
)
related_planning = PlanningRelatedEventLink(_id=event_id, link_type=link_type)
updates["related_events"].append(related_planning)
Expand Down
Loading

0 comments on commit 706491f

Please sign in to comment.