From fdecd1541a49c4429c6d13c29ee644213e19e913 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Thu, 26 Jul 2018 17:49:26 +0100 Subject: [PATCH] Add transition, outcome and proposal messages for slack --- opentech/apply/activity/messaging.py | 4 ++++ opentech/apply/determinations/forms.py | 4 ++-- opentech/apply/funds/models.py | 5 +++-- opentech/apply/funds/views.py | 14 +++++++++++--- opentech/apply/funds/workflow.py | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/opentech/apply/activity/messaging.py b/opentech/apply/activity/messaging.py index bac259cb5..415b9e029 100644 --- a/opentech/apply/activity/messaging.py +++ b/opentech/apply/activity/messaging.py @@ -22,6 +22,7 @@ class MESSAGES(Enum): REVIEWERS_UPDATED = 'reviewers_updated' NEW_REVIEW = 'new_review' COMMENT = 'comment' + PROPOSAL_SUBMITTED = 'proposal_submitted' class AdapterBase: @@ -98,6 +99,9 @@ class SlackAdapter(AdapterBase): MESSAGES.UPDATE_LEAD: 'The lead of <{link}|{submission.title}> has been updated from {old.lead} to {submission.lead} by {user}', MESSAGES.COMMENT: 'A new comment has been posted on <{link}|{submission.title}>', MESSAGES.REVIEWERS_UPDATED: '{user} has updated the reviewers on <{link}|{submission.title}>', + MESSAGES.TRANSITION: '{user} has updated the status of <{link}|{submission.title}>: {old_phase.display_name} → {submission.phase}', + MESSAGES.DETERMINATION_OUTCOME: 'A determination for <{link}|{submission.title}> was sent by email: {submission.determination.get_outcome_display}', + MESSAGES.PROPOSAL_SUBMITTED: 'A proposal has been submitted for review: <{link}|{submission.title}>', } def __init__(self): diff --git a/opentech/apply/determinations/forms.py b/opentech/apply/determinations/forms.py index 9ad3f2652..900485459 100644 --- a/opentech/apply/determinations/forms.py +++ b/opentech/apply/determinations/forms.py @@ -1,7 +1,7 @@ from django import forms from django.core.exceptions import NON_FIELD_ERRORS -from opentech.apply.funds.workflow import DETERMINATION_RESPONSE_TRANSITIONS +from opentech.apply.funds.workflow import DETERMINATION_OUTCOMES from .models import Determination, DETERMINATION_CHOICES, NEEDS_MORE_INFO, REJECTED, ACCEPTED, \ DETERMINATION_TRANSITION_SUFFIX @@ -75,7 +75,7 @@ class BaseDeterminationForm(forms.ModelForm): return super().save(commit) def get_determination_from_action_name(self, action_name): - if action_name in DETERMINATION_RESPONSE_TRANSITIONS: + if action_name in DETERMINATION_OUTCOMES: if 'more_info' in action_name: return NEEDS_MORE_INFO elif 'accepted' in action_name or 'invited_to_proposal' in action_name: diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 8c93ec46e..be3a73359 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -46,13 +46,14 @@ from .blocks import ApplicationCustomFormFieldsBlock, REQUIRED_BLOCK_NAMES from .edit_handlers import FilteredFieldPanel, ReadOnlyPanel, ReadOnlyInlinePanel from .workflow import ( active_statuses, + DETERMINATION_OUTCOMES, + DETERMINATION_PHASES, + DETERMINATION_RESPONSE_PHASES, get_review_statuses, INITIAL_STATE, review_statuses, UserPermissions, WORKFLOWS, - DETERMINATION_PHASES, - DETERMINATION_RESPONSE_PHASES, ) LIMIT_TO_STAFF = {'groups__name': STAFF_GROUP_NAME} diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 0f0f962f0..30fb9d80f 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -19,7 +19,7 @@ from opentech.apply.activity.views import ( DelegatedViewMixin, ) from opentech.apply.activity.messaging import messenger, MESSAGES -from opentech.apply.funds.workflow import DETERMINATION_RESPONSE_TRANSITIONS +from opentech.apply.funds.workflow import DETERMINATION_OUTCOMES from opentech.apply.review.views import ReviewContextMixin from opentech.apply.users.decorators import staff_required from opentech.apply.utils.views import DelegateableView, ViewDispatcher @@ -38,7 +38,7 @@ class SubmissionListView(AllActivityContextMixin, SingleTableMixin, FilterView): filterset_class = SubmissionFilter def get_queryset(self): - return self.filterset_class._meta.model.objects.current() + return self.filterset_class._meta.model.objects.active().current() def get_context_data(self, **kwargs): active_filters = self.filterset.data @@ -77,13 +77,21 @@ class ProgressSubmissionView(DelegatedViewMixin, UpdateView): def form_valid(self, form): action = form.cleaned_data.get('action') # Defer to the determination form for any of the determination transitions - if action in DETERMINATION_RESPONSE_TRANSITIONS: + if action in DETERMINATION_OUTCOMES and not self.object.determination.submitted: return HttpResponseRedirect(reverse_lazy( 'apply:submissions:determinations:form', args=(form.instance.id,)) + "?action=" + action) self.object.perform_transition(action, self.request.user, request=self.request) + if object.phase.name == 'proposal_discussion' and action == 'proposal_discussion': + messenger( + MESSAGES.PROPOSAL_SUBMITTED, + request=self.request, + user=self.request.user, + submission=self.object.instance, + ) + return super().form_valid(form) diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 3d1afa63f..2f7dca237 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -427,4 +427,4 @@ def get_determination_transitions(): return transitions -DETERMINATION_RESPONSE_TRANSITIONS = get_determination_transitions() +DETERMINATION_OUTCOMES = get_determination_transitions() -- GitLab