Skip to content

Commit

Permalink
Merge pull request #194 from bourgeoa/aclUrlParser
Browse files Browse the repository at this point in the history
update aclUrlParser() to begin on current url
  • Loading branch information
bourgeoa authored Apr 4, 2021
2 parents 98f6794 + 5615afe commit 5678f55
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Binary file added file-placeholder.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solid-file-client",
"version": "1.2.4",
"version": "1.2.5",
"description": "A library for creating and managing files and folders in Solid data stores",
"author": "Jeff Zucker",
"maintainer": "Alain Bourgeois",
Expand Down
4 changes: 2 additions & 2 deletions src/SolidFileClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class SolidFileClient extends SolidApi {
async aclUrlParser (url) {
const target = getItemName(url)
const max = url.substring(getRootUrl(url).length - 2).split('/').length
for (let i = 1; i < max; i++) {
url = getParentUrl(url)
for (let i = 0; i < max; i++) {
if (i) url = getParentUrl(url)
const links = await this.getItemLinks(url, { links: 'include' })
if (links.acl) {
let aclContent = await this.readFile(links.acl)
Expand Down
16 changes: 11 additions & 5 deletions tests/aclParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('aclUrlParser', () => {
acl: true,
placeholder: { meta: true }
}) // Note: Acl Content will be overriden by some tests
const targetWithAcl = new File('target.txt', 'target', 'text/plain', {
const targetWithoutAcl = new File('target.txt', 'target', 'text/plain', {
})
const targetFolderWithAcl = new Folder('folder-with-acl', [], {
acl: true, // Note: Content will be overriden by some tests
Expand All @@ -197,7 +197,7 @@ describe('aclUrlParser', () => {
const folder = new BaseFolder(container, 'aclUrlParser', [
new Folder('nested', [
targetFolderWithAcl,
targetWithAcl
targetWithoutAcl
])
], {
acl: true
Expand All @@ -206,14 +206,20 @@ describe('aclUrlParser', () => {
beforeEach(() => folder.reset())
folder.acl.content = acl0('./', '/profile/card#', defaultTarget)

test('get acl content for folder', async () => {
test('get acl content for folder with acl', async () => {
const users = await api.aclUrlParser(targetFolderWithAcl.url)
const keysUsers = ['agent&' + getRootUrl(folder.url) + '/profile/card#me', 'agentClass&Agent']
const usersKeys = Object.keys(users)
expect(usersKeys).toEqual(keysUsers)
})
test('get acl content for folder without acl', async () => {
const users = await api.aclUrlParser(folder.url+'nested/')
const keysUsers = ['agent&' + getRootUrl(folder.url) + '/profile/card#me', 'agent&https://test.solid.community/profile/card#me', 'agentClass&AuthenticatedAgent', 'agentClass&Agent']
const usersKeys = Object.keys(users)
expect(usersKeys).toEqual(keysUsers)
})
test('get acl content for file', async () => {
const users = await api.aclUrlParser(targetWithAcl.url)
test('get acl content for file without acl', async () => {
const users = await api.aclUrlParser(targetWithoutAcl.url)
const keysUsers = ['agent&' + getRootUrl(folder.url) + '/profile/card#me', 'agent&https://test.solid.community/profile/card#me', 'agentClass&AuthenticatedAgent', 'agentClass&Agent']
const usersKeys = Object.keys(users)
expect(usersKeys).toEqual(keysUsers)
Expand Down

0 comments on commit 5678f55

Please sign in to comment.