示例#1
0
    def get_admins_infos(self):
        beg = self.get_argument("beg", 0)
        count = self.get_argument("count", 30)
        search = self.get_argument("search", "")
        sort = self.get_argument("sort", "telephone")
        self.logger.info("sort:" + sort)

        usr_rules_db = UserConfDao(session=self.session)
        admin_list = usr_rules_db.get_admins()
        results = []
        for admin in admin_list:
            if admin['user_name'].find(
                    search) == -1 and admin['telephone'].find(search) == -1:
                continue
            results.append(admin)
        results.sort(key=lambda admin: admin[sort])
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "get_admins_info",
                             "-")

        result = {
            "result":
            True,
            "count":
            len(results),
            "admins":
            results[int(beg):int(beg) + int(count)] if
            (int(beg) + int(count)) <= len(results) else results[int(beg):]
        }
        return result
示例#2
0
    def delete_admins(self, user_id):
        self.logger.info("user_id:" + user_id)

        usr_rle_db = UserConfDao(session=self.session)

        admins = usr_rle_db.get_admins()

        if len(admins) <= 1:
            result = {'result': False, 'msg': err_msgs['CANT_DEL_LAST_ADMIN']}
            self.set_status(400)
            return result

        usr_rle_db.delete_user_by_usrid_and_type(user_id,
                                                 UserConf.TYPE_ROLE_ADMIN)

        redis = RedisBase()
        usr_status_db = UserLastStatusDao(session=self.session)
        statuses = usr_status_db.get_status_by_userid_and_role_group(
            user_id, Users.ROLE_ADMIN)
        for status in statuses:
            if redis.exists_token(status.token):
                u_token_info = redis.get_token_info(status.token)
                u_token_info['status'] = {
                    'code': CODE_USER_DELETED,
                    'msg': token_status[CODE_USER_DELETED]['msg']
                }
                redis.set_token(status.token, json.dumps(u_token_info), False)

        usr_status_db.del_status(user_id, Users.ROLE_ADMIN)

        usr_db = UserDao(session=self.session)
        usr_db.delete_user(user_id, Users.ROLE_ADMIN)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "delete_admin",
                             user_id)

        result = {'result': True}

        return result