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

Restrict event creation to approved clubs #748

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3120,6 +3120,14 @@ def create(self, request, *args, **kwargs):

---
"""
# only approved clubs can create events
club = Club.objects.get(code=kwargs["club_code"])
if not club.approved:
return Response(
{"detail": "Only approved clubs can create events"},
status=status.HTTP_403_FORBIDDEN,
)

# get event type
type = request.data.get("type", 0)
if type == Event.FAIR and not self.request.user.is_superuser:
Expand Down
27 changes: 27 additions & 0 deletions backend/tests/clubs/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,33 @@ def test_event_create_update_delete(self):
)
self.assertIn(resp.status_code, [200, 204], resp.content)

def test_event_create_unapproved_club(self):
self.club1.approved = False
self.club1.save()

start_date = datetime.datetime.now() - datetime.timedelta(days=3)
end_date = start_date + datetime.timedelta(hours=2)

# add user as officer
Membership.objects.create(
person=self.user1, club=self.club1, role=Membership.ROLE_OFFICER
)

self.client.login(username=self.user1.username, password="test")
resp = self.client.post(
reverse("club-events-list", args=(self.club1.code,)),
{
"name": "Interest Meeting",
"description": "Interest Meeting on Friday!",
"location": "JMHH G06",
"type": Event.RECRUITMENT,
"start_time": start_date.isoformat(),
"end_time": end_date.isoformat(),
},
content_type="application/json",
)
self.assertEqual(resp.status_code, 403, resp.content)

def test_recurring_event_create(self):
self.client.login(username=self.user4.username, password="test")
self.assertFalse(self.user4.is_superuser)
Expand Down
Loading