From fa407d4c0bf1af4abf59ec4afec490051eb58552 Mon Sep 17 00:00:00 2001 From: Parbhat Puri <parbhatpuri17@gmail.com> Date: Mon, 22 Apr 2019 08:57:05 +0000 Subject: [PATCH] GH-1147: Partner submission list show submissions which user can review, edit. Minor refactoring. --- .../templates/dashboard/community_dashboard.html | 4 ++-- .../templates/dashboard/partner_dashboard.html | 4 ++-- .../templates/dashboard/reviewer_dashboard.html | 4 ++-- opentech/apply/dashboard/views.py | 12 ++++++------ opentech/apply/funds/models/submissions.py | 4 +++- opentech/apply/funds/workflow.py | 12 ++++++++++++ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/opentech/apply/dashboard/templates/dashboard/community_dashboard.html b/opentech/apply/dashboard/templates/dashboard/community_dashboard.html index 27d49cb7d..54d510d4f 100644 --- a/opentech/apply/dashboard/templates/dashboard/community_dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/community_dashboard.html @@ -66,10 +66,10 @@ {% endfor %} </div> - {% if my_inactive_submissions_table.data %} + {% if my_inactive_submissions.data %} <div class="wrapper wrapper--bottom-space"> <h4 class="heading heading--normal">Submission history</h4> - {% render_table my_inactive_submissions_table %} + {% render_table my_inactive_submissions %} </div> {% endif %} </div> diff --git a/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html b/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html index 7bbd5c514..ad7443b2f 100644 --- a/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/partner_dashboard.html @@ -60,10 +60,10 @@ {% endfor %} </div> - {% if my_inactive_submissions_table.data %} + {% if my_inactive_submissions.data %} <div class="wrapper wrapper--bottom-space"> <h4 class="heading heading--normal">Submission history</h4> - {% render_table my_inactive_submissions_table %} + {% render_table my_inactive_submissions %} </div> {% endif %} </div> diff --git a/opentech/apply/dashboard/templates/dashboard/reviewer_dashboard.html b/opentech/apply/dashboard/templates/dashboard/reviewer_dashboard.html index 70d41e53c..e95f835c1 100644 --- a/opentech/apply/dashboard/templates/dashboard/reviewer_dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/reviewer_dashboard.html @@ -63,10 +63,10 @@ {% endfor %} </div> - {% if my_inactive_submissions_table.data %} + {% if my_inactive_submissions.data %} <div class="wrapper wrapper--bottom-space"> <h4 class="heading heading--normal">Submission history</h4> - {% render_table my_inactive_submissions_table %} + {% render_table my_inactive_submissions %} </div> {% endif %} </div> diff --git a/opentech/apply/dashboard/views.py b/opentech/apply/dashboard/views.py index 91a41a7ed..098a172cf 100644 --- a/opentech/apply/dashboard/views.py +++ b/opentech/apply/dashboard/views.py @@ -109,7 +109,7 @@ class ReviewerDashboardView(TemplateView): active_statuses_filter = ''.join(f'&status={status}' for status in review_filter_for_user(request.user)) # Applications by reviewer - my_submissions, my_inactive_submissions_table = self.get_my_submissions(request, qs) + my_submissions, my_inactive_submissions = self.get_my_submissions(request, qs) context = { 'my_review': my_review, @@ -120,7 +120,7 @@ class ReviewerDashboardView(TemplateView): 'filter': filterset, 'active_statuses_filter': active_statuses_filter, 'my_submissions': my_submissions, - 'my_inactive_submissions_table': my_inactive_submissions_table, + 'my_inactive_submissions': my_inactive_submissions, } return render(request, 'dashboard/reviewer_dashboard.html', context) @@ -213,14 +213,14 @@ class PartnerDashboardView(TemplateView): my_reviewed_qs, my_reviewed = self.get_my_reviewed(self.request, qs) # Applications by partner - my_submissions, my_inactive_submissions_table = self.get_my_submissions(self.request, qs) + my_submissions, my_inactive_submissions = self.get_my_submissions(self.request, qs) context.update({ 'partner_submissions': partner_submissions, 'partner_submissions_count': partner_submissions_qs.count(), 'my_reviewed': my_reviewed, 'my_submissions': my_submissions, - 'my_inactive_submissions_table': my_inactive_submissions_table, + 'my_inactive_submissions': my_inactive_submissions, }) return context @@ -266,14 +266,14 @@ class CommunityDashboardView(TemplateView): my_reviewed_qs, my_reviewed = self.get_my_reviewed(self.request, qs) # Applications by partner - my_submissions, my_inactive_submissions_table = self.get_my_submissions(self.request, qs) + my_submissions, my_inactive_submissions = self.get_my_submissions(self.request, qs) context.update({ 'my_community_review': my_community_review, 'my_community_review_count': my_community_review_qs.count(), 'my_reviewed': my_reviewed, 'my_submissions': my_submissions, - 'my_inactive_submissions_table': my_inactive_submissions_table, + 'my_inactive_submissions': my_inactive_submissions, }) return context diff --git a/opentech/apply/funds/models/submissions.py b/opentech/apply/funds/models/submissions.py index 9744ff26c..4eaf78a92 100644 --- a/opentech/apply/funds/models/submissions.py +++ b/opentech/apply/funds/models/submissions.py @@ -34,6 +34,7 @@ from ..workflow import ( active_statuses, DETERMINATION_RESPONSE_PHASES, get_review_active_statuses, + get_edit_or_review_active_statuses, INITIAL_STATE, PHASES, review_statuses, @@ -102,7 +103,8 @@ class ApplicationSubmissionQueryset(JSONOrderable): return self.filter(reviews__author=user) def partner_for(self, user): - return self.filter(partners=user) + user_edit_review_statuses = get_edit_or_review_active_statuses(user) + return self.filter(partners=user, status__in=user_edit_review_statuses) def awaiting_determination_for(self, user): return self.filter(status__in=DETERMINATION_RESPONSE_PHASES).filter(lead=user) diff --git a/opentech/apply/funds/workflow.py b/opentech/apply/funds/workflow.py index 76958755c..ece64e35a 100644 --- a/opentech/apply/funds/workflow.py +++ b/opentech/apply/funds/workflow.py @@ -871,6 +871,18 @@ def get_review_active_statuses(user=None): return reviews +def get_edit_or_review_active_statuses(user=None): + statuses = set() + + for phase_name, phase in PHASES: + if phase_name in active_statuses: + if user is None: + statuses.add(phase_name) + elif phase.permissions.can_review(user) or phase.permissions.can_edit(user): + statuses.add(phase_name) + return statuses + + def get_review_statuses(user=None): reviews = set() -- GitLab