Skip to content

Commit 0431915

Browse files
committed
made changes to support PR feedback from solid-ui PR
1 parent 10ae9ef commit 0431915

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎src/acl/aclLogic.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { findEffectiveACL, planGrant as planAuthorizationGrant, planPublicRead as planAuthorizationPublicRead, type AccessMode, type AccessSubject, type ACLContext, type Authorization, type PatchPlan } from '@dokieli/web-access-control'
1+
import { applyPlan as applyAuthorizationPlan, findEffectiveACL, planGrant as planAuthorizationGrant, planPublicRead as planAuthorizationPublicRead, planRevoke as planAuthorizationRevoke, type AccessMode, type AccessSubject, type ACLContext, type Authorization, type PatchPlan } from '@dokieli/web-access-control'
22
import { graph, NamedNode, Namespace, serialize, sym } from 'rdflib'
33
import type { AclLogic } from '../types'
44
import { ns as namespace } from '../util/ns'
@@ -57,10 +57,19 @@ export function createAclLogic(store): AclLogic {
5757
return planAuthorizationGrant(context, subject, modes)
5858
}
5959

60+
async function planRevoke(resourceURL: string | NamedNode, subject: AccessSubject): Promise<PatchPlan> {
61+
const context = await findEffectiveAcl(resourceURL)
62+
return planAuthorizationRevoke(context, subject)
63+
}
64+
6065
async function planPublicRead(resourceURL: string | NamedNode, enabled: boolean): Promise<PatchPlan> {
6166
const context = await findEffectiveAcl(resourceURL)
6267
return planAuthorizationPublicRead(context, enabled)
6368
}
69+
70+
async function applyPlan(plan: PatchPlan): Promise<Response> {
71+
return applyAuthorizationPlan(plan, { fetch: getFetch() })
72+
}
6473
/**
6574
* Simple Access Control
6675
*
@@ -194,7 +203,9 @@ export function createAclLogic(store): AclLogic {
194203
findEffectiveAcl,
195204
findAccessGrants,
196205
planGrant,
206+
planRevoke,
197207
planPublicRead,
208+
applyPlan,
198209
setACLUserPublic,
199210
genACLText
200211
}

‎src/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export interface AclLogic {
8383
findEffectiveAcl: (resourceURL: string | NamedNode) => Promise<ACLContext>,
8484
findAccessGrants: (resourceURL: string | NamedNode) => Promise<Authorization[]>,
8585
planGrant: (resourceURL: string | NamedNode, subject: AccessSubject, modes: AccessMode[]) => Promise<PatchPlan>,
86+
planRevoke: (resourceURL: string | NamedNode, subject: AccessSubject) => Promise<PatchPlan>,
8687
planPublicRead: (resourceURL: string | NamedNode, enabled: boolean) => Promise<PatchPlan>,
88+
applyPlan: (plan: PatchPlan) => Promise<Response>,
8789
setACLUserPublic: (docURI: string, me: NamedNode,
8890
options: {
8991
defaultForNew?: boolean,

‎test/aclLogic.test.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
22
import { Fetcher, Store, sym, UpdateManager } from 'rdflib'
3-
import { findEffectiveACL, planGrant, planPublicRead } from '@dokieli/web-access-control'
3+
import { applyPlan, findEffectiveACL, planGrant, planPublicRead, planRevoke } from '@dokieli/web-access-control'
44
import { ACL_LINK, createAclLogic } from '../src/acl/aclLogic'
55

66
vi.mock('@dokieli/web-access-control', () => ({
77
findEffectiveACL: vi.fn(),
88
planGrant: vi.fn(),
99
planPublicRead: vi.fn(),
10+
planRevoke: vi.fn(),
11+
applyPlan: vi.fn(),
1012
Authenticated: Symbol('Authenticated'),
1113
Public: Symbol('Public'),
12-
planOwnerControl: vi.fn(),
13-
planRevoke: vi.fn()
14+
planOwnerControl: vi.fn()
1415
}))
1516

1617
describe('createAclLogic', () => {
@@ -102,6 +103,30 @@ describe('createAclLogic', () => {
102103
expect(planPublicRead).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), true)
103104
})
104105

106+
it('delegates planRevoke through the effective ACL context', async () => {
107+
const resource = sym('https://example.com/resource.ttl')
108+
const subject = { type: 'agent', iri: 'https://example.com/profile/card#me' }
109+
const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] }
110+
111+
vi.mocked(findEffectiveACL).mockResolvedValue({ authorizations: [] } as any)
112+
vi.mocked(planRevoke).mockReturnValue(plan as any)
113+
store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 }))
114+
115+
await expect(aclLogic.planRevoke(resource, subject as any)).resolves.toBe(plan)
116+
expect(planRevoke).toHaveBeenCalledWith(expect.objectContaining({ authorizations: [] }), subject)
117+
})
118+
119+
it('applies a patch plan with the store fetcher', async () => {
120+
const plan = { target: 'https://example.com/resource.ttl.acl', deletes: [], inserts: [] }
121+
const response = new Response('ok', { status: 200 })
122+
123+
store.fetcher._fetch.mockResolvedValue(new Response('', { status: 200 }))
124+
vi.mocked(applyPlan).mockResolvedValue(response)
125+
126+
await expect(aclLogic.applyPlan(plan as any)).resolves.toBe(response)
127+
expect(applyPlan).toHaveBeenCalledWith(plan, expect.objectContaining({ fetch: expect.any(Function) }))
128+
})
129+
105130
it('throws when the store cannot supply a fetch function', async () => {
106131
const resource = sym('https://example.com/resource.ttl')
107132
store.fetcher = { _fetch: vi.fn(), load: vi.fn(), webOperation: vi.fn(), unload: vi.fn() } as any

‎test/resourceLogic.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('resourceLogic', () => {
3838
findEffectiveAcl: vi.fn().mockResolvedValue({ authorizations: [] }),
3939
findAccessGrants: vi.fn().mockResolvedValue([]),
4040
planGrant: vi.fn(),
41+
planRevoke: vi.fn(),
4142
planPublicRead: vi.fn(),
43+
applyPlan: vi.fn(),
4244
setACLUserPublic: vi.fn(),
4345
genACLText: vi.fn()
4446
}

0 commit comments

Comments
 (0)