Skip to content

Commit 477f029

Browse files
authored
Update communication view to be an independent page (#4414)
Depends on: - #3944 - #4413 What's changed: - project and submission to use the same communication page - update urls to point to the new page - update urls in email. - Cleanup the old comment view page code - new permission check added "view_comments" -- anyone with either access to project or submission will have access to it's comments page. Other updates: - Global activity feed has updated text for the comments - New function based view is use to show and add comment - Remove the use of tab.js on the submisison/project detail page, all the tabs are server-rendered full-page now. Fixes #4355
1 parent ae5dbf8 commit 477f029

26 files changed

+1303
-1226
lines changed

.test_durations

+771-733
Large diffs are not rendered by default.

hypha/apply/activity/adapters/activity_feed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def handle_paf_assignment(self, source, paf_approvals, **kwargs):
205205
]
206206
)
207207
users_sentence = " and".join(users.rsplit(",", 1))
208-
return _("Project form assigned to {}").format(users_sentence)
208+
return _("assigned Project form to {}").format(users_sentence)
209209
return None
210210

211211
def handle_task_removal(self, source, task, **kwargs):

hypha/apply/activity/adapters/emails.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def notify_comment(self, **kwargs):
252252
# Pass the user object to render_message rather than the email string
253253
recipient_obj = User.objects.get(email__exact=recipient)
254254
kwargs["recipient"] = recipient_obj
255-
if not comment.priviledged:
255+
if not comment.privileged:
256256
return self.render_message("messages/email/comment.html", **kwargs)
257257

258258
def recipients(self, message_type, source, user, **kwargs):

hypha/apply/activity/models.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ class Meta:
241241
base_manager_name = "objects"
242242

243243
def get_absolute_url(self):
244-
return f"{self.source.get_absolute_url()}#communications--{self.id}"
244+
# coverup for both submission and project as source.
245+
submission_id = (
246+
self.source.submission.id
247+
if hasattr(self.source, "submission")
248+
else self.source.id
249+
)
250+
return f"{reverse('funds:submissions:comments', args=[submission_id])}#communications--{self.id}"
245251

246252
@property
247-
def priviledged(self):
253+
def privileged(self):
248254
# Not visible to applicant
249255
return self.visibility not in [APPLICANT, PARTNER, APPLICANT_PARTNERS, ALL]
250256

hypha/apply/activity/templates/activity/include/comment_form.html

-41
This file was deleted.

hypha/apply/activity/templates/messages/email/applicant_base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{# fmt:off #}
77
{% block more_info %}{% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
88

9-
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
9+
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %}
1010

1111
{% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }}
1212

hypha/apply/activity/templates/messages/email/comment.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% display_name_for_email user as display_user %}
1010
{% blocktrans with title=source.title user=comment.user %}There has been a new comment on "{{ title }}" by {{ display_user }}.{% endblocktrans %}
1111

12-
{% trans "Read the full comment here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
12+
{% trans "Read the full comment here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment.get_absolute_url }}
1313
{% endblock %}
1414

1515
{% block more_info %}

hypha/apply/activity/templates/messages/email/contract_uploaded.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{% block more_info %}
2727
{% if request.user != source.user %}
2828
{% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
29-
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
29+
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.submission.pk %}
3030

3131
{% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }}
3232

hypha/apply/activity/templates/messages/email/invited_to_proposal.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{% block more_info %}
1010
{% trans "Here is the link to start creating your proposal" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
11-
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
11+
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %}
1212

1313
{% blocktrans %}The system will allow you to save a draft of your proposal as you work on it. When you feel it is ready for our review, please click the “Submit” button and we’ll know to take a look at it. We’ll reply to you with feedback on your Proposal as quickly as possible.{% endblocktrans %}
1414

hypha/apply/activity/templates/messages/email/ready_for_invoicing.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{% block more_info %}
1010
{% trans "Link to your project" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
11-
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
11+
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.submission.pk %}
1212

1313
{% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }}
1414

hypha/apply/activity/templates/messages/email/submission_confirmation.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
{% if source.is_draft %}{% trans "Please note that it is not submitted for review because it's still in draft." %} {% trans "You can access the draft at" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}{% else %}{% trans "We will review and reply to your submission as quickly as possible." %}{% endif %}
99

10-
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
10+
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %}
1111

1212
{% blocktrans %}If you have issues accessing the submission system or general inquiries, please email us at {{ ORG_EMAIL }}.{% endblocktrans %}
1313

hypha/apply/activity/templates/messages/email/transition.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
{% block content %}{# fmt:off #}
66
{% blocktrans with old_status=old_phase.public_name new_status=source.phase.public_name %}Your application is now in "{{ new_status }}" status (progressed from "{{ old_status }}").{% endblocktrans %}
77

8-
{% trans "Please submit any questions related to your application here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications
8+
{% trans "Please submit any questions related to your application here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.pk %}
99
{% endblock %}{# fmt:on #}

hypha/apply/activity/views.py

+14-65
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
from django.conf import settings
21
from django.contrib.auth.decorators import login_required
2+
from django.core.exceptions import PermissionDenied
33
from django.core.paginator import Paginator
44
from django.shortcuts import get_object_or_404, render
5-
from django.utils import timezone
65
from django.utils.decorators import method_decorator
76
from django.views.decorators.http import require_http_methods
8-
from django.views.generic import CreateView, ListView
9-
from django_ratelimit.decorators import ratelimit
7+
from django.views.generic import ListView
8+
from rolepermissions.checkers import has_object_permission
109

1110
from hypha.apply.funds.models.submissions import ApplicationSubmission
12-
from hypha.apply.funds.permissions import has_permission as has_funds_permission
1311
from hypha.apply.users.decorators import staff_required
1412
from hypha.apply.utils.storage import PrivateMediaView
15-
from hypha.apply.utils.views import DelegatedViewMixin
1613

1714
from . import services
1815
from .filters import NotificationFilter
19-
from .forms import CommentForm
20-
from .messaging import MESSAGES, messenger
2116
from .models import COMMENT, Activity, ActivityAttachment
2217

2318

@@ -39,13 +34,13 @@ def partial_comments(request, pk: int):
3934
Returns:
4035
HttpResponse: The rendered 'activity_list' template with the context data.
4136
"""
42-
obj = get_object_or_404(ApplicationSubmission, pk=pk)
43-
has_funds_permission(
44-
"submission_view", request.user, object=obj, raise_exception=True
45-
)
46-
editable = not obj.is_archive
37+
submission = get_object_or_404(ApplicationSubmission, pk=pk)
38+
if not has_object_permission("view_comments", request.user, submission):
39+
raise PermissionDenied
4740

48-
qs = services.get_related_activities_for_user(obj, request.user)
41+
editable = not submission.is_archive
42+
43+
qs = services.get_related_activities_for_user(submission, request.user)
4944
page = Paginator(qs, per_page=10, orphans=5).page(request.GET.get("page", 1))
5045

5146
ctx = {
@@ -87,66 +82,20 @@ class ActivityContextMixin:
8782
"""Mixin to add related 'comments' of the current view's 'self.object'"""
8883

8984
def get_context_data(self, **kwargs):
90-
# Do not prefetch on the related_object__author as the models
91-
# are not homogeneous and this will fail
92-
activities = services.get_related_activities_for_user(
93-
self.object, self.request.user
94-
)
95-
9685
# Comments for both projects and applications exist under the original application
9786
if isinstance(self.object, ApplicationSubmission):
9887
application_obj = self.object
9988
else:
10089
application_obj = self.object.submission
10190

102-
comments_count = services.get_comment_count(application_obj, self.request.user)
103-
104-
extra = {"activities": activities, "comments_count": comments_count}
91+
extra = {
92+
"comments_count": services.get_comment_count(
93+
application_obj, self.request.user
94+
)
95+
}
10596
return super().get_context_data(**extra, **kwargs)
10697

10798

108-
@method_decorator(
109-
ratelimit(key="user", rate=settings.DEFAULT_RATE_LIMIT, method="POST"),
110-
name="dispatch",
111-
)
112-
class CommentFormView(DelegatedViewMixin, CreateView):
113-
form_class = CommentForm
114-
context_name = "comment_form"
115-
116-
def form_valid(self, form):
117-
source = self.kwargs["object"]
118-
form.instance.user = self.request.user
119-
form.instance.source = source
120-
form.instance.type = COMMENT
121-
form.instance.timestamp = timezone.now()
122-
response = super().form_valid(form)
123-
messenger(
124-
MESSAGES.COMMENT,
125-
request=self.request,
126-
user=self.request.user,
127-
source=source,
128-
related=self.object,
129-
)
130-
return response
131-
132-
def get_success_url(self):
133-
return self.object.source.get_absolute_url() + "#communications"
134-
135-
def get_form_kwargs(self) -> dict:
136-
"""Get the kwargs for the [`CommentForm`][hypha.apply.activity.forms.CommentForm].
137-
138-
Returns:
139-
A dict of kwargs to be passed to [`CommentForm`][hypha.apply.activity.forms.CommentForm].
140-
The submission instance is removed from this return, while a boolean of `has_partners` is
141-
added based off the submission.
142-
"""
143-
kwargs = super().get_form_kwargs()
144-
instance = kwargs.pop("instance")
145-
if isinstance(instance, ApplicationSubmission):
146-
kwargs["submission_partner_list"] = instance.partners.all()
147-
return kwargs
148-
149-
15099
class AttachmentView(PrivateMediaView):
151100
model = ActivityAttachment
152101

hypha/apply/funds/permissions.py

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ def can_edit_submission(user, submission):
2727
return True, ""
2828

2929

30+
@register_object_checker()
31+
def view_comments(role, user, submission) -> bool:
32+
from hypha.apply.projects.permissions import can_access_project
33+
34+
if role == StaffAdmin:
35+
return True
36+
37+
if is_user_has_access_to_view_submission(user, submission):
38+
return True
39+
40+
if submission.project and can_access_project(user, submission.project):
41+
return True
42+
43+
return False
44+
45+
3046
@register_object_checker()
3147
def delete_submission(role, user, submission) -> bool:
3248
"""

0 commit comments

Comments
 (0)