Skip to content

Commit

Permalink
Merge branch 'rename-pod-service-to-storage-service'
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Dec 19, 2024
2 parents 1ad2e13 + 09f8597 commit efe11fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/middleware/packages/ldp/services/registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ module.exports = {
const { webId, accountData } = ctx.params;
// We want to add user's containers only in Pod provider config
if (this.settings.podProvider) {
const podUrl = await ctx.call('solid-storage.getUrl', { webId });
const storageUrl = await ctx.call('solid-storage.getUrl', { webId });
const registeredContainers = await this.actions.list({ dataset: accountData.username }, { parentCtx: ctx });
// Go through each registered containers
for (const container of Object.values(registeredContainers)) {
await ctx.call('ldp.container.createAndAttach', {
containerUri: urlJoin(podUrl, container.path),
containerUri: urlJoin(storageUrl, container.path),
webId
});
}
Expand Down
60 changes: 10 additions & 50 deletions src/middleware/packages/solid/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {

await this.broker.call('ontologies.register', pim);

// Register root container for the Pod (/:username/data/)
// Register root container for the storage (/:username/data/)
// Do not await or we will have a circular dependency with the LdpRegistryService
this.broker.call('ldp.registry.register', {
path: '/',
Expand All @@ -36,76 +36,36 @@ module.exports = {

ctx.meta.dataset = username;

// Create the Pod root container so that the LdpRegistryService can create the default containers
const podRootUri = urlJoin(this.settings.baseUrl, username, this.settings.pathName);
await ctx.call('ldp.container.create', { containerUri: podRootUri, webId: 'system' });
// Create the storage root container so that the LdpRegistryService can create the default containers
const storageRootUri = urlJoin(this.settings.baseUrl, username, this.settings.pathName);
await ctx.call('ldp.container.create', { containerUri: storageRootUri, webId: 'system' });

return podRootUri;
return storageRootUri;
},
async getUrl(ctx) {
const { webId } = ctx.params;
// This is faster, but later we should use the 'pim:storage' property of the webId
return urlJoin(webId, this.settings.pathName);
},
async createAndAttachContainers(ctx) {
const registeredContainers = await ctx.call('ldp.registry.list');
const accounts = await ctx.call('auth.account.find');
for (const { webId, username } of accounts) {
this.logger.info(`Creating and attaching containers for ${webId}...`);

const podUrl = await this.actions.getUrl({ webId }, { parentCtx: ctx });
ctx.meta.dataset = username;

for (const { path, permissions } of Object.values(registeredContainers)) {
await ctx.call('ldp.container.createAndAttach', {
containerUri: urlJoin(podUrl, path),
permissions, // Used by the WebAclMiddleware
webId
});
}

// Give full rights to user on his pod
await ctx.call('webacl.resource.addRights', {
resourceUri: podUrl,
additionalRights: {
user: {
uri: webId,
read: true,
write: true,
control: true
},
default: {
user: {
uri: webId,
read: true,
write: true,
control: true
}
}
},
webId: 'system'
});
}
}
},
events: {
async 'auth.registered'(ctx) {
const { webId } = ctx.params;

const podUrl = await this.actions.getUrl({ webId }, { parentCtx: ctx });
const storageUrl = await this.actions.getUrl({ webId }, { parentCtx: ctx });

// Attach the podUrl to the webId
// Attach the storage URL to the webId
await ctx.call('ldp.resource.patch', {
resourceUri: webId,
triplesToAdd: [
triple(namedNode(webId), namedNode('http://www.w3.org/ns/pim/space#storage'), namedNode(podUrl))
triple(namedNode(webId), namedNode('http://www.w3.org/ns/pim/space#storage'), namedNode(storageUrl))
],
webId: 'system'
});

// Give full rights to user on his pod
// Give full rights to user on his storage
await ctx.call('webacl.resource.addRights', {
resourceUri: podUrl,
resourceUri: storageUrl,
additionalRights: {
user: {
uri: webId,
Expand Down

0 comments on commit efe11fd

Please sign in to comment.