fix: use sor.R for role lookup + proper datetime format
- Changed raw SQL role query to sor.R('role', {'role': name})
- Fixed timestampstr() → datetime format to avoid data truncation
- Added logined + reseller.operator roles alongside admin
This commit is contained in:
parent
ed4898bf90
commit
fb579cbd2f
@ -26,7 +26,7 @@ async with DBPools().sqlorContext('sage') as sor_sage:
|
||||
'SELECT id FROM organization WHERE id = ${oid}$', {'oid': org_id}
|
||||
)
|
||||
if not org_recs:
|
||||
now = timestampstr()
|
||||
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
await sor_sage.C('organization', {
|
||||
'id': org_id, 'orgname': sd.sub_dist_name, 'create_at': now,
|
||||
})
|
||||
@ -47,7 +47,7 @@ async with DBPools().sqlorContext('sage') as sor_sage:
|
||||
|
||||
# Generate password from uuid
|
||||
pwd = getID().replace('-','')[:12]
|
||||
now = timestampstr()
|
||||
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
user_id = getID()
|
||||
|
||||
await sor_sage.C('users', {
|
||||
@ -57,14 +57,13 @@ async with DBPools().sqlorContext('sage') as sor_sage:
|
||||
'user_status': '1', 'created_at': now,
|
||||
})
|
||||
|
||||
# Assign reseller.admin role
|
||||
role_recs = await sor_sage.sqlExe(
|
||||
"SELECT id FROM role WHERE role = ${r}$", {'r': 'reseller.admin'}
|
||||
)
|
||||
if role_recs:
|
||||
await sor_sage.C('userrole', {
|
||||
'userid': user_id, 'roleid': role_recs[0].id,
|
||||
})
|
||||
# Assign roles: logined + reseller.admin + reseller.operator
|
||||
for role_name in ['logined', 'reseller.admin', 'reseller.operator']:
|
||||
role_recs = await sor_sage.R('role', {'role': role_name})
|
||||
if role_recs:
|
||||
await sor_sage.C('userrole', {
|
||||
'userid': user_id, 'roleid': role_recs[0].id,
|
||||
})
|
||||
|
||||
return {
|
||||
'widgettype': 'Message',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user