Remove unused Notifier subclasses, and refactor EmailNotifier into EmailNotificationMixin

pull/6257/head
jacobtoppm 2020-02-25 16:51:13 +00:00 zatwierdzone przez Matt Westcott
rodzic 05fafff317
commit c59cae51ee
1 zmienionych plików z 10 dodań i 44 usunięć

Wyświetl plik

@ -191,8 +191,8 @@ class Notifier:
return self.send_notifications(template_set, context, recipients, **kwargs) return self.send_notifications(template_set, context, recipients, **kwargs)
class EmailNotifier(Notifier): class EmailNotificationMixin:
"""Class for sending email notifications upon events""" """Mixin for sending email notifications upon events"""
def get_recipient_users(self, instance, **kwargs): def get_recipient_users(self, instance, **kwargs):
"""Gets the ideal set of recipient users, without accounting for notification preferences or missing email addresses""" """Gets the ideal set of recipient users, without accounting for notification preferences or missing email addresses"""
@ -263,8 +263,8 @@ class EmailNotifier(Notifier):
return self.send_emails(template_set, context, recipients, **kwargs) return self.send_emails(template_set, context, recipients, **kwargs)
class BaseWorkflowStateEmailNotifier(EmailNotifier): class BaseWorkflowStateEmailNotifier(EmailNotificationMixin, Notifier):
"""A base EmailNotifier to send updates for WorkflowState events""" """A base notifier to send email updates for WorkflowState events"""
def __init__(self): def __init__(self):
super().__init__((WorkflowState,)) super().__init__((WorkflowState,))
@ -277,7 +277,7 @@ class BaseWorkflowStateEmailNotifier(EmailNotifier):
class WorkflowStateApprovalEmailNotifier(BaseWorkflowStateEmailNotifier): class WorkflowStateApprovalEmailNotifier(BaseWorkflowStateEmailNotifier):
"""An EmailNotifier to send updates for WorkflowState approval events""" """A notifier to send email updates for WorkflowState approval events"""
notification = 'approved' notification = 'approved'
@ -292,7 +292,7 @@ class WorkflowStateApprovalEmailNotifier(BaseWorkflowStateEmailNotifier):
class WorkflowStateRejectionEmailNotifier(BaseWorkflowStateEmailNotifier): class WorkflowStateRejectionEmailNotifier(BaseWorkflowStateEmailNotifier):
"""An EmailNotifier to send updates for WorkflowState rejection events""" """A notifier to send email updates for WorkflowState rejection events"""
notification = 'rejected' notification = 'rejected'
@ -307,7 +307,7 @@ class WorkflowStateRejectionEmailNotifier(BaseWorkflowStateEmailNotifier):
class WorkflowStateSubmissionEmailNotifier(BaseWorkflowStateEmailNotifier): class WorkflowStateSubmissionEmailNotifier(BaseWorkflowStateEmailNotifier):
"""An EmailNotifier to send updates for WorkflowState submission events""" """A notifier to send email updates for WorkflowState submission events"""
notification = 'submitted' notification = 'submitted'
@ -323,8 +323,8 @@ class WorkflowStateSubmissionEmailNotifier(BaseWorkflowStateEmailNotifier):
return recipients return recipients
class BaseGroupApprovalTaskStateEmailNotifier(EmailNotifier): class BaseGroupApprovalTaskStateEmailNotifier(EmailNotificationMixin, Notifier):
"""A base EmailNotifier to send updates for GroupApprovalTask events""" """A base notifier to send email updates for GroupApprovalTask events"""
def __init__(self): def __init__(self):
super().__init__((TaskState,)) super().__init__((TaskState,))
@ -360,40 +360,6 @@ class BaseGroupApprovalTaskStateEmailNotifier(EmailNotifier):
class GroupApprovalTaskStateSubmissionEmailNotifier(BaseGroupApprovalTaskStateEmailNotifier): class GroupApprovalTaskStateSubmissionEmailNotifier(BaseGroupApprovalTaskStateEmailNotifier):
"""An EmailNotifier to send updates for GroupApprovalTask submission events""" """A notifier to send email updates for GroupApprovalTask submission events"""
notification = 'submitted' notification = 'submitted'
class GroupApprovalTaskStateApprovalEmailNotifier(BaseGroupApprovalTaskStateEmailNotifier):
"""An EmailNotifier to send updates for GroupApprovalTask approval events"""
notification = 'approved'
def get_recipient_users(self, task_state, **kwargs):
recipients = super().get_recipient_users(task_state, **kwargs)
requested_by = task_state.workflow_state.requested_by
# add the EmailNotifier's requester
triggering_user = kwargs.get('user', None)
if not triggering_user or triggering_user.pk != requested_by.pk:
recipients = set(recipients)
recipients.add(requested_by)
return recipients
class GroupApprovalTaskStateRejectionEmailNotifier(BaseGroupApprovalTaskStateEmailNotifier):
"""An EmailNotifier to send updates for GroupApprovalTask rejection events"""
notification = 'rejected'
def get_recipient_users(self, task_state, **kwargs):
recipients = super().get_recipient_users(task_state, **kwargs)
requested_by = task_state.workflow_state.requested_by
# add the EmailNotifier's requester
triggering_user = kwargs.get('user', None)
if not triggering_user or triggering_user.pk != requested_by.pk:
recipients = set(recipients)
recipients.add(requested_by)
return recipients