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

Add support for (ticket) email blasts #749

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion backend/clubs/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ def has_object_permission(self, request, view, obj):

if not old_type == FAIR_TYPE and new_type == FAIR_TYPE:
return False
elif view.action in ["buyers", "create_tickets", "issue_tickets"]:
elif view.action in [
"buyers",
"create_tickets",
"issue_tickets",
"email_blast",
]:
if not request.user.is_authenticated:
return False
membership = find_membership_helper(request.user, obj.club)
Expand Down
18 changes: 18 additions & 0 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3067,6 +3067,17 @@ def email_blast(self, request, *args, **kwargs):
type: string
description: A message indicating how many
recipients received the blast
"400":
description: Content field was empty or missing
content:
application/json:
schema:
type: object
properties:
detail:
type: string
description: Error message indicating content
was not provided
"404":
description: Event not found
content:
Expand All @@ -3088,6 +3099,13 @@ def email_blast(self, request, *args, **kwargs):
officer_emails = event.club.get_officer_emails()
emails = list(holder_emails) + list(officer_emails)

content = request.data.get("content").strip()
aviupadhyayula marked this conversation as resolved.
Show resolved Hide resolved
if not content:
return Response(
{"detail": "Content must be specified"},
status=status.HTTP_400_BAD_REQUEST,
)

send_mail_helper(
name="blast",
subject=f"Update on {event.name} from {event.club.name}",
Expand Down
9 changes: 9 additions & 0 deletions backend/tests/clubs/test_ticketing.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ def test_email_blast(self):
)
self.assertIn("Test email blast content", email.body)

def test_email_blast_empty_content(self):
self.client.login(username=self.user1.username, password="test")
resp = self.client.post(
reverse("club-events-email-blast", args=(self.club1.code, self.event1.pk)),
{"content": ""},
format="json",
)
self.assertEqual(resp.status_code, 400, resp.content)

def test_get_tickets_information_no_tickets(self):
# Delete all the tickets
Ticket.objects.all().delete()
Expand Down
Loading