Skip to content

Commit

Permalink
refactor: better errors and subscriber sticking
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 5, 2024
1 parent 2f65a62 commit 19d9c25
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions intranet/apps/announcements/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ...test.ion_test import IonTestCase
from ...utils.date import get_senior_graduation_year
from ..eighth.models import EighthActivity
from ..users.models import Group
from .models import Announcement, AnnouncementRequest

Expand Down Expand Up @@ -443,6 +444,17 @@ def test_hide_announcement_view(self):
response = self.client.get(reverse("hide_announcement"))
self.assertEqual(405, response.status_code)

def test_modify_club_announcement(self):
self.make_admin()
act = EighthActivity.objects.get_or_create(name="test")[0]
announce = Announcement.objects.get_or_create(title="test9", content="test9", activity=act)[0]
self.client.post(
reverse("modify_club_announcement", args=[announce.id]),
{"title": "hi", "content": "bye", "expiration_date": "3000-01-01"},
)
announce.refresh_from_db()
self.assertEqual(act, announce.activity)


class ApiTest(IonTestCase):
def test_api_announcements_list(self):
Expand Down
1 change: 1 addition & 0 deletions intranet/apps/eighth/views/admin/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def edit_activity_view(request, activity_id):

activity = form.save()
activity.subscribers.add(*[sponsor.user for sponsor in form.cleaned_data["sponsors"]])
activity.subscribers.add(*form.cleaned_data["club_sponsors"], *form.cleaned_data["officers"])
activity.save()

except forms.ValidationError as error:
Expand Down
3 changes: 2 additions & 1 deletion intranet/apps/eighth/views/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ def unsubscribe_from_club(request, activity_id):
activity = get_object_or_404(EighthActivity, id=activity_id)

if activity.sponsors.filter(user=request.user).exists() or request.user in activity.club_sponsors.all():
raise http.Http404
messages.error(request, "You cannot unsubscribe from an activity you sponsor.")
return redirect("club_announcements")

if request.user in activity.subscribers.all():
activity.subscribers.remove(request.user)
Expand Down

0 comments on commit 19d9c25

Please sign in to comment.