From fb579cbd2fd403f48a93196e31f52f11fd358f56 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 10 Jul 2026 13:52:14 +0800 Subject: [PATCH] fix: use sor.R for role lookup + proper datetime format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- wwwroot/api/add_sub_distributor_admin.dspy | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wwwroot/api/add_sub_distributor_admin.dspy b/wwwroot/api/add_sub_distributor_admin.dspy index a20747d..fc381e2 100644 --- a/wwwroot/api/add_sub_distributor_admin.dspy +++ b/wwwroot/api/add_sub_distributor_admin.dspy @@ -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',