Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(feedback): correct the permission requirement for removing feedback relation #3317

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/events/dashboard/tests.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from datetime import timedelta

from django.contrib.auth.models import Permission
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
from django_dynamic_fixture import G
from guardian.shortcuts import assign_perm
from rest_framework import status

from apps.authentication.models import OnlineUser as User
from apps.events.models import AttendanceEvent, Event
from apps.feedback.models import Feedback, FeedbackRelation, TextQuestion


def create_generic_attendance_event():
Expand All @@ -23,6 +27,7 @@ def add_permissions(user):
user.user_permissions.add(
Permission.objects.filter(codename="view_event").first(),
Permission.objects.filter(codename="add_event").first(),
Permission.objects.filter(codename="delete_feedbackrelation").first(),
)


Expand Down Expand Up @@ -62,3 +67,26 @@ def test_dashboard_events_create(self):
response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_dashboard_remove_feedback_from_event(self):
add_permissions(self.user)

event = create_generic_attendance_event()
feedback = Feedback.objects.create(author=self.user)
TextQuestion.objects.create(feedback=feedback)
deadline = timezone.now().date() + timedelta(days=4)

feedbackrelation = FeedbackRelation.objects.create(
feedback=feedback, content_object=event, deadline=deadline, active=True
)

assign_perm("delete_feedbackrelation", self.user, feedbackrelation)
self.assertTrue(self.user.has_perm("feedback.delete_feedbackrelation"))

url = reverse(
"dashboard_events_remove_feedback",
kwargs={"event_id": event.id, "pk": feedback.id},
)
response = self.client.post(url)

self.assertEqual(response.status_code, status.HTTP_302_FOUND)
3 changes: 2 additions & 1 deletion apps/events/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def form_valid(self, form):

class RemoveFeedbackRelationView(DashboardObjectPermissionMixin, DeleteView):
model = FeedbackRelation
permission_required = "events.add_attendanceevent"

permission_required = "feedback.delete_feedbackrelation"

def get_success_url(self):
return reverse(
Expand Down