@live-change/access-control-service 0.8.121 → 0.8.123

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.
Files changed (2) hide show
  1. package/invite.js +78 -12
  2. package/package.json +3 -3
package/invite.js CHANGED
@@ -273,7 +273,7 @@ for(const contactType of config.contactTypes) {
273
273
  },
274
274
  access: (params, { client, context, visibilityTest}) =>
275
275
  visibilityTest || access.clientCanInvite(client, params),
276
- async execute(params, { client, service, trigger }, emit) {
276
+ async execute(params, { client, service, trigger }, emit) {
277
277
  const { [contactTypeName]: contact } = params
278
278
  const { objectType, object } = params
279
279
  const { roles } = params
@@ -315,12 +315,13 @@ for(const contactType of config.contactTypes) {
315
315
  ...invitationProperties
316
316
  },
317
317
  maxRetries: 1,
318
- async execute(params, { service, task }, emit) {
318
+ async execute(params, { service, task, trigger }, emit) {
319
319
  const { [contactTypeName]: contact } = params
320
320
  const { objectType, object } = params
321
321
  const { roles } = params
322
322
  const { fromType, from } = params
323
323
  const invitationData = { fromType, from, roles }
324
+ for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
324
325
  return await doInvite(contact, objectType, object, invitationData, emit, trigger)
325
326
  }
326
327
  }, definition)
@@ -353,19 +354,21 @@ for(const contactType of config.contactTypes) {
353
354
  }
354
355
  }
355
356
  },
356
- async execute(params, { service, task }, emit) {
357
- const { objectType, object } = params
358
- const { roles } = params
359
- const { fromType, from } = params
360
- const invitationData = { fromType, from, roles }
361
- for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
362
- for(const contact of params.contacts) {
357
+ async execute(params, { service, task, trigger }, emit) {
358
+ const contactsCount = params.contacts.length
359
+ for(let i = 0; i < contactsCount; i++) {
360
+ task.progress(i, contactsCount, 'inviting')
361
+ const contact = params.contacts[i]
363
362
  try {
364
- await doInvite(contact[contactTypeName], objectType, object, invitationData, emit, trigger)
363
+ task.run(inviteOneTask, {
364
+ ...params,
365
+ ...contact
366
+ })
365
367
  } catch(e) {
366
368
  // ignore errors
367
369
  }
368
370
  }
371
+ task.progress(contactsCount, contactsCount, 'done')
369
372
  }
370
373
  }, definition)
371
374
 
@@ -383,6 +386,7 @@ for(const contactType of config.contactTypes) {
383
386
  },
384
387
  ...invitationProperties,
385
388
  contacts: {
389
+ validation: ['nonEmpty'],
386
390
  type: Array,
387
391
  of: {
388
392
  type: Object,
@@ -393,7 +397,6 @@ for(const contactType of config.contactTypes) {
393
397
  access: (params, { client, context, visibilityTest}) =>
394
398
  visibilityTest || access.clientCanInvite(client, params),
395
399
  async execute(params, { client, service, trigger, command }, emit) {
396
- const { [contactTypeName]: contact } = params
397
400
  const { objectType, object } = params
398
401
 
399
402
  const myRoles = await access.getClientObjectRoles(client, { objectType, object }, true)
@@ -405,11 +408,74 @@ for(const contactType of config.contactTypes) {
405
408
 
406
409
  const [ fromType, from ] = client.user ? ['user_User', client.user] : ['session_Session', client.session]
407
410
 
408
- await inviteManyTask.start({
411
+ return await inviteManyTask.start({
412
+ ...params,
413
+ fromType, from,
414
+ ownerType: objectType,
415
+ owner: object,
416
+ }, 'action', command.id )
417
+ }
418
+ })
419
+
420
+ definition.action({
421
+ name: 'inviteMany' + pluralize(contactTypeUpperCaseName) + 'FromText',
422
+ waitForEvents: true,
423
+ properties: {
424
+ objectType: {
425
+ type: String,
426
+ validation: ['nonEmpty']
427
+ },
428
+ object: {
429
+ type: String,
430
+ validation: ['nonEmpty']
431
+ },
432
+ ...invitationProperties,
433
+ [pluralize(contactTypeName) + 'Text']: {
434
+ type: String,
435
+ validation: ['nonEmpty']
436
+ }
437
+ },
438
+ access: (params, { client, context, visibilityTest}) =>
439
+ visibilityTest || access.clientCanInvite(client, params),
440
+ async execute(params, { client, service, trigger, command }, emit) {
441
+ const fieldName = pluralize(contactTypeName) + 'Text'
442
+ const contacts = params[fieldName].split(/[,;\n]/).map(line => {
443
+ const parts = line.split('\t')
444
+ return parts[0].trim()
445
+ }).filter(x => !!x).map(contact => ({ [contactTypeName]: contact }))
446
+
447
+ if(contacts.length === 0) throw {
448
+ properties: { [fieldName]: 'empty' }
449
+ }
450
+ for(const contact of contacts) {
451
+ console.log("C", contact)
452
+ const error = service.definition.validators[contactTypeName]()(contact[contactTypeName], {
453
+ source: { properties: { [fieldName]: contact[contactTypeName] } }
454
+ })
455
+ if(error) throw {
456
+ properties: { [fieldName]: error }
457
+ }
458
+ }
459
+
460
+ const { objectType, object } = params
461
+
462
+ const myRoles = await access.getClientObjectRoles(
463
+ client, { objectType, object }, true
464
+ )
465
+ if(!myRoles.includes('admin')) {
466
+ for(const requestedRole of roles) {
467
+ if(!myRoles.includes(requestedRole)) throw 'notAuthorized'
468
+ }
469
+ }
470
+
471
+ const [ fromType, from ] = client.user ? ['user_User', client.user] : ['session_Session', client.session]
472
+
473
+ return await inviteManyTask.start({
409
474
  ...params,
410
475
  fromType, from,
411
476
  ownerType: objectType,
412
477
  owner: object,
478
+ contacts
413
479
  }, 'action', command.id )
414
480
  }
415
481
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/access-control-service",
3
- "version": "0.8.121",
3
+ "version": "0.8.123",
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.121"
24
+ "@live-change/framework": "^0.8.123"
25
25
  },
26
- "gitHead": "2fd79c450701fcfe3f69fa92276efd351eb57580",
26
+ "gitHead": "42148742342a5ac004deb122042ead1d977cb8f8",
27
27
  "type": "module"
28
28
  }