예제 #1
0
    def test_reset_notifications(self):
        sess_id = self.login_actor()
        notifs = self.get_notifications_info(sess_id)
        ids = [n['id'] for n in notifs]

        req = {'session_id': sess_id, 'ids': ids,
            'new_messages': []}
        resp = self.modify_notifications(**req)
        self.check_response_ok(resp)
        notifs = self.get_notifications_info(sess_id)
        for n_info in notifs:
            self.assertEquals([], n_info['messages'])

        req = {'session_id': sess_id, 'ids': ids}
        resp = self.reset_notifications(**req)
        self.check_response_ok(resp)
        notifs = self.get_notifications_info(sess_id)
        n = Notifier()
        for n_info in notifs:
            self.assertNotEquals([], n_info['messages'])
            found = False
            for n_exp in n.default_email_notif_struct(n_info['event']):
                if n_exp in n_info['messages']:
                    found = True
                    break
            self.assertTrue(found)
예제 #2
0
    def test_get_message_data_disabled(self, curs=None):
        sess_id = self.login_actor()
        ns_info = self.get_notifications_info(sess_id)
        n_info = ns_info[0]
        n_id = n_info['id']
        req = {'session_id': sess_id, 'ids': [n_id],
            'new_is_active': False}
        resp = self.modify_notifications(**req)
        self.check_response_ok(resp)

        env = self.get_environment_by_name(self.actor_env_name)
        n = Notifier()
        s_old = settings.email_notifications_enabled
        settings.email_notifications_enabled = True
        try:
            n_proc = n._get_message_data(env.id, message.EVENT_REGISTER_USER,
                Notification.TYPE_EMAIL, message.LANG_EN, curs)
            n_proc_info = n_proc.to_dict()
            self.assertEquals(False, n_proc_info['is_processable'])
            self.assertEquals({}, n_proc_info['message_data'])
            self.assertEquals(
                [NotificationProcessing.STEP_NOTIFICATIONS_ENABLED,
                NotificationProcessing.STEP_EVENT_NOTIFICATION_DISABLED],
                n_proc_info['checking_steps'])
        except Exception, e:
            raise e
예제 #3
0
    def test_get_message_data_lang_not_found(self, curs=None):
        sess_id = self.login_actor()
        # Setting messages to empty list
        ns_info = self.get_notifications_info(sess_id)
        n_info = ns_info[0]
        n_id = n_info['id']

        req = {'session_id': sess_id, 'ids': [n_id],
            'new_messages': []}
        resp = self.modify_notifications(**req)
        self.check_response_ok(resp)

        # Checking lang not found
        env = self.get_environment_by_name(self.actor_env_name)
        n = Notifier()
        s_old = settings.email_notifications_enabled
        settings.email_notifications_enabled = True
        try:
            n_proc = n._get_message_data(env.id, message.EVENT_REGISTER_USER,
                Notification.TYPE_EMAIL, 'FAKE', curs)
            n_proc_info = n_proc.to_dict()
            self.assertEquals(False, n_proc_info['is_processable'])
            self.assertEquals(
                [NotificationProcessing.STEP_NOTIFICATIONS_ENABLED,
                NotificationProcessing.STEP_EVENT_NOTIFICATION_ENABLED,
                NotificationProcessing.STEP_MSG_LANG_NOT_FOUND,
                NotificationProcessing.STEP_MSG_DFLT_LANG_NOT_FOUND],
                n_proc_info['checking_steps'])
        except Exception, e:
            raise e
예제 #4
0
    def register_user(self, data, req_info, curs=None):
        env_name = data.get('environment_name')
        env_f = EnvironmentFilter({'name': env_name}, {}, None)
        env = env_f.filter_one_obj(curs)

        # creating user
        a = Authenticator()
        salt = a.salt()
        lang = data.get('lang', User.DEFAULT_LANG)
        u_data = {'environment_id': env.id, 'email': data.get('email'),
            'password': a.encrypt_password(data.get('password'), salt),
            'salt': salt, 'role': User.ROLE_USER,
            'lang': lang}

        group_f = GroupFilter(env.id, {'is_default': True}, {}, None)
        groups = group_f.filter_objs(curs)
        groups_ids = [g.id for g in groups]

        u_data['groups_ids'] = groups_ids
        user = User(**u_data)

        # For correct action logging
        data['environment_id'] = env.id
        try:
            mapping.save(curs, user)
        except ObjectCreationError:
            raise UserAlreadyExists
        auth = Authenticator()
        session = auth.create_session(curs, env, user, req_info)
        _add_log_info(data, session)

        n = Notifier()
        n_process = n.register_user(curs, user, session)
        return response_ok(session_id=session.session_id, id=user.id,
                           notification=n_process)
예제 #5
0
    def add_user(self, data, req_info, session, curs=None):
        a = Authenticator()
        env_id = session.environment_id
        salt = a.salt()
        u_data = {'environment_id': env_id, 'email': data.get('email'),
            'role': data.get('role', User.ROLE_USER),
            'password': a.encrypt_password(data.get('password'), salt),
            'salt': salt, 'is_active': data.get('is_active', True),
            'lang': data.get('lang', User.DEFAULT_LANG)
        }
        if u_data['role'] == User.ROLE_SUPER:
            raise SuperUserCreationDenied

        groups_ids = data.get('groups_ids', [])
        filtered_g_ids = self._filter_existed_groups(curs, session, groups_ids)
        u_data['groups_ids'] = filtered_g_ids
        user = User(**u_data)
        try:
            mapping.save(curs, user)
        except ObjectCreationError:
            raise HelixauthObjectAlreadyExists

        # For correct action logging
        data['id'] = [user.id]
        n = Notifier()
        n_process = n.register_user(curs, user, session)
        return response_ok(id=user.id, notification=n_process)
예제 #6
0
 def _create_default_notifications(self, curs, env, events):
     notifier = Notifier()
     for event in events:
         e_msgs = notifier.default_email_notif_struct(event)
         n = Notification(environment_id=env.id, event=event,
             is_active=True, type=Notification.TYPE_EMAIL,
             messages=e_msgs)
         mapping.save(curs, n)
예제 #7
0
 def reset_notifications(self, data, req_info, session, curs=None):
     n_ids = data['ids']
     f = NotificatonFilter(session.environment_id, {'ids': n_ids},
         {}, None)
     objs = f.filter_objs(curs, for_update=True)
     n = Notifier()
     for o in objs:
         if o.type == Notification.TYPE_EMAIL:
             msg_struct = n.default_email_notif_struct(o.event)
             o.serialized_messages = json.dumps(msg_struct)
             mapping.save(curs, o)
     return response_ok()
예제 #8
0
 def test_get_message_data_emailing_disabled(self):
     env = self.get_environment_by_name(self.actor_env_name)
     n = Notifier()
     s_old = settings.email_notifications_enabled
     settings.email_notifications_enabled = False
     try:
         n_proc = n._get_message_data(env.id, message.EVENT_REGISTER_USER,
             Notification.TYPE_EMAIL, message.LANG_EN, None)
         n_proc_info = n_proc.to_dict()
         self.assertEquals(False, n_proc_info['is_processable'])
         self.assertEquals({}, n_proc_info['message_data'])
         self.assertEquals(
             [NotificationProcessing.STEP_NOTIFICATIONS_DISABLED],
             n_proc_info['checking_steps'])
     except Exception, e:
         raise e
예제 #9
0
 def test_get_message_data_unknown_event(self, curs=None):
     env = self.get_environment_by_name(self.actor_env_name)
     n = Notifier()
     s_old = settings.email_notifications_enabled
     settings.email_notifications_enabled = True
     try:
         n_proc = n._get_message_data(env.id, 'FAKE',
             Notification.TYPE_EMAIL, message.LANG_EN, curs)
         n_proc_info = n_proc.to_dict()
         self.assertEquals(False, n_proc_info['is_processable'])
         self.assertEquals({}, n_proc_info['message_data'])
         self.assertEquals(
             [NotificationProcessing.STEP_NOTIFICATIONS_ENABLED,
             NotificationProcessing.STEP_UNKNOWN_EVENT],
             n_proc_info['checking_steps'])
     except Exception, e:
         raise e
예제 #10
0
 def test_get_message_data_default_lang_selection(self, curs=None):
     env = self.get_environment_by_name(self.actor_env_name)
     n = Notifier()
     s_old = settings.email_notifications_enabled
     settings.email_notifications_enabled = True
     try:
         n_proc = n._get_message_data(env.id, message.EVENT_REGISTER_USER,
             Notification.TYPE_EMAIL, 'FAKE', curs)
         n_proc_info = n_proc.to_dict()
         self.assertEquals(True, n_proc_info['is_processable'])
         self.assertEquals(
             [NotificationProcessing.STEP_NOTIFICATIONS_ENABLED,
             NotificationProcessing.STEP_EVENT_NOTIFICATION_ENABLED,
             NotificationProcessing.STEP_MSG_LANG_NOT_FOUND,
             NotificationProcessing.STEP_MSG_DFLT_LANG_FOUND],
             n_proc_info['checking_steps'])
     except Exception, e:
         raise e
예제 #11
0
 def test_get_message_data(self, curs=None):
     # Checking lang not found
     env = self.get_environment_by_name(self.actor_env_name)
     n = Notifier()
     s_old = settings.email_notifications_enabled
     settings.email_notifications_enabled = True
     try:
         for event in message.EVENTS:
             n_proc = n._get_message_data(env.id, event,
                 Notification.TYPE_EMAIL, message.LANG_EN, curs)
             n_proc_info = n_proc.to_dict()
             self.assertEquals(True, n_proc_info['is_processable'])
             self.assertEquals(
                 [NotificationProcessing.STEP_NOTIFICATIONS_ENABLED,
                 NotificationProcessing.STEP_EVENT_NOTIFICATION_ENABLED,
                 NotificationProcessing.STEP_MSG_LANG_FOUND],
                 n_proc_info['checking_steps'])
     except Exception, e:
         raise e
예제 #12
0
    def restore_password(self, data, req_info, curs=None):
        env_name = data.get('environment_name')
        env_f = EnvironmentFilter({'name': env_name}, {}, None)
        env = env_f.filter_one_obj(curs)

        # For correct action logging
        data['environment_id'] = env.id

        user_f = SubjectUserFilter(env.id, {'email': data.get('email')}, {}, None)
        user = user_f.filter_one_obj(curs)

        # creating user session
        auth = Authenticator()
        session = auth.create_restore_password_session(curs, env, user, req_info,
            lifetime_minutes=settings.session_restore_password_lifetime_minutes)
        _add_log_info(data, session)

        n = Notifier()
        n_process = n.restore_password(curs, user, session)
        return response_ok(notification=n_process)