forked from thieflord06/activitypods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.js
52 lines (48 loc) · 1.46 KB
/
location.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { getAnnouncesGroupUri } = require('@activitypods/announcer');
module.exports = {
name: 'events.location',
actions: {
async setNewRights(ctx) {
const { resourceUri, newData } = ctx.params;
// Give read right for the event's location (if it is set)
if (newData.location) {
await ctx.call('webacl.resource.addRights', {
resourceUri: newData.location,
additionalRights: {
group: {
uri: getAnnouncesGroupUri(resourceUri),
read: true,
},
},
webId: newData['dc:creator'],
});
}
},
async updateRights(ctx) {
const { resourceUri, newData, oldData } = ctx.params;
// If event location has changed, remove rights on old location and add them to new one
if (newData.location !== oldData.location) {
await ctx.call('webacl.resource.addRights', {
resourceUri: newData.location,
additionalRights: {
group: {
uri: getAnnouncesGroupUri(resourceUri),
read: true,
},
},
webId: newData['dc:creator'],
});
await ctx.call('webacl.resource.removeRights', {
resourceUri: oldData.location,
rights: {
group: {
uri: getAnnouncesGroupUri(resourceUri),
read: true,
},
},
webId: newData['dc:creator'],
});
}
},
},
};