Пример #1
0
def notify_and_add_activity(activity_name, msg, resource=None, item=None, user_list=None, **data):
    """
    Adds the activity and notify enabled and active users via email.
    """

    add_activity(activity_name, msg=msg, resource=resource, item=item,
                 notify=[str(user.get("_id")) for user in user_list] if user_list else None, **data)

    if activity_name == ACTIVITY_ERROR or user_list:
        recipients = get_recipients(user_list, activity_name)

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, 'user', None)
            activity = {
                'name': activity_name,
                'message': current_user.get('display_name') + ' ' + msg if current_user else msg,
                'data': data,
                'resource': resource
            }
        else:
            activity = {
                'name': activity_name,
                'message': 'System ' + msg,
                'data': data,
                'resource': resource
            }

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #2
0
def notify_and_add_activity(activity_name, msg, resource=None, item=None, user_list=None, **data):
    """
    Adds the activity and notify enabled and active users via email.
    """

    add_activity(activity_name, msg=msg, resource=resource, item=item,
                 notify=[str(user.get("_id")) for user in user_list] if user_list else None, **data)

    if activity_name == ACTIVITY_ERROR or user_list:
        recipients = get_recipients(user_list, activity_name)

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, 'user', None)
            activity = {
                'name': activity_name,
                'message': current_user.get('display_name') + ' ' + msg if current_user else msg,
                'data': data,
                'resource': resource
            }
        else:
            activity = {
                'name': activity_name,
                'message': 'System ' + msg,
                'data': data,
                'resource': resource
            }

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #3
0
def notify_and_add_activity(activity_name, msg, resource=None, item=None, user_list=None, **data):
    """
    this function will add the activity and notify via email.
    """

    if not user_list and activity_name == ACTIVITY_ERROR:
        user_list = superdesk.get_resource_service('users').get_users_by_user_type('administrator')

    add_activity(activity_name, msg=msg, resource=resource, item=item,
                 notify=[user.get("_id") for user in user_list] if user_list else None, **data)
    if user_list:
        recipients = [user.get('email') for user in user_list if
                      superdesk.get_resource_service('preferences').
                      email_notification_is_enabled(preferences=user.get('preferences', {}))]

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, 'user', None)
            activity = {
                'name': activity_name,
                'message': current_user.get('display_name') + ' ' + msg if current_user else msg,
                'data': data,
                'resource': resource
            }
        else:
            activity = {
                'name': activity_name,
                'message': 'System ' + msg,
                'data': data,
                'resource': resource
            }

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #4
0
def notify_and_add_activity(activity_name, msg, resource=None, item=None, user_list=None, **data):
    """
    Adds the activity and notify enabled and active users via email.
    """

    add_activity(
        activity_name,
        msg=msg,
        resource=resource,
        item=item,
        notify=[str(user.get("_id")) for user in user_list] if user_list else None,
        **data,
    )

    if activity_name == ACTIVITY_ERROR or user_list:
        recipients = get_recipients(user_list, activity_name)

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, "user", None)
            activity = {
                "name": activity_name,
                "message": current_user.get("display_name") + " " + msg if current_user else msg,
                "data": data,
                "resource": resource,
            }
        else:
            activity = {"name": activity_name, "message": "System " + msg, "data": data, "resource": resource}

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #5
0
def notify_and_add_activity(activity_name, msg, item=None, user_list=None, **data):
    """
    this function will add the activity and notify via email.
    """

    if not user_list and activity_name == ACTIVITY_ERROR:
        user_list = superdesk.get_resource_service("users").get_users_by_user_type("administrator")

    add_activity(
        activity_name, msg=msg, item=item, notify=[user.get("_id") for user in user_list] if user_list else None, **data
    )
    if user_list:
        recipients = [
            user.get("email")
            for user in user_list
            if superdesk.get_resource_service("preferences").email_notification_is_enabled(
                preferences=user.get("preferences", {})
            )
        ]

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, "user", None)
            activity = {
                "name": activity_name,
                "message": current_user.get("display_name") + " " + msg if current_user else msg,
                "data": data,
            }
        else:
            activity = {"name": activity_name, "message": "System " + msg, "data": data}

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #6
0
def notify_and_add_activity(activity_name,
                            msg,
                            resource=None,
                            item=None,
                            user_list=None,
                            **data):
    """
    Adds the activity and notify enabled and active users via email.
    """

    if not user_list and activity_name == ACTIVITY_ERROR:
        user_list = superdesk.get_resource_service(
            'users').get_users_by_user_type('administrator')

    add_activity(activity_name,
                 msg=msg,
                 resource=resource,
                 item=item,
                 notify=[user.get("_id")
                         for user in user_list] if user_list else None,
                 **data)
    if user_list:
        recipients = [
            user.get('email') for user in user_list
            if user.get('is_enabled', False) and user.get('is_active', False)
            and superdesk.get_resource_service(
                'preferences').email_notification_is_enabled(
                    preferences=user.get('user_preferences', {}))
        ]

        if activity_name != ACTIVITY_ERROR:
            current_user = getattr(g, 'user', None)
            activity = {
                'name':
                activity_name,
                'message':
                current_user.get('display_name') + ' ' +
                msg if current_user else msg,
                'data':
                data,
                'resource':
                resource
            }
        else:
            activity = {
                'name': activity_name,
                'message': 'System ' + msg,
                'data': data,
                'resource': resource
            }

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
 def test_send_activity_emails_error(self):
     recipients = ['foo', 'bar']
     activities = [
         {
             'message': 'error',
             'data': {
                 'foo': 1
             }
         },
         {
             'message': 'error',
             'data': {
                 'bar': 1
             }
         },
     ]
     with patch.object(send_email, 'delay', return_value=None) as sent:
         with self.app.app_context():
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)
Пример #8
0
 def test_send_activity_emails_error(self):
     recipients = ["foo", "bar"]
     activities = [
         {
             "message": "error",
             "data": {
                 "foo": 1
             }
         },
         {
             "message": "error",
             "data": {
                 "bar": 1
             }
         },
     ]
     with patch.object(send_email, "delay", return_value=None) as sent:
         with self.app.app_context():
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)
Пример #9
0
def notify_and_add_activity(activity_name, msg, item=None, user_list=None, **data):
    """
    this function will add the activity and notify via email.
    """
    add_activity(activity_name, msg=msg, item=item,
                 notify=[user.get("_id") for user in user_list] if user_list else None, **data)
    if user_list:
        recipients = [user.get('email') for user in user_list if
                      superdesk.get_resource_service('preferences').
                      email_notification_is_enabled(preferences=user.get('preferences', {}))]
        user = getattr(g, 'user', None)
        activity = {
            'name': activity_name,
            'message': user.get('display_name') + ' ' + msg if user else msg,
            'data': data,
        }

        if recipients:
            send_activity_emails(activity=activity, recipients=recipients)
Пример #10
0
 def test_send_activity_emails_error(self):
     recipients = ['foo', 'bar']
     activities = [
         {'message': 'error', 'data': {'foo': 1}},
         {'message': 'error', 'data': {'bar': 1}},
     ]
     with patch.object(send_email, 'delay', return_value=None) as sent:
         with self.app.app_context():
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[0], recipients)
             self.assertEqual(1, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)
             send_activity_emails(activities[1], recipients)
             self.assertEqual(2, sent.call_count)