示例#1
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)
示例#2
0
 def _get_user_rights(self, curs, env, user, srvs):
     rights = {}
     if user.role != User.ROLE_SUPER:
         f = GroupFilter(env.id, {'ids': user.groups_ids, 'is_active': True},
             {}, None)
         groups = f.filter_objs(curs)
         for g in groups:
             rights_lst = json.loads(g.serialized_rights)
             for r in rights_lst:
                 # String key id for json.encode
                 srv_id = str(r['service_id'])
                 srv_props = r['properties']
                 cur_props = rights.get(srv_id, [])
                 rights[srv_id] = list(set(cur_props + srv_props))
     res = {}
     for srv in srvs:
         if user.role == User.ROLE_SUPER:
             r = json.loads(srv.serialized_properties)
         else:
             r = rights.get(str(srv.id), []) # String key id for json.encode
         res[srv.type] = r
     return res
示例#3
0
 def _filter_existed_groups(self, curs, session, groups_ids):
     f = GroupFilter(session.environment_id, {}, {}, None)
     groups = f.filter_objs(curs)
     g_ids = [g.id for g in groups]
     return filter(lambda x: x in g_ids, groups_ids)