Esempio n. 1
0
    def auth_user_role_detail(cls, account_id) -> dict:
        acc: Accounts = Accounts.select(Accounts).where(
            Accounts.id == account_id).first()
        rs = AuthUser.select().where(AuthUser.acc_id == account_id)
        auth_user_dict = {
            'acc':
            Accounts.to_dict(
                acc, BASE_FIELDS + [
                    "id", "password", "fuzzy_id", "login_token",
                    "login_updated_at", "pin"
                ])
        }
        if rs:
            au: AuthUser = rs[0]
            auth_user_dict['au'] = {
                'oid': au.org_id,
                'rfid': au.ref_id,
                'rid': au.role_id,
                't': au.type
            }
            auth_user_dict['role'] = cls._get_roles(au)
            role_list = []
            role_obj_list = Role.select()
            for r in role_obj_list:
                role_list.append(Role.to_dict(r, BASE_FIELDS))
            auth_user_dict['roles'] = role_list

        return auth_user_dict
Esempio n. 2
0
 def user_list(self, kw, size, offset):
     items = DataDao.query_user_list_by_keyword(kw,
                                                offset=offset,
                                                limit=size)
     item_json_list = []
     # print("items:", items)
     for item in items:
         item_json_list.append(Accounts.to_dict(item, BASE_FIELDS + ['id']))
     return item_json_list
Esempio n. 3
0
    def account_list(cls, pin=None, _type=None, offset=0, page_size=30):
        if pin and _type:
            account_list = Accounts.select(Accounts, AuthUser).join(
                AuthUser, on=(Accounts.id == AuthUser.acc_id),
                attr='auth').where(Accounts.pin == pin,
                                   AuthUser.type == _type).order_by(
                                       Accounts.created_at.desc()).offset(
                                           offset).limit(page_size)
        elif _type:
            account_list = Accounts.select(Accounts, AuthUser).join(
                AuthUser, on=(Accounts.id == AuthUser.acc_id),
                attr='auth').where(AuthUser.type == _type).order_by(
                    Accounts.created_at.desc()).offset(offset).limit(page_size)
        elif pin:
            account_list = Accounts.select().where(
                Accounts.pin == pin).order_by(
                    Accounts.created_at.desc()).offset(offset).limit(page_size)
        else:
            account_list = Accounts.select(Accounts).order_by(
                Accounts.created_at.desc()).offset(offset).limit(page_size)
        # print("account_list:", account_list)
        rs = []
        n = 0
        acc_ids = []
        for acc in account_list:
            acc_dict = Accounts.to_dict(acc)
            if hasattr(acc, 'auth') and acc.auth:
                auth_user_dict = AuthUser.to_dict(acc.auth, BASE_FIELDS)
                acc_dict['auth'] = auth_user_dict
            else:
                acc_ids.append(acc.id)
            if not acc.fuzzy_id:
                acc_dict['fuzzy_id'] = obfuscate_id(acc.id)
            rs.append(acc_dict)

            n = n + 1
        au_list = AuthUser.select().where(AuthUser.acc_id.in_(acc_ids))
        au_dict = {}
        if au_list:
            for au in au_list:
                au_dict[au.acc_id] = AuthUser.to_dict(au)

        for acc_dict in rs:
            if acc_dict['id'] in au_dict:
                acc_dict['auth'] = au_dict[acc_dict['id']]
            uoe_list = UserOrgExtend.select().where(
                UserOrgExtend.acc_id == acc_dict['id'])
            if uoe_list:
                acc_dict['extorgs'] = [uoe.org_id for uoe in uoe_list]
            ure_list = UserRoleExtend.select().where(
                UserRoleExtend.acc_id == acc_dict['id'])
            if ure_list:
                acc_dict['extroles'] = [ure.role_id for ure in ure_list]
            acc_dict.pop('id')
        return rs, n == page_size
Esempio n. 4
0
    def auth_user_detail(cls, account_id) -> dict:
        acc: Accounts = Accounts.select(Accounts).where(
            Accounts.id == account_id).first()
        rs = AuthUser.select().where(AuthUser.acc_id == account_id)
        auth_user_dict = {
            'acc':
            Accounts.to_dict(
                acc, BASE_FIELDS + [
                    "id", "password", "fuzzy_id", "login_token",
                    "login_updated_at", "pin"
                ])
        }
        if rs:
            au: AuthUser = rs[0]
            org: Org = Org.select().where(Org.id == au.org_id).first()
            auth_user_dict['org'] = {
                'base': Org.to_dict(org, BASE_FIELDS),
                'parent': {
                    'id': 0,
                    'name': '无'
                }
            }
            if org.parent:
                porg: Org = Org.select().where(Org.id == org.parent).first()
                auth_user_dict['org']['parent'] = porg
            ext_org_list = Org.select(Org).join(
                UserOrgExtend, on=(UserOrgExtend.org_id == Org.id)).where(
                    UserOrgExtend.acc_id == au.acc_id)
            if ext_org_list:
                ext_org = auth_user_dict['org']['ext'] = []
                for org in ext_org_list:
                    ext_org.append(Org.to_dict(org, BASE_FIELDS))
            auth_user_dict['au'] = {
                'oid': au.org_id,
                'rfid': au.ref_id,
                'rid': au.role_id,
                't': au.type
            }
            auth_user_dict['role'] = cls._get_roles(au)

        return auth_user_dict