Skip to content

Commit de1e4fe

Browse files
Update permission for Project document upload button (#4277)
Fixes #4275
1 parent e305cbb commit de1e4fe

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

hypha/apply/projects/permissions.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from django.conf import settings
22
from django.core.exceptions import PermissionDenied
3+
from rolepermissions.permissions import register_object_checker
34

45
from hypha.apply.activity.adapters.utils import get_users_for_groups
56
from hypha.apply.users.models import User
7+
from hypha.apply.users.roles import Staff
68

79
from .models.project import (
810
CLOSING,
@@ -401,6 +403,13 @@ def can_edit_paf(user, project):
401403
return False, "You are not allowed to edit the project at this time"
402404

403405

406+
@register_object_checker()
407+
def upload_project_documents(role, user, project) -> bool:
408+
if role == Staff:
409+
return True
410+
return False
411+
412+
404413
permissions_map = {
405414
"contract_approve": can_approve_contract,
406415
"contract_upload": can_upload_contract,

hypha/apply/projects/templates/application_projects/partials/supporting_documents.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% load i18n approval_tools project_tags heroicons %}
2+
{% load can from permission_tags %}
23

34
<li class="docs-block__row">
45
<div class="docs-block__row-inner">
@@ -36,7 +37,8 @@
3637
<p class="docs-block__document-info"><b>{{ latest_file.title }}</b> - {{ latest_file.created_at }}</p>
3738
{% endif %}
3839
</div>
39-
{% if document_category in remaining_document_categories %}
40+
{% can "upload_project_documents" object as can_upload_documents %}
41+
{% if document_category in remaining_document_categories and can_upload_documents %}
4042
<div class="docs-block__document-inner__actions">
4143
<a class="font-bold flex items-center me-0 hover:opacity-70 transition-opacity"
4244
href="{% url 'apply:projects:supporting_doc_upload' object.id document_category.id %}"

hypha/apply/projects/views/project.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from django_tables2 import SingleTableMixin
3535
from docx import Document
3636
from htmldocx import HtmlToDocx
37+
from rolepermissions.checkers import has_object_permission
3738

3839
from hypha.apply.activity.adapters.utils import get_users_for_groups
3940
from hypha.apply.activity.messaging import MESSAGES, messenger
@@ -277,7 +278,6 @@ def post(self, *args, **kwargs):
277278

278279

279280
# PROJECT DOCUMENTS
280-
@method_decorator(staff_required, name="dispatch")
281281
class UploadDocumentView(CreateView):
282282
form_class = UploadDocumentForm
283283
model = Project
@@ -288,7 +288,11 @@ def dispatch(self, request, *args, **kwargs):
288288
self.category = get_object_or_404(
289289
DocumentCategory, id=kwargs.get("category_pk")
290290
)
291-
# permission check
291+
permission = has_object_permission(
292+
"upload_project_documents", request.user, obj=self.project
293+
)
294+
if not permission:
295+
raise PermissionDenied()
292296
return super().dispatch(request, *args, **kwargs)
293297

294298
def get(self, *args, **kwargs):

0 commit comments

Comments
 (0)