Skip to content

Commit

Permalink
Make it possible to allow none/staff/staff admins to export submissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Sep 7, 2023
1 parent 19d69d9 commit 3fba646
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hypha/apply/dashboard/templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% endif %}

{% if rounds.closed or rounds.open %}
{% include "funds/includes/round-block.html" with closed_rounds=rounds.closed open_rounds=rounds.open title="Your rounds and labs" page_type='dashboard' %}
{% include "funds/includes/round-block.html" with can_export=can_export closed_rounds=rounds.closed open_rounds=rounds.open title="Your rounds and labs" page_type='dashboard' %}
{% endif %}

{% if paf_waiting_for_approval.count %}
Expand Down
2 changes: 2 additions & 0 deletions hypha/apply/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ReviewerSettings,
RoundsAndLabs,
)
from hypha.apply.funds.permissions import can_export_submissions
from hypha.apply.funds.tables import (
ReviewerSubmissionsTable,
SubmissionFilterAndSearch,
Expand Down Expand Up @@ -75,6 +76,7 @@ def get_context_data(self, **kwargs):
context.update({
'active_invoices': self.active_invoices(),
'awaiting_reviews': self.awaiting_reviews(submissions),
'can_export': can_export_submissions(self.request.user),
'my_reviewed': self.my_reviewed(submissions),
'projects': self.projects(),
'paf_waiting_for_approval': self.paf_waiting_for_approval(),
Expand Down
8 changes: 8 additions & 0 deletions hypha/apply/funds/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ def can_access_drafts(user):
return False


def can_export_submissions(user):
if user.is_apply_staff and settings.SUBMISSIONS_EXPORT_ACCESS_STAFF:
return True
if user.is_apply_staff_admin and settings.SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN:
return True
return False


def is_user_has_access_to_view_submission(user, submission):
if not user.is_authenticated:
return False, "Login Required"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
{% endif %}
</p>
<a class="round-block__view" href="{% url 'apply:rounds:detail' pk=round.pk %}">{% trans 'View' %}</a>
<a class="round-block__view" href="{% url 'apply:rounds:export' pk=round.pk %}">{% trans 'Export' %}</a>
{% if can_export %}
<a class="round-block__view" href="{% url 'apply:rounds:export' pk=round.pk %}">{% trans 'Export' %}</a>
{% endif %}
</li>
{% else %}
<li class="round-block__item round-block__item--more">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4 class="heading heading--normal heading--no-margin">{{ title }}</a></h4>
{% if page_type == 'dashboard' %}
{% include "funds/includes/no_round_block_dashboard.html" with rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% else %}
{% include "funds/includes/round-block-listing.html" with rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% include "funds/includes/round-block-listing.html" with can_export=can_export rounds=open_rounds display_text="Open until" query=open_query type="Open" %}
{% endif %}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% include "funds/includes/status-block.html" with type="Applications" %}

{% if closed_rounds or open_rounds %}
{% include "funds/includes/round-block.html" with closed_rounds=closed_rounds open_rounds=open_rounds title=rounds_title page_type='submission' %}
{% include "funds/includes/round-block.html" with can_export=can_export closed_rounds=closed_rounds open_rounds=open_rounds title=rounds_title page_type='submission' %}
{% endif %}

{% block table %}
Expand Down
12 changes: 10 additions & 2 deletions hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
from .permissions import (
can_access_archived_submissions,
can_access_drafts,
can_export_submissions,
has_permission,
)
from .tables import (
Expand Down Expand Up @@ -408,6 +409,7 @@ def get_table_data(self):
def get_context_data(self, **kwargs):
limit = 6
base_query = RoundsAndLabs.objects.with_progress().active().order_by('-end_date')
can_export = can_export_submissions(self.request.user)
open_rounds = base_query.open()[:limit]
open_query = '?round_state=open'
closed_rounds = base_query.closed()[:limit]
Expand All @@ -434,6 +436,7 @@ def get_context_data(self, **kwargs):
return super().get_context_data(
open_rounds=open_rounds,
open_query=open_query,
can_export=can_export,
closed_rounds=closed_rounds,
closed_query=closed_query,
rounds_title=rounds_title,
Expand Down Expand Up @@ -526,8 +529,9 @@ def get_queryset(self):
def test_func(self):
return self.request.user.is_apply_staff or self.request.user.is_reviewer

@method_decorator(staff_required, name='dispatch')
class ExportSubmissionsByRound(BaseAdminSubmissionsTable):

@method_decorator(login_required, name='dispatch')
class ExportSubmissionsByRound(UserPassesTestMixin, BaseAdminSubmissionsTable):

def export_submissions(self, round_id):
csv_stream = StringIO()
Expand Down Expand Up @@ -577,6 +581,10 @@ def get(self, request, pk):
response['Content-Disposition'] = 'inline; filename=' + str(self.obj) + '.csv'
return response

def test_func(self):
return can_export_submissions(self.request.user)


@method_decorator(staff_required, name='dispatch')
class SubmissionsByRound(BaseAdminSubmissionsTable, DelegateableListView):
template_name = 'funds/submissions_by_round.html'
Expand Down
6 changes: 6 additions & 0 deletions hypha/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
# Should staff admins be able to access/see draft submissions.
SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN = env.bool('SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN', False)

# Should staff be able to export submissions.
SUBMISSIONS_EXPORT_ACCESS_STAFF = env.bool('SUBMISSIONS_EXPORT_ACCESS_STAFF', True)

# Should staff admins be able to export submissions.
SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN = env.bool('SUBMISSIONS_EXPORT_ACCESS_STAFF_ADMIN', True)

# Columns to exclude from the submission tables.
# Possible values are: fund, round, status, lead, reviewers, screening_statuses, category_options, meta_terms, organization_name
SUBMISSIONS_TABLE_EXCLUDED_FIELDS = env.list('SUBMISSIONS_TABLE_EXCLUDED_FIELDS', ['organization_name'])
Expand Down

0 comments on commit 3fba646

Please sign in to comment.