@@ -33,54 +33,58 @@ export async function queryAccountAuthoritiesById(
3333) : Promise < Array < string > > {
3434 try {
3535 const result = await query (
36- // SELECT
37- // r.scope || '.role.' || r.name AS authority
38- // FROM
39- // accounts ua
40- // JOIN
41- // account_roles ur ON ua.id = ur.account_id
42- // JOIN
43- // roles r ON ur.role_id = r.id
44- // WHERE
45- // ua.id = $1
46- // AND (r.scope = $2 )
36+ `-- Select roles for the specified user and scope
37+ SELECT
38+ r.scope || '.role.' || r.name AS authority
39+ FROM
40+ accounts ua
41+ JOIN
42+ account_roles ur ON ua.id = ur.account_id
43+ JOIN
44+ roles r ON ur.role_id = r.id
45+ WHERE
46+ ua.id = $1
47+ AND r.scope = $2
4748
48- // UNION
49- `
50- SELECT
51- p.scope || '.perm.' || p.name AS authority
52- FROM
53- accounts ua
54- JOIN
55- account_roles ur ON ua.id = ur.account_id
56- JOIN
57- roles r ON ur.role_id = r.id
58- JOIN
59- role_permissions rp ON r.id = rp.role_id
60- JOIN
61- permissions p ON rp.permission_id = p.id
62- WHERE
63- ua.id = $1
64- AND (p.scope = $2)
49+ UNION
6550
66- UNION
51+ -- Select permissions associated with roles for the specified user and scope
52+ SELECT
53+ p.scope || '.perm.' || p.name AS authority
54+ FROM
55+ accounts ua
56+ JOIN
57+ account_roles ur ON ua.id = ur.account_id
58+ JOIN
59+ roles r ON ur.role_id = r.id
60+ JOIN
61+ role_permissions rp ON r.id = rp.role_id
62+ JOIN
63+ permissions p ON rp.permission_id = p.id
64+ WHERE
65+ ua.id = $1
66+ AND p.scope = $2
6767
68- SELECT
69- p.scope || '.perm.' || p.name AS authority
70- FROM
71- accounts ua
72- JOIN
73- account_permissions up ON ua.id = up.account_id
74- JOIN
75- permissions p ON up.permission_id = p.id
76- WHERE
77- ua.id = $1
78- AND (p.scope = $2);
79- ` ,
68+ UNION
69+
70+ -- Select permissions directly assigned to the specified user and scope
71+ SELECT
72+ p.scope || '.perm.' || p.name AS authority
73+ FROM
74+ accounts ua
75+ JOIN
76+ account_permissions up ON ua.id = up.account_id
77+ JOIN
78+ permissions p ON up.permission_id = p.id
79+ WHERE
80+ ua.id = $1
81+ AND p.scope = $2;
82+ ` ,
8083 [ accountId , scope ]
8184 ) ;
8285
83- return result . rows . map ( ( row ) => row . authority ) ;
86+ const res = result . rows . map ( ( row ) => row . authority ) ;
87+ return res ;
8488 } catch ( error ) {
8589 console . error ( "Error fetching account authorities:" , error ) ;
8690 return [ ] ;
0 commit comments