Skip to content

Commit c740ec6

Browse files
Restrict permission to invite and update co-applicant in archived submissions and complete projects (#4596)
1 parent f66268c commit c740ec6

3 files changed

Lines changed: 73 additions & 17 deletions

File tree

hypha/apply/funds/permissions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ def can_view_submission_screening(user, submission):
236236

237237

238238
def can_invite_co_applicants(user, submission):
239+
if submission.is_archive:
240+
return False, "Co-applicant can't be added to archived submission"
241+
if hasattr(submission, "project"):
242+
from hypha.apply.projects.models.project import COMPLETE
243+
244+
if submission.project.status == COMPLETE:
245+
return False, "Co-applicants can't be invited to completed projects"
239246
if (
240247
submission.co_applicant_invites.all().count()
241248
>= settings.SUBMISSIONS_COAPPLICANT_INVITES_LIMIT
@@ -257,6 +264,13 @@ def can_view_co_applicants(user, submission):
257264

258265

259266
def can_update_co_applicant(user, invite):
267+
if invite.submission.is_archive:
268+
return False, "Co-applicant can't be updated to archived submission"
269+
if hasattr(invite.submission, "project"):
270+
from hypha.apply.projects.models.project import COMPLETE
271+
272+
if invite.submission.project.status == COMPLETE:
273+
return False, "Co-applicants can't be updated to completed projects"
260274
if invite.invited_by == user:
261275
return True, "Same user who invited can delete the co-applicant"
262276
if invite.submission.user == user:

hypha/apply/funds/templates/funds/includes/co-applicant-block.html

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n heroicons %}
1+
{% load i18n heroicons co-applicant_tags %}
22

33
<div class="sidebar__inner sidebar__inner--actions" data-testid="sidebar-primary-actions">
44
<details {% if user.is_applicant or not co_applicants %} open {% endif %} class="group">
@@ -7,11 +7,12 @@
77
{% trans "Co-applicants" %} <span class="text-base font-medium"> ({{ co_applicants.count }})</span>
88
{% heroicon_solid "chevron-down" size="16" class="w-4 h-4 transition-transform rotate-90 ms-2 group-open:rotate-0" %}
99
</p>
10+
{% can_invite_coapplicant user object as can_invite %}
1011
<button
1112
class="flex items-center py-1 pr-4 pl-2 font-bold rounded-sm -me-2 {% if object.co_applicant_invites.count >= invite_max_limit %} text-blue-200 {% else %}transition-colors cursor-pointer text-dark-blue hover:bg-slate-200{% endif %}"
1213
hx-get="{% url 'apply:submissions:invite_co_applicant' pk=object.id %}"
1314
hx-target="#htmx-modal"
14-
{% if object.co_applicant_invites.count >= invite_max_limit %}disabled title='{% trans "Max limit reached" %}'{% endif %}
15+
{% if not can_invite %}disabled title='{% trans "Not allowed" %}'{% endif %}
1516
role="button"
1617
aria-label="{% trans "Invite co-applicant" %}"
1718
>
@@ -27,25 +28,39 @@
2728
{% if co_applicants %}
2829
<div class="flex flex-col gap-2 justify-between">
2930
{% for invite in co_applicants %}
30-
31+
{% can_update_coapplicant user invite as can_update %}
3132
<div>
32-
<a
33-
class="font-bold line-clamp-2 group/coapplicant"
34-
href="{% url 'apply:submissions:edit_co_applicant' invite_pk=invite.id %}"
35-
hx-get="{% url 'apply:submissions:edit_co_applicant' invite_pk=invite.id %}"
36-
hx-target="#htmx-modal"
37-
>
38-
<div class="flex justify-between">
39-
{% if invite.status == "accepted" %}
40-
{{ invite.co_applicant.user }}
41-
{% else %}
42-
{{ invite.invited_user_email }}
43-
{% endif %}
33+
{% if can_update %}
34+
<a
35+
class="font-bold line-clamp-2 group/coapplicant"
36+
href="{% url 'apply:submissions:edit_co_applicant' invite_pk=invite.id %}"
37+
hx-get="{% url 'apply:submissions:edit_co_applicant' invite_pk=invite.id %}"
38+
hx-target="#htmx-modal"
39+
>
40+
<div class="flex justify-between">
41+
{% if invite.status == "accepted" %}
42+
{{ invite.co_applicant.user }}
43+
{% else %}
44+
{{ invite.invited_user_email }}
45+
{% endif %}
46+
47+
{% heroicon_solid "pencil" class="hidden align-middle me-1 group-hover/coapplicant:inline" width=16 height=16 stroke_width=2 aria_hidden=true %}
4448

45-
{% heroicon_solid "pencil" class="hidden align-middle me-1 group-hover/coapplicant:inline" width=16 height=16 stroke_width=2 aria_hidden=true %}
49+
</div>
50+
</a>
51+
{% else %}
52+
<div class="font-bold line-clamp-2 group/coapplicant">
53+
<div class="flex justify-between">
54+
{% if invite.status == "accepted" %}
55+
{{ invite.co_applicant.user }}
56+
{% else %}
57+
{{ invite.invited_user_email }}
58+
{% endif %}
4659

60+
</div>
4761
</div>
48-
</a>
62+
{% endif %}
63+
4964
{% if invite.status == "accepted" %}
5065
<div class="text-xs text-fg-muted" >{{ invite.co_applicant.get_role_display }}</div>
5166
{% else %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django import template
2+
3+
from hypha.apply.funds.permissions import has_permission
4+
5+
register = template.Library()
6+
7+
8+
@register.simple_tag
9+
def can_invite_coapplicant(user, submission):
10+
permission, _ = has_permission(
11+
"co_applicant_invite",
12+
user,
13+
object=submission,
14+
raise_exception=False,
15+
)
16+
return permission
17+
18+
19+
@register.simple_tag
20+
def can_update_coapplicant(user, invite):
21+
permission, _ = has_permission(
22+
"co_applicants_update",
23+
user,
24+
object=invite,
25+
raise_exception=False,
26+
)
27+
return permission

0 commit comments

Comments
 (0)