Skip to content

Commit

Permalink
Temporarily disable permissions removal on update
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Nov 26, 2024
1 parent e27f2b2 commit 3370bec
Showing 1 changed file with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
const { hasType } = require('@semapps/ldp');
const { ACTIVITY_TYPES } = require('../../../../constants');

const removeReadRights = async ({ ctx, recipientUris, resourceUri, skipObjectsWatcher, anon }) => {
if (recipientUris === 0 && !anon) return;
await ctx.call(
'webacl.resource.removeRights',
{
resourceUri,
rights: {
...(anon && { anon: { read: true } }),
...(recipientUris && {
uri: recipientUris,
read: true
})
},
webId: 'system'
},
{
meta: {
skipObjectsWatcher
}
}
);
};
// const removeReadRights = async ({ ctx, recipientUris, resourceUri, skipObjectsWatcher, anon }) => {
// if (recipientUris === 0 && !anon) return;
// await ctx.call(
// 'webacl.resource.removeRights',
// {
// resourceUri,
// rights: {
// ...(anon && { anon: { read: true } }),
// ...(recipientUris && {
// uri: recipientUris,
// read: true
// })
// },
// webId: 'system'
// },
// {
// meta: {
// skipObjectsWatcher
// }
// }
// );
// };

const addReadRights = async ({ ctx, recipientUris, resourceUri, skipObjectsWatcher, anon }) => {
if (recipientUris?.length === 0 && !anon) return;
Expand Down Expand Up @@ -91,12 +91,10 @@ const setRightsHandler = {
resourceUri: objectUri
});

const removedRecipients = previousRecipients.filter(r => !newRecipients.includes(r));
const addedRecipients = newRecipients.filter(r => !previousRecipients.includes(r));

// We add rights to all new recipients.
// ~~*And* if the object was private before, we send out a `Create` activity instead,
// by not skipping the objectWatcher that handles this.~~
const addedRecipients = newRecipients.filter(r => !previousRecipients.includes(r));
await addReadRights({
ctx,
resourceUri: objectUri,
Expand All @@ -108,14 +106,15 @@ const setRightsHandler = {
// We remove rights from all actors that aren't recipients anymore.
// *And* we do not skip the object-watcher middleware, to send `Delete` activities
// to actors that cannot see the object anymore.
if (removedRecipients.length > 0 || !activityIsPublic)
await removeReadRights({
ctx,
resourceUri: objectUri,
recipientUris: removedRecipients,
skipObjectsWatcher: false,
anon: !activityIsPublic
});
// const removedRecipients = previousRecipients.filter(r => !newRecipients.includes(r));
// if (removedRecipients.length > 0 || !activityIsPublic)
// await removeReadRights({
// ctx,
// resourceUri: objectUri,
// recipientUris: removedRecipients,
// skipObjectsWatcher: false,
// anon: !activityIsPublic
// });
}
}
};
Expand Down

0 comments on commit 3370bec

Please sign in to comment.