예제 #1
0
    def __send_notification(self, updates, user):
        user_id = user['_id']

        if 'is_enabled' in updates and not updates['is_enabled']:
            push_notification('user_disabled', updated=1, user_id=str(user_id))
        elif 'is_active' in updates and not updates['is_active']:
            push_notification('user_inactivated', updated=1, user_id=str(user_id))
        elif 'role' in updates:
            push_notification('user_role_changed', updated=1, user_id=str(user_id))
        elif 'privileges' in updates:
            added, removed, modified = compare_preferences(user.get('privileges', {}), updates['privileges'])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification('user_privileges_revoked', updated=1, user_id=str(user_id))
            if len(added) > 0:
                add_activity(ACTIVITY_UPDATE,
                             'user {{user}} has been granted new privileges: Please re-login.',
                             self.datasource,
                             notify=[user_id],
                             user=user.get('display_name', user.get('username')))
        elif 'user_type' in updates:
            if not is_admin(updates):
                push_notification('user_type_changed', updated=1, user_id=str(user_id))
            else:
                add_activity(ACTIVITY_UPDATE,
                             'user {{user}} is updated to administrator: Please re-login.',
                             self.datasource,
                             notify=[user_id],
                             user=user.get('display_name', user.get('username')))
        else:
            push_notification('user', updated=1, user_id=str(user_id))
예제 #2
0
    def __send_notification(self, updates, user):
        user_id = user['_id']

        if 'is_enabled' in updates and not updates['is_enabled']:
            push_notification('user_disabled', updated=1, user_id=str(user_id))
        elif 'is_active' in updates and not updates['is_active']:
            push_notification('user_inactivated', updated=1, user_id=str(user_id))
        elif 'role' in updates:
            push_notification('user_role_changed', updated=1, user_id=str(user_id))
        elif 'privileges' in updates:
            added, removed, modified = compare_preferences(user.get('privileges', {}), updates['privileges'])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification('user_privileges_revoked', updated=1, user_id=str(user_id))
            if len(added) > 0:
                add_activity(ACTIVITY_UPDATE,
                             'user {{user}} is granted new privileges: Please re-login.',
                             self.datasource,
                             notify=[user_id],
                             user=user.get('display_name', user.get('username')))
        elif 'user_type' in updates:
            if not is_admin(updates):
                push_notification('user_type_changed', updated=1, user_id=str(user_id))
            else:
                add_activity(ACTIVITY_UPDATE,
                             'user {{user}} is updated to administrator: Please re-login.',
                             self.datasource,
                             notify=[user_id],
                             user=user.get('display_name', user.get('username')))
        else:
            push_notification('user', updated=1, user_id=str(user_id))
예제 #3
0
    def __send_notification(self, updates, role):
        role_id = role['_id']

        role_users = superdesk.get_resource_service('users').get_users_by_role(
            role_id)
        notified_users = [user['_id'] for user in role_users]

        if 'privileges' in updates:
            privileges_updated = False
            added, removed, modified = compare_preferences(
                role.get('privileges', {}), updates['privileges'])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification('role_privileges_revoked',
                                  updated=1,
                                  role_id=str(role_id))
                privileges_updated = True
            if len(added) > 0 or (0, 1) in modified.values():
                activity = add_activity(
                    ACTIVITY_UPDATE,
                    'role {{role}} has been granted new privileges: Please re-login.',
                    self.datasource,
                    notify=notified_users,
                    can_push_notification=False,
                    role=role.get('name'))
                push_notification('activity', _dest=activity['recipients'])
                privileges_updated = True
            if privileges_updated:
                app.on_role_privileges_updated(role, role_users)

        else:
            push_notification('role', updated=1, user_id=str(role_id))
예제 #4
0
    def __send_notification(self, updates, role):
        role_id = role["_id"]

        role_users = superdesk.get_resource_service("users").get_users_by_role(role_id)
        notified_users = [user["_id"] for user in role_users]

        if "privileges" in updates:
            privileges_updated = False
            added, removed, modified = compare_preferences(role.get("privileges", {}), updates["privileges"])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification("role_privileges_revoked", updated=1, role_id=str(role_id))
                privileges_updated = True
            if len(added) > 0 or (0, 1) in modified.values():
                activity = add_activity(
                    ACTIVITY_UPDATE,
                    "role {{role}} has been granted new privileges: Please re-login.",
                    self.datasource,
                    notify=notified_users,
                    can_push_notification=False,
                    role=role.get("name"),
                )
                push_notification("activity", _dest=activity["recipients"])
                privileges_updated = True
            if privileges_updated:
                app.on_role_privileges_updated(role, role_users)

        else:
            push_notification("role", updated=1, user_id=str(role_id))
예제 #5
0
    def __send_notification(self, updates, role):
        role_id = role['_id']

        role_users = superdesk.get_resource_service('users').get_users_by_role(role_id)
        notified_users = [user['_id'] for user in role_users]

        if 'privileges' in updates:
            added, removed, modified = compare_preferences(role.get('privileges', {}), updates['privileges'])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification('role_privileges_revoked', updated=1, role_id=str(role_id))
            if len(added) > 0:
                add_activity(ACTIVITY_UPDATE,
                             'role {{role}} is granted new privileges: Please re-login.',
                             self.datasource,
                             notify=notified_users,
                             role=role.get('name'))
        else:
            push_notification('role', updated=1, user_id=str(role_id))
예제 #6
0
    def __send_notification(self, updates, user):
        user_id = user["_id"]

        if "is_enabled" in updates and not updates["is_enabled"]:
            push_notification("user_disabled", updated=1, user_id=str(user_id))
        elif "is_active" in updates and not updates["is_active"]:
            push_notification("user_inactivated",
                              updated=1,
                              user_id=str(user_id))
        elif "role" in updates:
            push_notification("user_role_changed",
                              updated=1,
                              user_id=str(user_id))
        elif "privileges" in updates:
            added, removed, modified = compare_preferences(
                user.get("privileges", {}), updates["privileges"])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification("user_privileges_revoked",
                                  updated=1,
                                  user_id=str(user_id))
            if len(added) > 0:
                add_activity(
                    ACTIVITY_UPDATE,
                    "user {{user}} has been granted new privileges: Please re-login.",
                    self.datasource,
                    notify=[user_id],
                    user=user.get("display_name", user.get("username")),
                )
        elif "user_type" in updates:
            if not is_admin(updates):
                push_notification("user_type_changed",
                                  updated=1,
                                  user_id=str(user_id))
            else:
                add_activity(
                    ACTIVITY_UPDATE,
                    "user {{user}} is updated to administrator: Please re-login.",
                    self.datasource,
                    notify=[user_id],
                    user=user.get("display_name", user.get("username")),
                )
        else:
            push_notification("user", updated=1, user_id=str(user_id))
예제 #7
0
    def __send_notification(self, updates, role):
        role_id = role['_id']

        role_users = superdesk.get_resource_service('users').get_users_by_role(
            role_id)
        notified_users = [user['_id'] for user in role_users]

        if 'privileges' in updates:
            added, removed, modified = compare_preferences(
                role.get('privileges', {}), updates['privileges'])
            if len(removed) > 0 or (1, 0) in modified.values():
                push_notification('role_privileges_revoked',
                                  updated=1,
                                  role_id=str(role_id))
            if len(added) > 0:
                add_activity(
                    ACTIVITY_UPDATE,
                    'role {{role}} is granted new privileges: Please re-login.',
                    self.datasource,
                    notify=notified_users,
                    role=role.get('name'))
        else:
            push_notification('role', updated=1, user_id=str(role_id))