@@ -2,7 +2,9 @@ import { applyPlan as applyAuthorizationPlan, findEffectiveACL, planGrant as pla
22import { graph , NamedNode , Namespace , serialize , sym } from 'rdflib'
33import type { AclLogic } from '../types'
44import { ns as namespace } from '../util/ns'
5+ import * as accessControlSubjects from './accessControlSubjects'
56
7+ // Will remove the below comment when i'm done with the manage access work
68// Helpers available from @dokieli/web-access-control:
79// - Discovery: findEffectiveACL, parentContainer
810// - ACL context and parsing: buildACLContext, authorizationsFromDataset, parseTurtle
@@ -12,6 +14,9 @@ import { ns as namespace } from '../util/ns'
1214// - Link and allow parsing: allows, parseWacAllow, linkTargets, parseLinkHeader
1315// - Terms and constants: ACCESS_MODES, ACL, Authenticated, FOAF, modeFromIRI, modeIRI, namedNode, Public, quad, RDF_TYPE, variable
1416
17+ export const ACCESS_ROLES = [ 'Owner' , 'Editor' , 'No Access' , 'Viewer' , 'Poster' , 'Submitter' ] as const
18+
19+ export type AccessRole = typeof ACCESS_ROLES [ number ]
1520
1621export const ACL_LINK = sym (
1722 'http://www.iana.org/assignments/link-relations/acl'
@@ -20,6 +25,25 @@ export const ACL_LINK = sym(
2025export function createAclLogic ( store ) : AclLogic {
2126
2227 const ns = namespace
28+ const ACCESS_ROLE_RULES : Array < { label : AccessRole , modes : AccessMode [ ] } > = [
29+ { label : 'Owner' , modes : [ 'Read' , 'Write' , 'Control' ] } ,
30+ { label : 'Editor' , modes : [ 'Read' , 'Write' ] } ,
31+ { label : 'Poster' , modes : [ 'Append' , 'Read' ] } ,
32+ { label : 'Submitter' , modes : [ 'Append' ] } ,
33+ { label : 'Viewer' , modes : [ 'Read' ] } ,
34+ { label : 'No Access' , modes : [ ] }
35+ ]
36+
37+ function roleFromModes ( modes : Iterable < AccessMode > ) : AccessRole {
38+ const modeSet = new Set ( modes )
39+ const matchingRule = ACCESS_ROLE_RULES . find ( rule => rule . label !== 'No Access' && rule . modes . every ( mode => modeSet . has ( mode ) ) )
40+
41+ return matchingRule ?. label ?? 'No Access'
42+ }
43+
44+ function modesFromRole ( role : AccessRole ) : AccessMode [ ] {
45+ return [ ...( ACCESS_ROLE_RULES . find ( rule => rule . label === role ) ?. modes ?? [ ] ) ]
46+ }
2347
2448 function getFetch ( ) {
2549 const fetcher = store . fetcher as {
@@ -70,6 +94,10 @@ export function createAclLogic(store): AclLogic {
7094 async function applyPlan ( plan : PatchPlan ) : Promise < Response > {
7195 return applyAuthorizationPlan ( plan , { fetch : getFetch ( ) } )
7296 }
97+
98+ async function classifyAccessControlSubject ( principle : string ) {
99+ return accessControlSubjects . classifyAccessControlSubject ( store , principle )
100+ }
73101 /**
74102 * Simple Access Control
75103 *
@@ -202,10 +230,13 @@ export function createAclLogic(store): AclLogic {
202230 findAclDocUrl,
203231 findEffectiveAcl,
204232 findAccessGrants,
233+ roleFromModes,
234+ modesFromRole,
205235 planGrant,
206236 planRevoke,
207237 planPublicRead,
208238 applyPlan,
239+ classifyAccessControlSubject,
209240 setACLUserPublic,
210241 genACLText
211242 }
0 commit comments