Skip to content

Commit

Permalink
Merge branch 'submission-table-view' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Sep 5, 2024
2 parents 729a2bd + d79327a commit 84868c4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hypha/apply/funds/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def can_change_external_reviewers(user, submission) -> bool:
return False


def can_access_drafts(user):
def can_access_drafts(user) -> bool:
if user.is_apply_staff and settings.SUBMISSIONS_DRAFT_ACCESS_STAFF:
return True
if user.is_apply_staff_admin and settings.SUBMISSIONS_DRAFT_ACCESS_STAFF_ADMIN:
return True
return False


def can_export_submissions(user):
def can_export_submissions(user) -> bool:
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:
Expand Down
23 changes: 22 additions & 1 deletion hypha/apply/funds/templates/submissions/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<form method="GET" action="./" class="flex items-center justify-between gap-2 mt-3 md:gap-4">
{% for key, value in request.GET.items %}
{% if key != 'archived' %}<input type="hidden" class="js-filter-options" value="{{ value}}" name="{{ key }}">{% endif %}
{% if key != 'archived' and key != 'drafts' %}<input type="hidden" class="js-filter-options" value="{{ value}}" name="{{ key }}">{% endif %}
{% endfor %}

{% dropdown_menu title="Filters" heading="Filter submissions" %}
Expand Down Expand Up @@ -136,6 +136,27 @@
</label>
</span>
{% endif %}

{% if can_access_drafts %}
<span>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" {% if show_drafts %}checked{% endif %}
class="sr-only peer"
name="drafts"
hx-push-url="true"
hx-get="./"
hx-swap="outerHTML"
hx-include="input.js-filter-options:not([name=drafts])"
hx-target="#main"
>
<div
class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600">
</div>
<span class="text-sm font-medium text-gray-600 ms-3">{% trans "Drafts" %}</span>
</label>
</span>
{% endif %}

{% if can_export_submissions %}
<a
class="px-2 py-1.5 transition-colors border rounded hover:bg-gray-100 shadow-sm"
Expand Down
6 changes: 5 additions & 1 deletion hypha/apply/funds/views_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def submission_all_beta(
search_term, search_filters = parsed_query["text"], parsed_query["filters"]

show_archived = request.GET.get("archived", False) == "on"
show_drafts = request.GET.get("drafts", False) == "on"
selected_funds = request.GET.getlist("fund")
selected_rounds = request.GET.getlist("round")
selected_leads = request.GET.getlist("lead")
Expand All @@ -89,6 +90,7 @@ def submission_all_beta(
page = request.GET.get("page", 1)

can_view_archives = permissions.can_view_archived_submissions(request.user)
can_access_drafts = permissions.can_access_drafts(request.user)

selected_fund_objects = (
Page.objects.filter(id__in=selected_funds) if selected_funds else []
Expand All @@ -109,7 +111,7 @@ def submission_all_beta(
else:
qs = ApplicationSubmission.objects.current().for_table(request.user)

if not permissions.can_access_drafts(request.user):
if not can_access_drafts or not show_drafts:
qs = qs.exclude_draft()

if "submitted" in search_filters:
Expand Down Expand Up @@ -258,6 +260,7 @@ def submission_all_beta(
"submissions": page.object_list,
"submission_ids": [x.id for x in page.object_list],
"show_archived": show_archived,
"show_drafts": show_drafts,
"selected_funds": selected_funds,
"selected_fund_objects": selected_fund_objects,
"selected_rounds": selected_rounds,
Expand All @@ -274,6 +277,7 @@ def submission_all_beta(
"is_filtered": is_filtered,
"duration": end - start,
"can_view_archive": can_view_archives,
"can_access_drafts": can_access_drafts,
"can_bulk_archive": permissions.can_bulk_archive_submissions(request.user),
"can_bulk_delete": permissions.can_bulk_delete_submissions(request.user),
"can_export_submissions": permissions.can_export_submissions(request.user),
Expand Down

0 comments on commit 84868c4

Please sign in to comment.