Skip to content

Commit

Permalink
Show assigned user in comment for staff, link activity directly with …
Browse files Browse the repository at this point in the history
…task instead of its source
  • Loading branch information
sandeepsajan0 committed Jul 30, 2024
1 parent 98010bd commit e653ec5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hypha/apply/activity/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions hypha/apply/activity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<span class="js-last-edited text-fg-muted text-sm" data-tippy-content="{{ activity.edited|date:"SHORT_DATETIME_FORMAT" }}">{% trans "edited" %}</span>
{% endif %}
</p>
{% if request.user.is_apply_staff %}
<p hx-get="{% url 'activity:assigned' pk=activity.id %}" hx-trigger="revealed" hx-target="this"></p>
{% endif %}

{% if editable and activity.user == request.user %}
<p class="feed__meta-item feed__meta-item--edit-button">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}

{% if assigned_to %}
<p>{% trans "Assigned as task to: " %} {{ assigned_to }}</p>
{% endif %}
3 changes: 2 additions & 1 deletion hypha/apply/activity/urls.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -13,4 +13,5 @@
AttachmentView.as_view(),
name="attachment",
),
path("activity/<int:pk>/assigned/", get_activity_assgined_user, name="assigned"),
]
23 changes: 21 additions & 2 deletions hypha/apply/activity/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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},
)
2 changes: 1 addition & 1 deletion hypha/apply/todo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
COMMENT_TASK: {
"text": _("{msg}"),
"icon": "comment",
"url": "{link}#communications",
"url": "{link}",
"type": _("Comment"),
},
# SUBMISSIONS ACTIONS
Expand Down
3 changes: 3 additions & 0 deletions hypha/apply/todo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit e653ec5

Please sign in to comment.