From 352538a62f3c88d2aadfa3bc0c0dc48113f24bba Mon Sep 17 00:00:00 2001 From: NuttyShrimp Date: Mon, 2 Dec 2024 16:15:57 +0100 Subject: [PATCH] feat: add permission options to requestable files --- .../classes/accessRequests/AccessRequest.ts | 9 ++--- controller/src/classes/utils/Permissions.ts | 16 +++++++++ controller/src/types/modules.ts | 2 +- loama/src/lib/utils.ts | 9 +++++ loama/src/views/RequestView.vue | 34 ++++++++++++++++--- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 controller/src/classes/utils/Permissions.ts diff --git a/controller/src/classes/accessRequests/AccessRequest.ts b/controller/src/classes/accessRequests/AccessRequest.ts index e15eba3..687057c 100644 --- a/controller/src/classes/accessRequests/AccessRequest.ts +++ b/controller/src/classes/accessRequests/AccessRequest.ts @@ -2,6 +2,7 @@ import { getDatetime, getLinkedResourceUrlAll, getResourceInfo, getStringNoLocal import { AccessRequestMessage, Permission, RequestResponseMessage, ResourceAccessRequestNode, Resources } from "../../types"; import { IAccessRequest, IController, IInbox, IInboxConstructor, IStore } from "../../types/modules"; import { cacheBustedFetch } from "../../util"; +import { PermissionToACL } from "../utils/Permissions"; const REQUEST_RESPONSE_TYPES = ["as:Accept", "as:Reject"] @@ -94,7 +95,7 @@ export abstract class AccessRequest implements IAccessRequest { await this.resources.saveToRemote(); } - async sendRequestNotification(originWebId: string, resources: string[]) { + async sendRequestNotification(originWebId: string, resources: string[], permissions: Permission[]) { const requestableResources = await this.resources.getCurrent(); const filteredResources = resources.filter(r => requestableResources.items.includes(r)); @@ -128,11 +129,7 @@ export abstract class AccessRequest implements IAccessRequest { "@type": "acl:Authorization", "acl:agent": originWebId, "acl:accessTo": r, - "acl:mode": [ - { - "@id": "acl:Read" - } - ] + "acl:mode": permissions.map(p => ({ "@id": PermissionToACL(p) })) } }); }; diff --git a/controller/src/classes/utils/Permissions.ts b/controller/src/classes/utils/Permissions.ts new file mode 100644 index 0000000..efe11af --- /dev/null +++ b/controller/src/classes/utils/Permissions.ts @@ -0,0 +1,16 @@ +import { Permission } from "../../types"; + +export const PermissionToACL = (permission: Permission): string => { + switch (permission) { + case Permission.Read: + return "acl:Read" + case Permission.Write: + return "acl:Write" + case Permission.Append: + return "acl:Append" + case Permission.Control: + return "acl:Control" + default: + throw new Error("Permission not found"); + } +} diff --git a/controller/src/types/modules.ts b/controller/src/types/modules.ts index d5fb159..cec8e4d 100644 --- a/controller/src/types/modules.ts +++ b/controller/src/types/modules.ts @@ -46,7 +46,7 @@ export interface IAccessRequest { disallowAccessRequest(resourceUrl: string): Promise // Notifications - sendRequestNotification(originWebId: string, resources: string[]): Promise; + sendRequestNotification(originWebId: string, resources: string[], permissions: Permission[]): Promise; sendResponseNotification(type: "accept" | "reject", message: AccessRequestMessage): Promise; loadAccessRequests(): Promise; diff --git a/loama/src/lib/utils.ts b/loama/src/lib/utils.ts index 55d0bed..6fba494 100644 --- a/loama/src/lib/utils.ts +++ b/loama/src/lib/utils.ts @@ -1,3 +1,5 @@ +import { Permission } from "loama-controller"; + export const uriToName = (uri: string, isContainer: boolean) => { const splitted = uri.split('/'); @@ -17,3 +19,10 @@ export const debounce = (fn: Function, wait: number) => { }, wait); } } + +export const allPermissions = [ + Permission.Read, + Permission.Write, + Permission.Append, + Permission.Control, +] diff --git a/loama/src/views/RequestView.vue b/loama/src/views/RequestView.vue index e632e31..4faccba 100644 --- a/loama/src/views/RequestView.vue +++ b/loama/src/views/RequestView.vue @@ -4,14 +4,16 @@