Skip to content

Commit

Permalink
Add acl
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier committed Jul 25, 2024
1 parent f0f62c4 commit 14f302e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions types/src/front/acl.ts
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;
}

0 comments on commit 14f302e

Please sign in to comment.