Skip to content

Commit

Permalink
fix issue with recursive publishing (#2358)
Browse files Browse the repository at this point in the history
when using internal destination auto publish macro as
incoming rule on a stage

SDESK-6526
  • Loading branch information
petrjasek committed Aug 12, 2022
1 parent 83ea557 commit cd3335d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
17 changes: 11 additions & 6 deletions apps/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from superdesk.users.services import current_user_has_privilege
from superdesk.resource import Resource
from superdesk.errors import SuperdeskApiError, InvalidStateTransitionError
from superdesk.errors import StopDuplication, SuperdeskApiError, InvalidStateTransitionError
from superdesk.notification import push_notification
from superdesk.utc import utcnow
from superdesk.metadata.utils import item_url
Expand Down Expand Up @@ -115,11 +115,6 @@ def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, default
task["desk"] = destination_stage["desk"]
task["stage"] = stage_id

if destination_stage:
apply_stage_rule(doc, update, destination_stage, MACRO_INCOMING, desk=desk, task=task)
if destination_stage.get("task_status"):
task["status"] = destination_stage["task_status"]

if update:
update.setdefault("task", {})
update["task"].update(task)
Expand All @@ -128,6 +123,14 @@ def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, default
doc["task"].update(task)
doc["expiry"] = get_item_expiry(desk=desk, stage=destination_stage)

if destination_stage:
apply_stage_rule(doc, update, destination_stage, MACRO_INCOMING, desk=desk, task=task)
if destination_stage.get("task_status"):
if update:
update["task"]["status"] = destination_stage["task_status"]
else:
doc["task"]["status"] = destination_stage["task_status"]


def apply_stage_rule(doc, update, stage, rule_type, desk=None, task=None):
macro_type = "{}_macro".format(rule_type)
Expand All @@ -144,6 +147,8 @@ def apply_stage_rule(doc, update, stage, rule_type, desk=None, task=None):
modified = compare_dictionaries(original_doc, doc)
for i in modified:
update[i] = doc[i]
except StopDuplication:
raise
except Exception as ex:
message = _("Error:{exception} in {rule_type} rule:{rule} for stage:{stage}").format(
exception=str(ex), rule_type=rule_type, rule=macro.get("label"), stage=stage.get("name")
Expand Down
11 changes: 8 additions & 3 deletions superdesk/internal_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ class InternalDestinationsService(Service):
pass


def handle_item_published(sender, item, **extra):
def handle_item_published(sender, item, desk=None, **extra):
macros_service = get_resource_service("macros")
archive_service = get_resource_service("archive")
filters_service = get_resource_service("content_filters")
destinations_service = get_resource_service(NAME)

for dest in destinations_service.get(req=None, lookup={"is_active": True}):
if dest.get("desk") == item.get("task").get("desk"):
item_desk = desk["_id"] if desk is not None else item.get("task").get("desk")
if dest.get("desk") == item_desk:
# item desk and internal destination are same then don't execute
continue

Expand All @@ -72,7 +73,11 @@ def handle_item_published(sender, item, **extra):
item[SCHEDULE_SETTINGS] = {}

new_item = deepcopy(item)
send_to(new_item, desk_id=dest["desk"], stage_id=dest.get("stage"))

try:
send_to(new_item, desk_id=dest["desk"], stage_id=dest.get("stage"))
except StopDuplication:
continue

if dest.get("macro"):
macro = macros_service.get_macro_by_name(dest["macro"])
Expand Down

0 comments on commit cd3335d

Please sign in to comment.