diff --git a/hypha/apply/activity/forms.py b/hypha/apply/activity/forms.py index 0b44702d73..6fe9c5e0b7 100644 --- a/hypha/apply/activity/forms.py +++ b/hypha/apply/activity/forms.py @@ -75,7 +75,7 @@ def save(self, commit=True): code=COMMENT_TASK, message=instance.message, user=assigned_user, - related_obj=instance.source, + related_obj=instance, ) added_files = self.cleaned_data["attachments"] if added_files: diff --git a/hypha/apply/activity/models.py b/hypha/apply/activity/models.py index 06f8b9edac..75ecf3be94 100644 --- a/hypha/apply/activity/models.py +++ b/hypha/apply/activity/models.py @@ -245,6 +245,17 @@ def priviledged(self): # Not visible to applicant return self.visibility not in [APPLICANT, PARTNER, APPLICANT_PARTNERS, ALL] + # @property + def get_absolute_url(self): + if self.type == COMMENT: + return "{source_link}#communications".format( + source_link=self.source.get_absolute_url() + ) + else: + return "{source_link}#activity_feed".format( + source_link=self.source.get_absolute_url() + ) + @property def private(self): # not visible to all diff --git a/hypha/apply/activity/templates/activity/include/listing_base.html b/hypha/apply/activity/templates/activity/include/listing_base.html index 0179a6d8f0..2eabe360bf 100644 --- a/hypha/apply/activity/templates/activity/include/listing_base.html +++ b/hypha/apply/activity/templates/activity/include/listing_base.html @@ -20,6 +20,9 @@ {% trans "edited" %} {% endif %}

+ {% if request.user.is_apply_staff %} +

+ {% endif %} {% if editable and activity.user == request.user %}

diff --git a/hypha/apply/activity/templates/activity/partials/assigned_activity.html b/hypha/apply/activity/templates/activity/partials/assigned_activity.html new file mode 100644 index 0000000000..892fcbb3e9 --- /dev/null +++ b/hypha/apply/activity/templates/activity/partials/assigned_activity.html @@ -0,0 +1,5 @@ +{% load i18n %} + +{% if assigned_to %} +

{% trans "Assigned as task to: " %} {{ assigned_to }}

+{% endif %} diff --git a/hypha/apply/activity/urls.py b/hypha/apply/activity/urls.py index 4ec8389522..b51dc9dbbd 100644 --- a/hypha/apply/activity/urls.py +++ b/hypha/apply/activity/urls.py @@ -1,6 +1,6 @@ from django.urls import include, path -from .views import AttachmentView, NotificationsView +from .views import AttachmentView, NotificationsView, get_activity_assgined_user app_name = "activity" @@ -13,4 +13,5 @@ AttachmentView.as_view(), name="attachment", ), + path("activity//assigned/", get_activity_assgined_user, name="assigned"), ] diff --git a/hypha/apply/activity/views.py b/hypha/apply/activity/views.py index 6f14dad786..58722fc4e7 100644 --- a/hypha/apply/activity/views.py +++ b/hypha/apply/activity/views.py @@ -1,12 +1,15 @@ from django.conf import settings -from django.shortcuts import get_object_or_404 +from django.contrib.auth.decorators import login_required, user_passes_test +from django.contrib.contenttypes.models import ContentType +from django.shortcuts import get_object_or_404, render from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import CreateView, ListView from django_ratelimit.decorators import ratelimit from hypha.apply.funds.models.submissions import ApplicationSubmission -from hypha.apply.users.decorators import staff_required +from hypha.apply.todo.models import Task +from hypha.apply.users.decorators import is_apply_staff, staff_required from hypha.apply.utils.storage import PrivateMediaView from hypha.apply.utils.views import DelegatedViewMixin @@ -108,3 +111,19 @@ def get_context_data(self, *, object_list=None, **kwargs): context = super(NotificationsView, self).get_context_data() context["filter"] = self.filterset return context + + +@login_required +@user_passes_test(is_apply_staff) +def get_activity_assgined_user(request, *args, **kwargs): + activity = get_object_or_404(Activity, pk=kwargs.get("pk")) + task = Task.objects.filter( + related_content_type=ContentType.objects.get_for_model(activity).id, + related_object_id=activity.id, + ).first() + assigned_to = task.user if task else None + return render( + request, + "activity/partials/assigned_activity.html", + context={"assigned_to": assigned_to}, + ) diff --git a/hypha/apply/todo/options.py b/hypha/apply/todo/options.py index 311748322b..185fcf1793 100644 --- a/hypha/apply/todo/options.py +++ b/hypha/apply/todo/options.py @@ -48,7 +48,7 @@ COMMENT_TASK: { "text": _("{msg}"), "icon": "comment", - "url": "{link}#communications", + "url": "{link}", "type": _("Comment"), }, # SUBMISSIONS ACTIONS diff --git a/hypha/apply/todo/views.py b/hypha/apply/todo/views.py index 39c3ca9fe0..cd813aee63 100644 --- a/hypha/apply/todo/views.py +++ b/hypha/apply/todo/views.py @@ -85,6 +85,7 @@ def dispatch(self, request, *args, **kwargs): def delete(self, *args, **kwargs): source = self.task.related_object + from hypha.apply.activity.models import Activity from hypha.apply.determinations.models import Determination from hypha.apply.projects.models import Invoice from hypha.apply.review.models import Review @@ -95,6 +96,8 @@ def delete(self, *args, **kwargs): self.task.related_object, Review ): source = self.task.related_object.submission + elif isinstance(self.task.related_object, Activity): + source = self.task.related_object.source messenger( MESSAGES.REMOVE_TASK, user=self.request.user,