@live-change/relations-plugin 0.9.18 → 0.9.19

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 (3) hide show
  1. package/entity.js +7 -1
  2. package/package.json +3 -3
  3. package/utils.js +16 -0
package/entity.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  defineProperties, defineIndex,
3
- processModelsAnnotation, extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl
3
+ processModelsAnnotation, extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl,
4
+ includeAccessRoles
4
5
  } from './utils.js'
5
6
  import { fireChangeTriggers } from "./changeTriggers.js"
6
7
  import App from '@live-change/framework'
@@ -13,6 +14,7 @@ const annotation = 'entity'
13
14
 
14
15
  function entityAccessControl({service, modelName, modelPropertyName}, accessControl) {
15
16
  if(!accessControl) return undefined
17
+ if(Array.isArray(accessControl)) accessControl = { roles: accessControl }
16
18
  return {
17
19
  objects: p => [{ objectType: service.name + '_' + modelName, object: p[modelPropertyName]}],
18
20
  ...accessControl
@@ -367,6 +369,10 @@ export default function(service, app) {
367
369
 
368
370
  model.identifiers = [{ name: modelPropertyName, field: 'id' }]
369
371
  model.crud = {}
372
+ includeAccessRoles(model, [
373
+ config.readAccessControl, config.writeAccessControl,
374
+ config.createAccessControl, config.updateAccessControl, config.deleteAccessControl
375
+ ])
370
376
 
371
377
  function modelRuntime() {
372
378
  return service._runtime.models[modelName]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.9.18",
3
+ "version": "0.9.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.18",
25
+ "@live-change/framework": "^0.9.19",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "d7fd7ad0a0ea331caea9dc8385439b9c637525ed"
28
+ "gitHead": "ea1ba1df62d2efac97f43b31aa66b87ec465614a"
29
29
  }
package/utils.js CHANGED
@@ -229,3 +229,19 @@ export function defineParentDeleteTriggers(config, context) {
229
229
  export function defineParentCopyTriggers(config, context) {
230
230
  registerParentCopyTriggers(context, config)
231
231
  }
232
+
233
+ export function includeAccessRoles(model, access) {
234
+ if(!access) return
235
+ if(!model.accessRoles) model.accessRoles = []
236
+ if(typeof access === 'string' && !model.accessRoles.find(role => role === access)) {
237
+ model.accessRoles.push(access)
238
+ }
239
+ if(Array.isArray(access)) {
240
+ for(const element of access) {
241
+ includeAccessRoles(model, element)
242
+ }
243
+ }
244
+ if(access.roles) {
245
+ includeAccessRoles(model, access.roles)
246
+ }
247
+ }