Repository: fossasia/open-event-server

Issue:
Allow Accepting/Rejecting a session without sending emails 
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Currently, if we update the state of a session to `Accepted` or `Rejected`, emails are always sent to the speakers and the event organizer. 

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
There should be an option to specify if we need to send emails or not. Infact this is required in the Frontend where we allow the organizer to choose whether to accept/reject the user with or without the email confirmation.

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
Related code in the Session schema
``` Python
    def after_update_object(self, session, data, view_kwargs):
        """ Send email if session accepted or rejected """
        if 'state' in data and (session.state == 'accepted' or session.state == 'rejected'):
            # Email for speaker
            speakers = session.speakers
            for speaker in speakers:
                frontend_url = get_settings()['frontend_url']
                link = "{}/events/{}/sessions/{}" \
                    .format(frontend_url, session.event_id, session.id)
                send_email_session_accept_reject(speaker.email, session, link)
                send_notif_session_accept_reject(speaker, session.title, session.state, link)

            # Email for organizer
            if session.event.get_organizer():
                organizer = session.event.get_organizer()
                organizer_email = organizer.email
                frontend_url = get_settings()['frontend_url']
                link = "{}/events/{}/sessions/{}" \
                    .format(frontend_url, session.event_id, session.id)
                send_email_session_accept_reject(organizer_email, session,
                                                 link)
                send_notif_session_accept_reject(organizer, session.title,
                                                 session.state, link)
```

Needs to be implemented before https://github.com/fossasia/open-event-frontend/issues/1094

Working!


Discussion:

Resolving patch:
diff --git a/app/api/schema/sessions.py b/app/api/schema/sessions.py
--- a/app/api/schema/sessions.py
+++ b/app/api/schema/sessions.py
@@ -75,6 +75,7 @@ def validate_date(self, data, original_data):
     submitted_at = fields.DateTime(allow_none=True)
     is_mail_sent = fields.Boolean()
     last_modified_at = fields.DateTime(dump_only=True)
+    send_email = fields.Boolean(load_only=True, allow_none=True)
     microlocation = Relationship(attribute='microlocation',
                                  self_view='v1.session_microlocation',
                                  self_view_kwargs={'id': '<id>'},
diff --git a/app/api/sessions.py b/app/api/sessions.py
--- a/app/api/sessions.py
+++ b/app/api/sessions.py
@@ -122,7 +122,9 @@ def before_get_object(self, view_kwargs):
 
     def after_update_object(self, session, data, view_kwargs):
         """ Send email if session accepted or rejected """
-        if 'state' in data and (session.state == 'accepted' or session.state == 'rejected'):
+
+        if 'state' in data and data.get('send_email', None) and (session.state == 'accepted' or
+                                                                 session.state == 'rejected'):
             # Email for speaker
             speakers = session.speakers
             for speaker in speakers:


Test patch: