Skip to content

Commit

Permalink
Add Coverage Provider to Embedded Planning and Synchronize Coverage A…
Browse files Browse the repository at this point in the history
…ssignee Updates to Assignments [SDCP-875] (superdesk#2151)

* Fix : Coverages assignment: Reassigned / unassigned user is not retained on Save / Update

* update schema and implement changes to populate coverage_provider through  event form

* refactore code

* remove unwanted code

* add tests

* refactore logix
  • Loading branch information
devketanpro committed Dec 12, 2024
1 parent 90a2176 commit a26947d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions client/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function create(updates: Partial<IEventItem>): Promise<Array<IEventItem>> {
ednote: coverage.planning.ednote,
internal_note: coverage.planning.internal_note,
headline: coverage.planning.headline,
coverage_provider: coverage.assigned_to.coverage_provider
})),
})),
update_method: updates.update_method?.value ?? updates.update_method
Expand Down Expand Up @@ -193,6 +194,7 @@ function update(original: IEventItem, updates: Partial<IEventItem>): Promise<Arr
ednote: coverage.planning.ednote,
internal_note: coverage.planning.internal_note,
headline: coverage.planning.headline,
coverage_provider: coverage.assigned_to.coverage_provider
})),
})),
update_method: updates.update_method?.value ?? updates.update_method ?? original.update_method
Expand Down
14 changes: 13 additions & 1 deletion server/features/event_embedded_planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ Feature: Event Embedded Planning
"coverages": [{
"g2_content_type": "text",
"news_coverage_status": "ncostat:int",
"scheduled": "2029-11-21T15:00:00.000Z"
"scheduled": "2029-11-21T15:00:00.000Z",
"coverage_provider": {
"name":"Stringer",
"qcode":"stringer",
"contact_type":"stringer"
}
}]
}]
}]
Expand Down Expand Up @@ -53,6 +58,13 @@ Feature: Event Embedded Planning
"original_creator": "#CONTEXT_USER_ID#",
"version_creator": "#CONTEXT_USER_ID#",
"workflow_status": "draft",
"assigned_to": {
"coverage_provider": {
"name":"Stringer",
"qcode":"stringer",
"contact_type":"stringer"
}
},
"news_coverage_status": {"qcode": "ncostat:int", "name": "coverage intended", "label": "Planned"},
"planning": {
"g2_content_type": "text",
Expand Down
2 changes: 1 addition & 1 deletion server/features/planning.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ Feature: Planning
"slugline": "test slugline"
},
"assigned_to": {
"desk": "Politic Desk",
"desk": "Sports Desk",
"user": "507f191e810c19729de870eb",
"assignment_id": "#firstassignment#",
"state": "assigned"
Expand Down
9 changes: 9 additions & 0 deletions server/planning/events/events_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@
"ednote": {"type": "string", "nullable": True},
"internal_note": {"type": "string", "nullable": True},
"priority": {"type": "integer", "nullable": True},
"coverage_provider": {
"type": "dict",
"nullable": True,
"schema": {
"qcode": {"type": "string"},
"name": {"type": "string"},
"contact_type": {"type": "string"},
},
},
},
},
},
Expand Down
14 changes: 13 additions & 1 deletion server/planning/events/events_sync/embedded_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ def create_new_coverage_from_event_and_planning(
"planning": {},
}

if coverage.get("desk") or coverage.get("user"):
if coverage.get("desk") or coverage.get("user") or coverage.get("coverage_provider"):
new_coverage["assigned_to"] = {}
if coverage.get("desk"):
new_coverage["assigned_to"]["desk"] = coverage["desk"]
if coverage.get("user"):
new_coverage["assigned_to"]["user"] = coverage["user"]
if coverage.get("coverage_provider"):
new_coverage["assigned_to"]["coverage_provider"] = coverage["coverage_provider"]

if "language" in profiles.coverages.enabled_fields:
# If ``language`` is enabled for Coverages but not defined in ``embedded_planning``
Expand Down Expand Up @@ -357,6 +359,16 @@ def get_existing_plannings_from_embedded_planning(
except KeyError:
pass

try:
if (
existing_coverage.get("assigned_to", {}).get("coverage_provider")
!= embedded_coverage["coverage_provider"]
):
existing_coverage["assigned_to"]["coverage_provider"] = embedded_coverage["coverage_provider"]
update_required = True
except KeyError:
pass

# Create new Coverages from the ``embedded_planning`` Event field
for coverage_id, embedded_coverage in embedded_plan["coverages"].items():
if coverage_id in updated_coverage_ids:
Expand Down
7 changes: 7 additions & 0 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,13 @@ def _create_update_assignment(
if planning_original.get("name") != planning_updates.get("name"):
assignment["name"] = planning["name"] if not translated_value and translated_name else translated_name

# If the coverage assignee has been changed and workflow status is active
if original.get("workflow_status") != WORKFLOW_STATE.DRAFT and self.is_coverage_assignment_modified(
updates, original_assignment
):
assigned_to["state"] = ASSIGNMENT_WORKFLOW_STATE.ASSIGNED
assignment["assigned_to"] = assigned_to

# If there has been a change in the planning internal note then notify the assigned users/desk
if planning_updates.get("internal_note") and planning_original.get("internal_note") != planning_updates.get(
"internal_note"
Expand Down
1 change: 1 addition & 0 deletions server/planning/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EmbeddedCoverageItem(TypedDict, total=False):
ednote: str
internal_note: str
priority: int
coverage_provider: Dict[str, Any]


class EmbeddedPlanning(TypedDict, total=False):
Expand Down

0 comments on commit a26947d

Please sign in to comment.