diff --git a/server/api/fixtures/initial.json b/server/api/fixtures/initial.json index 27af973c..86a41d9f 100644 --- a/server/api/fixtures/initial.json +++ b/server/api/fixtures/initial.json @@ -22,10 +22,10 @@ "password": "pbkdf2_sha256$36000$N92TfR4PrqJ7$DZSbvw4wIWbDjrZ+xfDisnqCNwVoyoAdx/meV7pqkHY=", "last_login": "2018-09-09T00:35:53.883Z", "is_superuser": false, - "username": "mayowa.makinde", - "first_name": "Mayowa", - "last_name": "Makinde", - "email": "mayowa.makinde@andela.com", + "username": "olusola.oguntimehin", + "first_name": "Olusola", + "last_name": "Oguntimehin", + "email": "olusola.oguntimehin@andela.com", "is_staff": false, "is_active": true, "date_joined": "2018-09-09T00:35:28.114Z" @@ -232,4 +232,4 @@ "follower_category": 1 } } -] \ No newline at end of file +] diff --git a/server/graphql_schemas/event/schema.py b/server/graphql_schemas/event/schema.py index f38084d9..03da6dca 100644 --- a/server/graphql_schemas/event/schema.py +++ b/server/graphql_schemas/event/schema.py @@ -4,7 +4,6 @@ from dateutil.parser import parse from django.forms.models import model_to_dict -from django.core.mail import EmailMessage from django.core.exceptions import ObjectDoesNotExist from django.template.loader import get_template from django.utils import timezone @@ -17,6 +16,8 @@ from graphql_schemas.utils.helpers import (is_not_admin, update_instance, send_calendar_invites, + send_event_invite_email, + send_event_invite_emails, raise_calendar_error, not_valid_timezone) from graphql_schemas.utils.hasher import Hasher @@ -86,15 +87,16 @@ def mutate_and_get_payload(cls, root, info, **input): user_profile = AndelaUserProfile.objects.get( user=info.context.user ) + new_event = CreateEvent.create_event( + category, user_profile, **input) + # Send email invites in background + BackgroundTaskWorker.start_work(send_event_invite_emails, + (user_profile, new_event, info.context)) if user_profile.credential and user_profile.credential.valid: - new_event = CreateEvent.create_event( - category, user_profile, **input) # Send calender invite in background BackgroundTaskWorker.start_work(send_calendar_invites, - (user_profile, new_event)) + (user_profile, new_event)) else: - new_event = CreateEvent.create_event( - category, user_profile, **input) CreateEvent.notify_event_in_slack(category, input, new_event) raise_calendar_error(user_profile) @@ -244,25 +246,7 @@ def mutate_and_get_payload(cls, root, info, **input): raise GraphQLError( "User cannot invite self") - invite_hash = Hasher.gen_hash([ - event.id, receiver.user.id, sender.user.id]) - invite_url = info.context.build_absolute_uri( - f"/invite/{invite_hash}") - data_values = { - 'title': event.title, - 'imgUrl': event.featured_image, - 'venue': event.venue, - 'startDate': event.start_date, - 'url': invite_url - } - message = get_template('event_invite.html').render(data_values) - msg = EmailMessage( - f"You have been invited to an event by {sender.user.username}", - message, - to=[receiver_email] - ) - msg.content_subtype = 'html' - sent = msg.send() + sent = send_event_invite_email(sender, event, receiver, info.context) if sent: return cls(message="Event invite delivered") diff --git a/server/graphql_schemas/templates/event_email_invite.html b/server/graphql_schemas/templates/event_email_invite.html new file mode 100644 index 00000000..d4dda6e1 --- /dev/null +++ b/server/graphql_schemas/templates/event_email_invite.html @@ -0,0 +1,175 @@ + +
+ + +
+ Hi {{receiverName}}! + |
+
+ You have received an invite from + {{senderName}} to attend the + {{title}} + + |
+
+ Date + |
+
+ {{startDate}} + |
+
+ Venue> + |
+
+ {{venue}} + |
+
+ |
+ + RSVP Now + + | +
+ | + +
+ | + +
+ | + +