@live-change/access-control-service 0.8.118 → 0.8.119
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/invite.js +129 -45
- package/package.json +3 -3
package/invite.js
CHANGED
|
@@ -190,6 +190,9 @@ definition.action({
|
|
|
190
190
|
}
|
|
191
191
|
})
|
|
192
192
|
|
|
193
|
+
import task from '@live-change/task-service/task.js' // need to import taks.js to avoid circular dependency
|
|
194
|
+
|
|
195
|
+
|
|
193
196
|
for(const contactType of config.contactTypes) {
|
|
194
197
|
|
|
195
198
|
const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1)
|
|
@@ -206,6 +209,52 @@ for(const contactType of config.contactTypes) {
|
|
|
206
209
|
}
|
|
207
210
|
}
|
|
208
211
|
|
|
212
|
+
async function doInvite(contact, objectType, object, invitationData, emit, trigger = app.trigger) {
|
|
213
|
+
const contactData = await app.viewGet('get' + contactTypeUName, { [contactType]: contact })
|
|
214
|
+
if(contactData?.user) { // user exists
|
|
215
|
+
const { user } = contactData
|
|
216
|
+
await trigger({ type: 'notify' }, {
|
|
217
|
+
sessionOrUserType: 'user_User',
|
|
218
|
+
sessionOrUser: user,
|
|
219
|
+
notificationType: 'accessControl_Invitation',
|
|
220
|
+
objectType,
|
|
221
|
+
object,
|
|
222
|
+
...invitationData, id: undefined
|
|
223
|
+
})
|
|
224
|
+
emit({
|
|
225
|
+
type: 'userInvited',
|
|
226
|
+
user,
|
|
227
|
+
objectType, object,
|
|
228
|
+
...invitationData, id: undefined
|
|
229
|
+
})
|
|
230
|
+
return 'userInvited'
|
|
231
|
+
} else {
|
|
232
|
+
// Authenticate with message because we will create account later
|
|
233
|
+
const messageData = {
|
|
234
|
+
objectType, object,
|
|
235
|
+
...invitationData, id: undefined,
|
|
236
|
+
action: inviteMessageActionByObjectType[objectType] ?? 'inviteWithMessage'
|
|
237
|
+
}
|
|
238
|
+
await trigger({ type: 'authenticateWithMessage' }, {
|
|
239
|
+
contactType,
|
|
240
|
+
contact,
|
|
241
|
+
messageData,
|
|
242
|
+
action: 'inviteWithMessage',
|
|
243
|
+
actionProperties: { objectType, object },
|
|
244
|
+
targetPage: { name: 'accessControl:invitationAccepted', params: { objectType, object } },
|
|
245
|
+
fallbackPage: { name: 'accessControl:invitationFallback', params: { objectType, object } }
|
|
246
|
+
})
|
|
247
|
+
emit({
|
|
248
|
+
type: 'contactInvited',
|
|
249
|
+
contactType: contactTypeName + '_' + contactTypeUName,
|
|
250
|
+
contact,
|
|
251
|
+
objectType, object,
|
|
252
|
+
...invitationData, id: undefined
|
|
253
|
+
})
|
|
254
|
+
return 'contactInvited'
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
209
258
|
definition.action({
|
|
210
259
|
name: 'invite' + contactTypeUpperCaseName,
|
|
211
260
|
waitForEvents: true,
|
|
@@ -221,9 +270,9 @@ for(const contactType of config.contactTypes) {
|
|
|
221
270
|
...contactTypeProperties,
|
|
222
271
|
...invitationProperties
|
|
223
272
|
},
|
|
224
|
-
access: (params, { client, context, visibilityTest
|
|
273
|
+
access: (params, { client, context, visibilityTest}) =>
|
|
225
274
|
visibilityTest || access.clientCanInvite(client, params),
|
|
226
|
-
async execute(params, { client, service }, emit) {
|
|
275
|
+
async execute(params, { client, service, trigger }, emit) {
|
|
227
276
|
const { [contactTypeName]: contact } = params
|
|
228
277
|
const { objectType, object } = params
|
|
229
278
|
const { roles } = params
|
|
@@ -236,53 +285,88 @@ for(const contactType of config.contactTypes) {
|
|
|
236
285
|
}
|
|
237
286
|
|
|
238
287
|
const [ fromType, from ] = client.user ? ['user_User', client.user] : ['session_Session', client.session]
|
|
239
|
-
const invitationData = { fromType, from }
|
|
288
|
+
const invitationData = { fromType, from, roles }
|
|
240
289
|
for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
|
|
290
|
+
await doInvite(contact, objectType, object, invitationData, emit, trigger)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
const inviteOneTask = task({
|
|
295
|
+
name: "invite" + contactTypeUpperCaseName,
|
|
296
|
+
properties: {
|
|
297
|
+
objectType: {
|
|
298
|
+
type: String,
|
|
299
|
+
validation: ['nonEmpty']
|
|
300
|
+
},
|
|
301
|
+
object: {
|
|
302
|
+
type: String,
|
|
303
|
+
validation: ['nonEmpty']
|
|
304
|
+
},
|
|
305
|
+
fromType: {
|
|
306
|
+
type: String,
|
|
307
|
+
validation: ['nonEmpty']
|
|
308
|
+
},
|
|
309
|
+
from: {
|
|
310
|
+
type: String,
|
|
311
|
+
validation: ['nonEmpty']
|
|
312
|
+
},
|
|
313
|
+
...contactTypeProperties,
|
|
314
|
+
...invitationProperties
|
|
315
|
+
},
|
|
316
|
+
maxRetries: 1,
|
|
317
|
+
async execute(params, { service, task }, emit) {
|
|
318
|
+
const { [contactTypeName]: contact } = params
|
|
319
|
+
const { objectType, object } = params
|
|
320
|
+
const { roles } = params
|
|
321
|
+
const { fromType, from } = params
|
|
322
|
+
const invitationData = { fromType, from, roles }
|
|
323
|
+
return await doInvite(contact, objectType, object, invitationData, emit, trigger)
|
|
324
|
+
}
|
|
325
|
+
}, definition)
|
|
241
326
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
327
|
+
const inviteManyTask = task({
|
|
328
|
+
name: "inviteMany" + contactTypeUpperCaseName,
|
|
329
|
+
properties: {
|
|
330
|
+
objectType: {
|
|
331
|
+
type: String,
|
|
332
|
+
validation: ['nonEmpty']
|
|
333
|
+
},
|
|
334
|
+
object: {
|
|
335
|
+
type: String,
|
|
336
|
+
validation: ['nonEmpty']
|
|
337
|
+
},
|
|
338
|
+
fromType: {
|
|
339
|
+
type: String,
|
|
340
|
+
validation: ['nonEmpty']
|
|
341
|
+
},
|
|
342
|
+
from: {
|
|
343
|
+
type: String,
|
|
344
|
+
validation: ['nonEmpty']
|
|
345
|
+
},
|
|
346
|
+
...invitationProperties,
|
|
347
|
+
contacts: {
|
|
348
|
+
type: Array,
|
|
349
|
+
of: {
|
|
350
|
+
type: Object,
|
|
351
|
+
properties: contactTypeProperties
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
async execute(params, { service, task }, emit) {
|
|
356
|
+
const { objectType, object } = params
|
|
357
|
+
const { roles } = params
|
|
358
|
+
const { fromType, from } = params
|
|
359
|
+
const invitationData = { fromType, from, roles }
|
|
360
|
+
for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
|
|
361
|
+
for(const contact of params.contacts) {
|
|
362
|
+
try {
|
|
363
|
+
await doInvite(contact[contactTypeName], objectType, object, invitationData, emit, trigger)
|
|
364
|
+
} catch(e) {
|
|
365
|
+
// ignore errors
|
|
267
366
|
}
|
|
268
|
-
await service.trigger({ type: 'authenticateWithMessage' }, {
|
|
269
|
-
contactType,
|
|
270
|
-
contact,
|
|
271
|
-
messageData,
|
|
272
|
-
action: 'inviteWithMessage',
|
|
273
|
-
actionProperties: { objectType, object },
|
|
274
|
-
targetPage: { name: 'accessControl:invitationAccepted', params: { objectType, object } },
|
|
275
|
-
fallbackPage: { name: 'accessControl:invitationFallback', params: { objectType, object } }
|
|
276
|
-
})
|
|
277
|
-
emit({
|
|
278
|
-
type: 'contactInvited',
|
|
279
|
-
contactType: contactTypeName + '_' + contactTypeUName,
|
|
280
|
-
contact,
|
|
281
|
-
objectType, object,
|
|
282
|
-
...invitationData, id: undefined
|
|
283
|
-
})
|
|
284
367
|
}
|
|
285
368
|
}
|
|
286
|
-
})
|
|
369
|
+
}, definition)
|
|
370
|
+
|
|
287
371
|
|
|
288
372
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/access-control-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.119",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.8.
|
|
24
|
+
"@live-change/framework": "^0.8.119"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "1f0bb577d5bfe8b8d355775d7adbd73c789cd1d5",
|
|
27
27
|
"type": "module"
|
|
28
28
|
}
|