-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ModelId } from "../shared/model_id"; | ||
|
||
// Supported permissions | ||
export const SUPPORTED_PERMISSIONS = ["read", "write", "execute"] as const; | ||
|
||
export type PermissionType = (typeof SUPPORTED_PERMISSIONS)[number]; | ||
|
||
// Access Control Entry | ||
export type ACEType = { | ||
groupId: ModelId; | ||
permissions: PermissionType[]; | ||
}; | ||
|
||
// Access Control List | ||
export type ACLType = { | ||
aclEntries: Array<ACEType>; | ||
}; | ||
|
||
export function groupHasPermission( | ||
acl: ACLType, | ||
permission: PermissionType, | ||
groupId: ModelId | ||
): boolean { | ||
const entry = acl.aclEntries.find((ace) => ace.groupId === groupId); | ||
if (entry) { | ||
return entry.permissions.includes(permission); | ||
} | ||
return false; | ||
} |