Skip to content

Commit 916e9cf

Browse files
authored
Move save to log_status_update so e-mail get sent. (#4693)
Fixes #4692 ## Test Steps - [ ] Test that notification go out to reviewers. Slack for internal and e-mail for external. - [ ] Test that status updated go out via e-mail to applicant and look ok when a submission is moved forward.
1 parent f6f307a commit 916e9cf

5 files changed

Lines changed: 14 additions & 23 deletions

File tree

hypha/apply/activity/adapters/activity_feed.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,15 @@ def handle_task_removal(self, source, task, **kwargs):
221221
)
222222
)
223223

224-
def handle_transition(self, new_phase, source, old_phase=None, **kwargs):
224+
def handle_transition(self, old_phase, source, **kwargs):
225225
def wrap_in_color_class(text):
226226
color_class = PHASE_BG_COLORS.get(text, "")
227227
return f'<span class="rounded-full inline-block px-2 py-0.5 font-medium text-gray-800 {color_class}">{text}</span>'
228228

229229
submission = source
230230
base_message = _("Progressed from {old_display} to {new_display}")
231231

232-
if old_phase is None:
233-
old_phase = submission.phase
232+
new_phase = submission.phase
234233

235234
staff_message = base_message.format(
236235
old_display=wrap_in_color_class(old_phase.display_name),
@@ -284,9 +283,8 @@ def handle_batch_transition(self, transitions, sources, **kwargs):
284283
kwargs.pop("source")
285284
for submission in submissions:
286285
old_phase = transitions[submission.id]
287-
new_phase = submission.phase
288286
return self.handle_transition(
289-
old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs
287+
old_phase=old_phase, source=submission, **kwargs
290288
)
291289

292290
def partners_updated(self, added, removed, **kwargs):

hypha/apply/activity/adapters/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
MESSAGES.BATCH_DETERMINATION_OUTCOME: "determinations",
99
MESSAGES.UPDATE_LEAD: "old_lead",
1010
MESSAGES.NEW_REVIEW: "review",
11-
MESSAGES.TRANSITION: "new_phase",
11+
MESSAGES.TRANSITION: "old_phase",
1212
MESSAGES.BATCH_TRANSITION: "transitions",
1313
MESSAGES.APPLICANT_EDIT: "revision",
1414
MESSAGES.INVITE_COAPPLICANT: "co_applicant_invite",

hypha/apply/activity/adapters/emails.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,18 @@ def extra_kwargs(self, message_type, source, sources, **kwargs):
163163
"subject": self.get_subject(message_type, source),
164164
}
165165

166-
def handle_transition(self, new_phase, source, old_phase=None, **kwargs):
166+
def handle_transition(self, old_phase, source, **kwargs):
167167
from hypha.apply.funds.workflows import PHASES
168168

169169
submission = source
170170

171-
if old_phase is None:
172-
old_phase = submission.phase
173-
174171
# Retrieve status index to see if we are going forward or backward.
175172
old_index = list(dict(PHASES).keys()).index(old_phase.name)
176173
target_index = list(dict(PHASES).keys()).index(submission.status)
177174
is_forward = old_index < target_index
178175

179176
kwargs["old_phase"] = old_phase.public_name
180-
kwargs["new_phase"] = new_phase.public_name
177+
kwargs["new_phase"] = submission.phase.public_name
181178

182179
if is_forward:
183180
return self.render_message(
@@ -210,9 +207,8 @@ def handle_batch_transition(self, transitions, sources, **kwargs):
210207
kwargs.pop("source")
211208
for submission in submissions:
212209
old_phase = transitions[submission.id]
213-
new_phase = submission.phase
214210
return self.handle_transition(
215-
old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs
211+
old_phase=old_phase, source=submission, **kwargs
216212
)
217213

218214
def handle_project_transition(self, source, **kwargs):

hypha/apply/activity/adapters/slack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SlackAdapter(AdapterBase):
4949
"{user} has updated the partners on <{link}|{source.title_text_display}>"
5050
),
5151
MESSAGES.TRANSITION: _(
52-
"{user} has updated the status of <{link}|{source.title_text_display}>: {source.phase.display_name} → {new_phase.display_name}"
52+
"{user} has updated the status of <{link}|{source.title_text_display}>: {old_phase.display_name} → {source.phase.display_name}"
5353
),
5454
MESSAGES.BATCH_TRANSITION: "handle_batch_transition",
5555
MESSAGES.DETERMINATION_OUTCOME: "handle_determination",

hypha/apply/funds/models/submissions.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,7 @@ def perform_transition(self, action, user, request=None, **kwargs):
375375
raise PermissionDenied(f'You do not have permission to "{action}"')
376376

377377
# Execute the transition
378-
result = transition_method(by=user, request=request, **kwargs)
379-
if result:
380-
self.status = action
381-
self.save(update_fields=["status"])
382-
378+
transition_method(by=user, request=request, **kwargs)
383379
self.progress_stage_when_possible(user, request, **kwargs)
384380

385381
attrs["perform_transition"] = perform_transition
@@ -1038,10 +1034,11 @@ def get_no_screening_status(self):
10381034
@status_field.on_success()
10391035
def log_status_update(self, descriptor, source, target, **kwargs):
10401036
instance = self
1037+
old_phase = instance.workflow[source]
10411038

1042-
# The status associated with the application at this time will be the old phase
1043-
# so provide the new phase as an arg when transitioning
1044-
new_phase = self.workflow[target]
1039+
# Update status on instance.
1040+
instance.status = target
1041+
instance.save(update_fields=["status"])
10451042

10461043
by = kwargs["by"]
10471044
request = kwargs["request"]
@@ -1066,7 +1063,7 @@ def log_status_update(self, descriptor, source, target, **kwargs):
10661063
user=by,
10671064
request=request,
10681065
source=instance,
1069-
related=new_phase,
1066+
related=old_phase,
10701067
)
10711068

10721069
if instance.status in review_statuses:

0 commit comments

Comments
 (0)