diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 135988c9cc3ec3bb77221f58b9d21b016a276c01..0f9d8bab2fdf721d377eb9939fce29be5d0b0490 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 1de8859281a27f100d2efcd9613109fb38bc43a7..c1ddbf9a6746454d6535b41e2b238f7959d28054 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 a7dc4778f49ba12f7624faceac84c17270f9791d..dfe1f18ccead3b3bf3e20bb3a472c4dcb84fa7ed 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):