Skip to content

Commit 8cdd8f7

Browse files
[STT-1452] - Fix the STT "Autotranslate and publish" macro (#3144)
* Flag internal destination flow * Pass internal destination context to macros * Suggested fixes
1 parent c3c2426 commit 8cdd8f7

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

apps/tasks.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ def compare_dictionaries(original, updates):
7070
return modified
7171

7272

73-
async def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, default_stage="incoming_stage"):
73+
async def send_to(
74+
doc,
75+
update=None,
76+
desk_id=None,
77+
stage_id=None,
78+
user_id=None,
79+
default_stage="incoming_stage",
80+
macro_kwargs=None,
81+
) -> None:
7482
"""Send item to given desk and stage.
7583
7684
Applies the outgoing and incoming macros of current and destination stages
@@ -91,7 +99,7 @@ async def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, d
9199
task = {"desk": desk_id, "stage": stage_id, "user": original_task.get("user") if user_id is None else user_id}
92100

93101
if current_stage:
94-
await apply_stage_rule(doc, update, current_stage, MACRO_OUTGOING)
102+
await apply_stage_rule(doc, update, current_stage, MACRO_OUTGOING, macro_kwargs=macro_kwargs)
95103

96104
if desk_id:
97105
# TODO-ASYNC[desks]: Use DesksResourceModel async service where when upgrading this module
@@ -128,15 +136,17 @@ async def send_to(doc, update=None, desk_id=None, stage_id=None, user_id=None, d
128136
doc["expiry"] = get_item_expiry(desk=desk, stage=destination_stage)
129137

130138
if destination_stage:
131-
await apply_stage_rule(doc, update, destination_stage, MACRO_INCOMING, desk=desk, task=task)
139+
await apply_stage_rule(
140+
doc, update, destination_stage, MACRO_INCOMING, desk=desk, task=task, macro_kwargs=macro_kwargs
141+
)
132142
if destination_stage.get("task_status"):
133143
if update:
134144
update["task"]["status"] = destination_stage["task_status"]
135145
else:
136146
doc["task"]["status"] = destination_stage["task_status"]
137147

138148

139-
async def apply_stage_rule(doc, update, stage, rule_type, desk=None, task=None):
149+
async def apply_stage_rule(doc, update, stage, rule_type, desk=None, task=None, macro_kwargs=None):
140150
macro_type = "{}_macro".format(rule_type)
141151

142152
if stage.get(macro_type):
@@ -147,7 +157,7 @@ async def apply_stage_rule(doc, update, stage, rule_type, desk=None, task=None):
147157
logger.warning("macro %s is missing", stage.get(macro_type))
148158
return
149159

150-
await macro["callback"](doc, desk=desk, stage=stage, task=task)
160+
await macro["callback"](doc, desk=desk, stage=stage, task=task, **(macro_kwargs or {}))
151161
if update:
152162
modified = compare_dictionaries(original_doc, doc)
153163
for i in modified:

superdesk/internal_destinations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ async def handle_item_published(item, after_scheduled):
8383
new_item = deepcopy(item)
8484

8585
try:
86-
await send_to(new_item, desk_id=dest["desk"], stage_id=dest.get("stage"))
86+
await send_to(
87+
new_item,
88+
desk_id=dest["desk"],
89+
stage_id=dest.get("stage"),
90+
macro_kwargs={"internal_destination": dest},
91+
)
8792
except StopDuplication:
8893
continue
8994

0 commit comments

Comments
 (0)