@live-change/access-control-service 0.2.33 → 0.2.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/access.js +6 -1
- package/invite.js +71 -26
- package/package.json +2 -2
package/access.js
CHANGED
|
@@ -28,6 +28,11 @@ module.exports = (definition) => {
|
|
|
28
28
|
return true
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
clientHasAnyAccess, clientHasAdminAccess,
|
|
33
|
+
clientCanInvite,
|
|
34
|
+
clientCanRequest,
|
|
35
|
+
clientHasAccessRole
|
|
36
|
+
}
|
|
32
37
|
|
|
33
38
|
}
|
package/invite.js
CHANGED
|
@@ -21,25 +21,33 @@ const Session = definition.foreignModel('session', 'Session')
|
|
|
21
21
|
|
|
22
22
|
definition.event({
|
|
23
23
|
name: 'userInvited',
|
|
24
|
-
async execute(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
async execute(params) {
|
|
25
|
+
const { user, objectType, object, fromType, from } = params
|
|
26
|
+
const contactOrUserType = 'user_User'
|
|
27
|
+
const contactOrUser = user
|
|
28
|
+
const data = {
|
|
29
|
+
id: App.encodeIdentifier([ contactOrUserType, contactOrUser, objectType, object ]),
|
|
30
|
+
contactOrUserType, contactOrUser,
|
|
31
|
+
objectType, object, fromType, from
|
|
32
|
+
}
|
|
33
|
+
for(const propertyName in invitationProperties) data[propertyName] = params[propertyName]
|
|
34
|
+
await AccessInvitation.create(data)
|
|
31
35
|
}
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
definition.event({
|
|
35
39
|
name: 'contactInvited',
|
|
36
|
-
async execute(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
async execute(params) {
|
|
41
|
+
const { contactType, contact, objectType, object, fromType, from } = params
|
|
42
|
+
const contactOrUserType = contactType
|
|
43
|
+
const contactOrUser = contact
|
|
44
|
+
const data = {
|
|
45
|
+
id: App.encodeIdentifier([ contactOrUserType, contactOrUser, objectType, object ]),
|
|
46
|
+
contactOrUserType, contactOrUser,
|
|
47
|
+
objectType, object, fromType, from
|
|
48
|
+
}
|
|
49
|
+
for(const propertyName in invitationProperties) data[propertyName] = params[propertyName]
|
|
50
|
+
await AccessInvitation.create(data)
|
|
43
51
|
}
|
|
44
52
|
})
|
|
45
53
|
|
|
@@ -61,7 +69,7 @@ definition.event({
|
|
|
61
69
|
})
|
|
62
70
|
|
|
63
71
|
definition.trigger({
|
|
64
|
-
name: '
|
|
72
|
+
name: 'contactOrUserOwnedAccessInvitationMoved',
|
|
65
73
|
properties: {
|
|
66
74
|
...contactProperties,
|
|
67
75
|
from: {
|
|
@@ -88,14 +96,24 @@ definition.trigger({
|
|
|
88
96
|
}
|
|
89
97
|
},
|
|
90
98
|
async execute({ from, to, objectType, object }, { service }, emit) {
|
|
99
|
+
const invitation = App.encodeIdentifier([from.contactOrUserType, from.contactOrUser, objectType, object])
|
|
100
|
+
const invitationData = await AccessInvitation.get(invitation)
|
|
101
|
+
console.error("MOVED!!!", {
|
|
102
|
+
...invitationData,
|
|
103
|
+
type: 'notify',
|
|
104
|
+
sessionOrUserType: 'user_User',
|
|
105
|
+
sessionOrUser: to.contactOrUser,
|
|
106
|
+
notificationType: 'accessControl_Invitation',
|
|
107
|
+
id: undefined
|
|
108
|
+
})
|
|
91
109
|
if(to.contactOrUserType == 'user_User') {
|
|
92
110
|
await service.trigger({
|
|
111
|
+
...invitationData,
|
|
93
112
|
type: 'notify',
|
|
94
113
|
sessionOrUserType: 'user_User',
|
|
95
114
|
sessionOrUser: to.contactOrUser,
|
|
96
115
|
notificationType: 'accessControl_Invitation',
|
|
97
|
-
|
|
98
|
-
object
|
|
116
|
+
id: undefined
|
|
99
117
|
})
|
|
100
118
|
}
|
|
101
119
|
}
|
|
@@ -141,6 +159,34 @@ definition.trigger({
|
|
|
141
159
|
}
|
|
142
160
|
})
|
|
143
161
|
|
|
162
|
+
definition.action({
|
|
163
|
+
name: 'acceptInvitation',
|
|
164
|
+
waitForEvents: true,
|
|
165
|
+
properties: {
|
|
166
|
+
objectType: {
|
|
167
|
+
type: String,
|
|
168
|
+
validation: ['nonEmpty']
|
|
169
|
+
},
|
|
170
|
+
object: {
|
|
171
|
+
type: String,
|
|
172
|
+
validation: ['nonEmpty']
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
async execute({ objectType, object }, {client, service}, emit) {
|
|
176
|
+
if(!client.user) throw 'not_authorized'
|
|
177
|
+
const user = client.user
|
|
178
|
+
const invitation = App.encodeIdentifier(['user_User', user, objectType, object])
|
|
179
|
+
const invitationData = await AccessInvitation.get(invitation)
|
|
180
|
+
console.log("INVITATION", invitation, invitationData)
|
|
181
|
+
if(!invitationData) throw 'not_found'
|
|
182
|
+
const { roles } = invitationData
|
|
183
|
+
emit({
|
|
184
|
+
type: 'userInvitationAccepted',
|
|
185
|
+
user, objectType, object, roles
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
|
|
144
190
|
for(const contactType of config.contactTypes) {
|
|
145
191
|
|
|
146
192
|
const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1)
|
|
@@ -175,9 +221,10 @@ for(const contactType of config.contactTypes) {
|
|
|
175
221
|
access: (params, { client, context, visibilityTest }) =>
|
|
176
222
|
visibilityTest || access.clientCanInvite(client, params),
|
|
177
223
|
async execute(params, { client, service }, emit) {
|
|
224
|
+
const [ fromType, from ] = client.user ? ['user_User', client.user] : ['session_Session', client.session]
|
|
178
225
|
const { [contactTypeName]: contact } = params
|
|
179
226
|
const { objectType, object } = params
|
|
180
|
-
const invitationData = { }
|
|
227
|
+
const invitationData = { fromType, from }
|
|
181
228
|
for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
|
|
182
229
|
|
|
183
230
|
const contactData = (await service.trigger({
|
|
@@ -192,22 +239,20 @@ for(const contactType of config.contactTypes) {
|
|
|
192
239
|
sessionOrUser: user,
|
|
193
240
|
notificationType: 'accessControl_Invitation',
|
|
194
241
|
objectType,
|
|
195
|
-
object
|
|
242
|
+
object,
|
|
243
|
+
...invitationData, id: undefined
|
|
196
244
|
})
|
|
197
245
|
emit({
|
|
198
246
|
type: 'userInvited',
|
|
199
247
|
user,
|
|
200
248
|
objectType, object,
|
|
201
|
-
...invitationData
|
|
249
|
+
...invitationData, id: undefined
|
|
202
250
|
})
|
|
203
251
|
} else {
|
|
204
252
|
// Authenticate with message because we will create account later
|
|
205
253
|
const messageData = {
|
|
206
|
-
fromType: client.user ? 'user_User' : 'session_Session',
|
|
207
|
-
from: client.user ?? client.session,
|
|
208
254
|
objectType, object,
|
|
209
|
-
|
|
210
|
-
message: params.message
|
|
255
|
+
...invitationData, id: undefined
|
|
211
256
|
}
|
|
212
257
|
await service.trigger({
|
|
213
258
|
type: 'authenticateWithMessage',
|
|
@@ -223,10 +268,10 @@ for(const contactType of config.contactTypes) {
|
|
|
223
268
|
contactType: contactTypeName + '_' + contactTypeUName,
|
|
224
269
|
contact,
|
|
225
270
|
objectType, object,
|
|
226
|
-
...invitationData
|
|
271
|
+
...invitationData, id: undefined
|
|
227
272
|
})
|
|
228
273
|
}
|
|
229
274
|
}
|
|
230
275
|
})
|
|
231
276
|
|
|
232
|
-
}
|
|
277
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/access-control-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@live-change/framework": "0.6.5"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "f3bc615d20a0112c7cc76d55ba1cbefb53b84f01"
|
|
27
27
|
}
|