From 14006f9f1c354bf98d2575cc4edd12792848033e Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Wed, 29 May 2019 11:21:19 +0200 Subject: [PATCH] Automatically update status on submission when reviewers are added and reviews submitted. --- opentech/apply/funds/views.py | 15 ++++++++++++++- opentech/apply/funds/workflow.py | 18 +++++++++--------- opentech/apply/review/views.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 135988c9c..0f9d8bab2 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -59,7 +59,7 @@ from .tables import ( SubmissionReviewerFilterAndSearch, SummarySubmissionsTable, ) -from .workflow import STAGE_CHANGE_ACTIONS, PHASES_MAPPING, review_statuses +from .workflow import INITIAL_STATE, STAGE_CHANGE_ACTIONS, PHASES_MAPPING, review_statuses from .permissions import is_user_has_access_to_view_submission submission_storage = get_storage_class(getattr(settings, 'PRIVATE_FILE_STORAGE', None))() @@ -409,6 +409,19 @@ class UpdateReviewersView(DelegatedViewMixin, UpdateView): removed=removed, ) + if added and self.object.status == INITIAL_STATE: + # Automatically transition the submission to "Internal review". + action = self.object.workflow.stepped_phases[1][0].name + try: + self.object.perform_transition( + action, + self.request.user, + request=self.request, + notify=False, + ) + except (PermissionDenied, KeyError): + pass + return response diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 1de885928..c1ddbf9a6 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -446,26 +446,26 @@ SingleStageCommunityDefinition = [ }, }, { - 'com_community_review': { + 'com_internal_review': { 'transitions': { - 'com_internal_review': 'Open Review', + 'com_community_review': 'Open Community Review', + 'com_post_review_discussion': 'Close Review', 'com_rejected': 'Dismiss', }, - 'display': 'Community Review', + 'display': 'Internal Review', 'public': 'OTF Review', 'stage': RequestCom, - 'permissions': community_review_permissions, + 'permissions': default_permissions, }, - }, - { - 'com_internal_review': { + 'com_community_review': { 'transitions': { 'com_post_review_discussion': 'Close Review', + 'com_rejected': 'Dismiss', }, - 'display': 'Internal Review', + 'display': 'Community Review', 'public': 'OTF Review', 'stage': RequestCom, - 'permissions': default_permissions, + 'permissions': community_review_permissions, }, }, { diff --git a/opentech/apply/review/views.py b/opentech/apply/review/views.py index a7dc4778f..dfe1f18cc 100644 --- a/opentech/apply/review/views.py +++ b/opentech/apply/review/views.py @@ -12,6 +12,7 @@ from wagtail.core.blocks import RichTextBlock from opentech.apply.activity.messaging import messenger, MESSAGES from opentech.apply.funds.models import ApplicationSubmission, AssignedReviewers +from opentech.apply.funds.workflow import INITIAL_STATE from opentech.apply.review.blocks import RecommendationBlock, RecommendationCommentsBlock from opentech.apply.review.forms import ReviewModelForm, ReviewOpinionForm from opentech.apply.stream_forms.models import BaseStreamForm @@ -111,6 +112,33 @@ class ReviewCreateOrUpdateView(BaseStreamForm, CreateOrUpdateView): submission=self.submission, related=self.object, ) + + submission_stepped_phases = self.submission.workflow.stepped_phases + if self.submission.status == INITIAL_STATE: + # Automatically transition the submission to "Internal review". + action = submission_stepped_phases[1][0].name + try: + self.submission.perform_transition( + action, + self.request.user, + request=self.request, + notify=False, + ) + except (PermissionDenied, KeyError): + pass + elif self.submission.status == submission_stepped_phases[1][0].name and self.submission.reviews.count() > 1: + # Automatically transition the submission to "Ready for discussion". + action = submission_stepped_phases[2][0].name + try: + self.submission.perform_transition( + action, + self.request.user, + request=self.request, + notify=False, + ) + except (PermissionDenied, KeyError): + pass + return response def get_success_url(self): -- GitLab