Skip to content

Commit 9114d31

Browse files
committed
Always use webId system for ldp.container.exist
1 parent b8f1244 commit 9114d31

11 files changed

Lines changed: 28 additions & 39 deletions

File tree

src/middleware/packages/ldp/mixins/controlled-container.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ module.exports = {
108108

109109
do {
110110
if (containerExist === false) await delay(1000);
111-
containerExist = await ctx.call('ldp.container.exist', { containerUri, webId: 'system' });
111+
containerExist = await ctx.call('ldp.container.exist', { containerUri });
112112
} while (!containerExist);
113113

114114
const parentContainerUri = getParentContainerUri(containerUri);
115-
const parentContainerExist = await ctx.call('ldp.container.exist', {
116-
containerUri: parentContainerUri,
117-
webId: 'system'
118-
});
115+
const parentContainerExist = await ctx.call('ldp.container.exist', { containerUri: parentContainerUri });
119116

120117
// If a parent container exist, check that the child container has been attached
121118
// Otherwise, it may fail

src/middleware/packages/ldp/services/container/actions/createAndAttach.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
async handler(ctx) {
1919
const { containerUri, title, description, options, webId } = ctx.params;
2020

21-
const exists = await ctx.call('ldp.container.exist', { containerUri, webId: 'system' });
21+
const exists = await ctx.call('ldp.container.exist', { containerUri });
2222

2323
if (!exists) {
2424
let parentContainerUri;
@@ -41,10 +41,7 @@ module.exports = {
4141
parentContainerUri = urlJoin(parentContainerUri, '/');
4242
}
4343

44-
const parentExists = await ctx.call('ldp.container.exist', {
45-
containerUri: parentContainerUri,
46-
webId: 'system'
47-
});
44+
const parentExists = await ctx.call('ldp.container.exist', { containerUri: parentContainerUri });
4845

4946
if (!parentExists) {
5047
// Recursively create the parent containers, without title/description/permissions

src/middleware/packages/ldp/services/container/actions/exist.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ const { MIME_TYPES } = require('@semapps/mime-types');
33
module.exports = {
44
visibility: 'public',
55
params: {
6-
containerUri: { type: 'string' },
7-
webId: { type: 'string', optional: true }
6+
containerUri: { type: 'string' }
87
},
98
async handler(ctx) {
10-
const webId = ctx.params.webId || ctx.meta.webId || 'anon';
119
// Matches container with or without trailing slash
1210
const containerUri = ctx.params.containerUri.replace(/\/+$/, '');
1311

@@ -25,7 +23,7 @@ module.exports = {
2523
}
2624
`,
2725
accept: MIME_TYPES.JSON,
28-
webId
26+
webId: 'system'
2927
});
3028
}
3129
};

src/middleware/packages/ldp/services/container/actions/patch.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ module.exports = {
4242
const resourcesAdded = [],
4343
resourcesRemoved = [];
4444

45-
const containerExist = await ctx.call('ldp.container.exist', { containerUri, webId });
45+
const containerExist = await ctx.call('ldp.container.exist', { containerUri });
4646
if (!containerExist) {
4747
throw new MoleculerError(`Cannot update content of non-existing container ${containerUri}`, 400, 'BAD_REQUEST');
4848
}
4949

5050
if (!triplesToAdd && !triplesToRemove)
5151
throw new MoleculerError('No triples to add or to remove', 400, 'BAD_REQUEST');
5252

53+
if (triplesToRemove) {
54+
await ctx.call('permissions.check', { uri: containerUri, type: 'container', mode: 'acl:Write', webId });
55+
} else {
56+
await ctx.call('permissions.check', { uri: containerUri, type: 'container', mode: 'acl:Append', webId });
57+
}
58+
5359
if (triplesToAdd) {
5460
for (const triple of triplesToAdd) {
5561
checkTripleValidity(triple, containerUri);

src/middleware/packages/ldp/services/container/actions/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
const resourceUri =
7272
forcedResourceUri || (await ctx.call('ldp.resource.generateId', { containerUri, slug, isContainer }));
7373

74-
const containerExist = await ctx.call('ldp.container.exist', { containerUri, webId });
74+
const containerExist = await ctx.call('ldp.container.exist', { containerUri });
7575
if (!containerExist) {
7676
throw new MoleculerError(
7777
`Cannot create resource in non-existing container ${containerUri} (webId ${webId} / dataset ${ctx.meta.dataset})`,

src/middleware/packages/sync/middlewares/objects-watcher.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ const ObjectsWatcherMiddleware = (config = {}) => {
141141
case 'webacl.resource.deleteAllRights':
142142
// If we are modifying rights of an ACL group, ignore
143143
if (new URL(ctx.params.resourceUri).pathname.startsWith('/_groups/')) return await next(ctx);
144-
const containerExist = await ctx.call('ldp.container.exist', {
145-
containerUri: ctx.params.resourceUri,
146-
webId: 'system'
147-
});
144+
const containerExist = await ctx.call('ldp.container.exist', { containerUri: ctx.params.resourceUri });
148145
if (containerExist) {
149146
// We don't want to announce containers right changes
150147
return await next(ctx);
@@ -184,10 +181,7 @@ const ObjectsWatcherMiddleware = (config = {}) => {
184181

185182
case 'webacl.resource.deleteAllRights':
186183
// Ensure the resource has not already been deleted (this action is used by the WebAclMiddleware when resources are deleted)
187-
const containerExist = await ctx.call('ldp.container.exist', {
188-
containerUri: ctx.params.resourceUri,
189-
webId: 'system'
190-
});
184+
const containerExist = await ctx.call('ldp.container.exist', { containerUri: ctx.params.resourceUri });
191185
const resourceExist = await ctx.call('ldp.resource.exist', {
192186
resourceUri: ctx.params.resourceUri,
193187
acceptTombstones: false, // Ignore Tombstones

src/middleware/packages/webacl/services/group/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ module.exports = {
6868
await this.actions.create({ groupSlug: 'superadmins', webId: 'system' });
6969
}
7070

71-
const rootContainerExist = await this.broker.call('ldp.container.exist', {
72-
containerUri: this.settings.baseUrl,
73-
webId: 'system'
74-
});
71+
const rootContainerExist = await this.broker.call('ldp.container.exist', { containerUri: this.settings.baseUrl });
7572

7673
if (!rootContainerExist) {
7774
throw new Error('To give superadmins rights, you must setup a root container');

src/middleware/packages/webacl/services/resource/actions/deleteAllRights.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
async handler(ctx) {
88
const { resourceUri } = ctx.params;
99

10-
const isContainer = await ctx.call('ldp.container.exist', { containerUri: resourceUri, webId: 'system' });
10+
const isContainer = await ctx.call('ldp.container.exist', { containerUri: resourceUri });
1111

1212
await ctx.call('triplestore.update', {
1313
query: `

src/middleware/packages/webacl/services/resource/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = {
9191
return false; // it is never a container
9292
}
9393
// it can be a container or a resource
94-
const containerExist = await ctx.call('ldp.container.exist', { containerUri: resourceUri, webId: 'system' });
94+
const containerExist = await ctx.call('ldp.container.exist', { containerUri: resourceUri });
9595
if (!containerExist) {
9696
// it must be a resource then!
9797
const resourceExist = await ctx.call('ldp.resource.exist', { resourceUri, webId: 'system' });

src/middleware/tests/ldp/container.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ describe('LDP container tests', () => {
4848
webId: 'system'
4949
});
5050

51-
// Intermediate containers have no permissions
52-
expect(broker.call('ldp.container.exist', { containerUri: `${CONFIG.HOME_URL}parent` })).resolves.toBeFalsy();
53-
expect(
54-
broker.call('ldp.container.exist', { containerUri: `${CONFIG.HOME_URL}parent`, webId: 'system' })
51+
await expect(
52+
broker.call('ldp.container.exist', { containerUri: `${CONFIG.HOME_URL}parent` })
5553
).resolves.toBeTruthy();
5654

57-
expect(
55+
// Intermediate containers have no permissions
56+
await expect(broker.call('ldp.container.get', { containerUri: `${CONFIG.HOME_URL}parent` })).rejects.toThrow();
57+
58+
await expect(
5859
broker.call('ldp.container.exist', { containerUri: `${CONFIG.HOME_URL}parent/child` })
5960
).resolves.toBeTruthy();
6061

0 commit comments

Comments
 (0)