Skip to content

Commit

Permalink
Only users are part of the 'all users' group
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Sep 24, 2023
1 parent 9f533ce commit 798f507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
* Update to curveball 0.21
* Refactored the privilege system to make internally easier to use. There
should be no end-user effects to this.
* Added a system group principal , which allows admins to set privileges for
every user in the system.


0.23.1 (2023-03-29)
Expand Down
12 changes: 6 additions & 6 deletions src/privilege/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function getRecursiveGroupIds(principalId: number): Promise<number[]> {
async function getPrivilegesForPrincipal(principal: Principal): Promise<PrivilegeMap> {

const recursiveGroupIds = await getRecursiveGroupIds(principal.id);
recursiveGroupIds.push(await getAllGroupId());
if (principal.type === 'user') recursiveGroupIds.push(await getAllUsersGroupId());

const result = await query(
`SELECT resource, privilege FROM user_privileges WHERE user_id IN (${recursiveGroupIds.map(_ => '?').join(',')})`,
Expand All @@ -273,14 +273,14 @@ async function getPrivilegesForPrincipal(principal: Principal): Promise<Privileg

}

let allGroupId: number|null = null;
let allUsersGroupId: number|null = null;

/**
* Returns the set of privileges for the $all group
*/
async function getAllGroupId() {
async function getAllUsersGroupId() {

if (allGroupId) return allGroupId;
if (allUsersGroupId) return allUsersGroupId;
const allPrincipal = await db('principals')
.select('id')
.first()
Expand All @@ -292,7 +292,7 @@ async function getAllGroupId() {
if (!allPrincipal) {
throw new Error('Could not find the $all group in the database!');
}
allGroupId = allPrincipal.id;
return allGroupId;
allUsersGroupId = allPrincipal.id;
return allUsersGroupId;

}

0 comments on commit 798f507

Please sign in to comment.