def send_slack(request, slack_message, slack_channels): notify_contents = { 'slack_message': slack_message, 'action': slack_channels, 'request': request, } notify.notification(**notify_contents)
def send_email_with_body_from_user(request, subject, to, body): notify_contents = { 'subject': subject, 'to': to, 'html': body, 'action': ['email'], 'request': request, } notify.notification(**notify_contents)
def send_email_with_body_from_setting_template(request, template, subject, to, context): notify_contents = { 'subject': subject, 'to': to, 'html': render_template.get_message_content(request, context, template), 'action': ['email'], 'request': request, } notify.notification(**notify_contents)
def task_runner(task): if task.task_type == 'slack_message': pass elif task.task_type == 'email_message': log_dict = { 'level': 'Info', 'action_text': task.task_data, 'types': task.task_type, 'target': task.article } notify.notification(**{ 'action': ['email'], 'task': task, 'log_dict': log_dict })
def notify_hook(**kwargs): # dummy mock-up of new notification hook defer # action is a list of notification targets # if the "all" variable is passed, then some types of notification might act, like Slack. # Email, though, should only send if it's specifically an email in action, not on "all". action = kwargs.pop('action', []) if 'email' not in action: # email is only sent if list of actions includes "email" return # pop the args subject = kwargs.pop('subject', '') to = kwargs.pop('to', '') html = kwargs.pop('html', '') bcc = kwargs.pop('bcc', []) cc = kwargs.pop('cc', []) attachment = kwargs.pop('attachment', None) request = kwargs.pop('request', None) task = kwargs.pop('task', None) # call the method if not task: response = send_email(subject, to, html, request.journal, request, bcc, cc, attachment) else: response = send_email(task.email_subject, task.email_to, task.email_html, task.email_journal, request, task.email_bcc, task.email_cc) log_dict = kwargs.get('log_dict', None) if type(to) in [list, tuple]: to = ';'.join(to) if log_dict: notify_contents = { 'log_dict': log_dict, 'request': request, 'response': response, 'action': ['email_log'], 'html': html, 'to': to, } notify.notification(**notify_contents)
def send_email_with_body_from_user( request, subject, to, body, log_dict=None, cc=None, ): notify_contents = { 'subject': subject, 'to': to, 'html': body, 'action': ['email'], 'request': request, 'log_dict': log_dict, 'cc': cc, } notify.notification(**notify_contents)
def add_entry(types, description, level, actor=None, request=None, target=None, is_email=False, to=None, message_id=None, subject=None): if actor is not None and callable(getattr(actor, "is_anonymous", None)): if actor.is_anonymous(): actor = None kwargs = { 'types': types, 'description': description, 'level': level, # if no actor is supplied, assume anonymous 'actor': actor if actor else None, 'ip_address': get_ip_address(request), 'target': target, 'is_email': is_email, 'to': to, 'message_id': message_id, 'subject': subject, } new_entry = LogEntry.objects.create(**kwargs).save() if request and request.journal: if request.journal.slack_logging_enabled: notify.notification( **{ 'slack_message': '[{0}] {1}'.format(kwargs['ip_address'], description), 'action': ['slack_admins'], 'request': request }) return new_entry
def task_runner(task): if task.task_type == 'slack_message': pass elif task.task_type == 'email_message': notify.notification(**{'action': ['email'], 'task': task})