Skip to content

Commit 137a5ad

Browse files
authored
Fixed old status name showing twice in a transition notification (#4621)
<!-- Thanks for contributing to Hypha! Please ensure your contributions pass all necessary linting/testing and that the appropriate documentation has been updated. --> <!-- Describe briefly what your pull request changes. If this is resolving an issue, please specify below via "Fixes #<Github Issue ID>" --> Fixes #4616. After updating to django-viewflow it looks like the application status doesn't get updated until after the notification is sent, when before this would happen before. Thus, getting the current application status as the "new phase" resulted in a duplicate of the "old phase", ie. `<USER> has updated the status of <APPLICATION>: Need screening → Need screening` ## Test Steps <!-- If step does not require manual testing, skip/remove this section. Give a brief overview of the steps required for a user/dev to test this contribution. Important things to include: - Required user roles for where necessary (ie. "As a Staff Admin...") - Clear & validatable expected results (ie. "Confirm the submit button is now not clickable") - Language that can be understood by non-technical testers if being tested by users --> - [ ] Ensure slack & email notifications for application transitions represent the actual transition that took place
1 parent 9e40d00 commit 137a5ad

6 files changed

Lines changed: 25 additions & 11 deletions

File tree

hypha/apply/activity/adapters/activity_feed.py

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

224-
def handle_transition(self, old_phase, source, **kwargs):
224+
def handle_transition(self, new_phase, source, old_phase=None, **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-
new_phase = submission.phase
232+
if old_phase is None:
233+
old_phase = submission.phase
233234

234235
staff_message = base_message.format(
235236
old_display=wrap_in_color_class(old_phase.display_name),
@@ -283,8 +284,9 @@ def handle_batch_transition(self, transitions, sources, **kwargs):
283284
kwargs.pop("source")
284285
for submission in submissions:
285286
old_phase = transitions[submission.id]
287+
new_phase = submission.phase
286288
return self.handle_transition(
287-
old_phase=old_phase, source=submission, **kwargs
289+
old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs
288290
)
289291

290292
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: "old_phase",
11+
MESSAGES.TRANSITION: "new_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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,28 @@ def extra_kwargs(self, message_type, source, sources, **kwargs):
163163
"subject": self.get_subject(message_type, source),
164164
}
165165

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

169169
submission = source
170+
171+
if old_phase is None:
172+
old_phase = submission.phase
173+
170174
# Retrieve status index to see if we are going forward or backward.
171175
old_index = list(dict(PHASES).keys()).index(old_phase.name)
172176
target_index = list(dict(PHASES).keys()).index(submission.status)
173177
is_forward = old_index < target_index
178+
print("NEW PHASE")
179+
print(new_phase.public_name)
180+
181+
kwargs["old_phase"] = old_phase.public_name
182+
kwargs["new_phase"] = new_phase.public_name
174183

175184
if is_forward:
176185
return self.render_message(
177186
"messages/email/transition.html",
178187
source=submission,
179-
old_phase=old_phase,
180188
**kwargs,
181189
)
182190

@@ -204,8 +212,9 @@ def handle_batch_transition(self, transitions, sources, **kwargs):
204212
kwargs.pop("source")
205213
for submission in submissions:
206214
old_phase = transitions[submission.id]
215+
new_phase = submission.phase
207216
return self.handle_transition(
208-
old_phase=old_phase, source=submission, **kwargs
217+
old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs
209218
)
210219

211220
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}>: {old_phase.display_name} → {source.phase}"
52+
"{user} has updated the status of <{link}|{source.title_text_display}>: {source.phase.display_name} → {new_phase.display_name}"
5353
),
5454
MESSAGES.BATCH_TRANSITION: "handle_batch_transition",
5555
MESSAGES.DETERMINATION_OUTCOME: "handle_determination",

hypha/apply/activity/templates/messages/email/transition.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% load i18n %}
44

55
{% block content %}{# fmt:off #}
6-
{% blocktrans with old_status=old_phase.public_name new_status=source.phase.public_name %}Your application is now in "{{ new_status }}" status (progressed from "{{ old_status }}").{% endblocktrans %}
6+
{% blocktrans %}Your application is now in "{{ new_phase }}" status (progressed from "{{ old_phase }}").{% endblocktrans %}
77

88
{% trans "Please submit any questions related to your application here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %}
99
{% endblock %}{# fmt:on #}

hypha/apply/funds/models/submissions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,10 @@ def get_no_screening_status(self):
10381038
@status_field.on_success()
10391039
def log_status_update(self, descriptor, source, target, **kwargs):
10401040
instance = self
1041-
old_phase = self.workflow[source]
1041+
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]
10421045

10431046
by = kwargs["by"]
10441047
request = kwargs["request"]
@@ -1063,7 +1066,7 @@ def log_status_update(self, descriptor, source, target, **kwargs):
10631066
user=by,
10641067
request=request,
10651068
source=instance,
1066-
related=old_phase,
1069+
related=new_phase,
10671070
)
10681071

10691072
if instance.status in review_statuses:

0 commit comments

Comments
 (0)