main #143
@ -27,15 +27,16 @@ async def reseller_add_user(ns):
|
||||
try:
|
||||
ns['id'] = uuid()
|
||||
ns['password'] = password_encode(ns['password'])
|
||||
tenant_orgid = await get_reseller_user_tenant_orgid(sor, ns.get('orgid'))
|
||||
# tenant_orgid = await get_reseller_user_tenant_orgid(sor, ns.get('orgid'))
|
||||
tenant_orgid = ns.get('orgid')
|
||||
if not tenant_orgid:
|
||||
return {'status': False, 'msg': '未找到用户所属租户'}
|
||||
user_sql = """select id from users where username = '%s' and tenant_orgid = '%s' and del_flg = '0' limit 1;""" % (ns['username'], tenant_orgid)
|
||||
user = await sor.sqlExe(user_sql, {})
|
||||
if len(user) >= 1:
|
||||
return {'status': False, 'msg': '用户名重复'}
|
||||
rolereacs = await sor.R('role', {'role': '管理员', 'del_flg': '0', 'org_type': '1'})
|
||||
ns['user_reseller'] = '1'
|
||||
rolereacs = await sor.R('role', {'role': '管理员', 'del_flg': '0', 'org_type': ns.get('org_type')})
|
||||
ns['user_reseller'] = ns.get('org_type')
|
||||
ns['tenant_orgid'] = tenant_orgid
|
||||
await sor.C('users', ns)
|
||||
await sor.C('userrole', {'userid': ns['id'], 'roleid': rolereacs[0]['id'], 'id': uuid()})
|
||||
|
||||
55
b/user/add_user_role.dspy
Normal file
55
b/user/add_user_role.dspy
Normal file
@ -0,0 +1,55 @@
|
||||
import json
|
||||
|
||||
|
||||
def _parse_roleids(roleid):
|
||||
if roleid is None:
|
||||
return []
|
||||
if isinstance(roleid, list):
|
||||
return [i for i in roleid if i]
|
||||
if isinstance(roleid, str):
|
||||
roleid = roleid.strip()
|
||||
if not roleid:
|
||||
return []
|
||||
try:
|
||||
roleids = json.loads(roleid)
|
||||
except Exception:
|
||||
roleids = [roleid]
|
||||
if isinstance(roleids, list):
|
||||
return [i for i in roleids if i]
|
||||
return [roleids] if roleids else []
|
||||
return [roleid]
|
||||
|
||||
|
||||
async def add_user_role(ns):
|
||||
"""
|
||||
用户分配角色
|
||||
:param userid: 用户id
|
||||
:param roleid: 角色id列表
|
||||
:return:
|
||||
"""
|
||||
if not ns or not ns.get('userid') or 'roleid' not in ns:
|
||||
return {'status': False, 'msg': '参数不正确'}
|
||||
|
||||
userid = ns.get('userid')
|
||||
roleids = _parse_roleids(ns.get('roleid'))
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
userroles = await sor.R('userrole', {'userid': userid})
|
||||
for userrole in userroles:
|
||||
if userrole.get('roleid') not in roleids:
|
||||
await sor.U('userrole', {'del_flg': '1', 'id': userrole['id']})
|
||||
|
||||
for roleid in roleids:
|
||||
roles = {'userid': userid, 'roleid': roleid}
|
||||
reacs = await sor.R('userrole', roles)
|
||||
if len(reacs) >= 1:
|
||||
await sor.U('userrole', {'id': reacs[0]['id'], 'del_flg': '0'})
|
||||
continue
|
||||
await sor.C('userrole', {'id': uuid(), 'userid': userid, 'roleid': roleid})
|
||||
return {'status': True, 'msg': '添加成功'}
|
||||
|
||||
return {'status': False, 'msg': '添加失败'}
|
||||
|
||||
|
||||
ret = await add_user_role(params_kw)
|
||||
return ret
|
||||
Loading…
x
Reference in New Issue
Block a user