@live-change/access-control-service 0.2.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.
- package/access.js +19 -0
- package/definition.js +11 -0
- package/index.js +7 -0
- package/model.js +71 -0
- package/package.json +27 -0
package/access.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = (definition) => {
|
|
3
|
+
|
|
4
|
+
const Access = definition.foreignModel('access-control', 'Access')
|
|
5
|
+
const PublicAccess = definition.foreignModel('access-control', 'PublicAccess')
|
|
6
|
+
|
|
7
|
+
function clientHasAnyAccess(client, toType, toId) {
|
|
8
|
+
/// TODO: access control
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function clientHasAdminAccess(client, toType, toId) {
|
|
13
|
+
/// TODO: access control
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {clientHasAnyAccess, clientHasAdminAccess }
|
|
18
|
+
|
|
19
|
+
}
|
package/definition.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const app = require("@live-change/framework").app()
|
|
2
|
+
|
|
3
|
+
const relationsPlugin = require('@live-change/relations-plugin')
|
|
4
|
+
const userService = require('@live-change/user-service')
|
|
5
|
+
|
|
6
|
+
const definition = app.createServiceDefinition({
|
|
7
|
+
name: "accessControl",
|
|
8
|
+
use: [ relationsPlugin, userService ]
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
module.exports = definition
|
package/index.js
ADDED
package/model.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const definition = require('./definition.js')
|
|
2
|
+
const config = definition.config
|
|
3
|
+
const access = require('./access.js')(definition)
|
|
4
|
+
|
|
5
|
+
const Access = definition.model({
|
|
6
|
+
name: 'Access',
|
|
7
|
+
sessionOrUserItem: {
|
|
8
|
+
ownerReadAccess: () => true
|
|
9
|
+
},
|
|
10
|
+
itemOfAny: {
|
|
11
|
+
to: 'object',
|
|
12
|
+
readAccess: (params, { client, context, visibilityTest }) =>
|
|
13
|
+
visibilityTest || access.clientHasAnyAccess(client, params.ownerType, params.owner),
|
|
14
|
+
writeAccess: (params, { client, context, visibilityTest }) =>
|
|
15
|
+
visibilityTest || access.clientHasAdminAccess(client, params.ownerType, params.owner)
|
|
16
|
+
},
|
|
17
|
+
properties: {
|
|
18
|
+
role: {
|
|
19
|
+
type: String,
|
|
20
|
+
validation: ['nonEmpty']
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const PublicAccess = definition.model({
|
|
26
|
+
name: "PublicAccess",
|
|
27
|
+
propertyOfAny: {
|
|
28
|
+
to: 'object',
|
|
29
|
+
readAccess: (params, { client, context, visibilityTest }) =>
|
|
30
|
+
visibilityTest || access.clientHasAnyAccess(client, params.ownerType, params.owner),
|
|
31
|
+
writeAccess: (params, { client, context, visibilityTest }) =>
|
|
32
|
+
visibilityTest || access.clientHasAdminAccess(client, params.ownerType, params.owner)
|
|
33
|
+
},
|
|
34
|
+
properties: {
|
|
35
|
+
userRole: {
|
|
36
|
+
type: String,
|
|
37
|
+
validation: ['nonEmpty']
|
|
38
|
+
},
|
|
39
|
+
sessionRole: {
|
|
40
|
+
type: String,
|
|
41
|
+
validation: ['nonEmpty']
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
indexes: {
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const AccessRequest = definition.model({
|
|
49
|
+
name: 'AccessRequest',
|
|
50
|
+
sessionOrUserItem: {
|
|
51
|
+
},
|
|
52
|
+
itemOfAny: {
|
|
53
|
+
to: 'object',
|
|
54
|
+
readAccess: (params, { client, context, visibilityTest }) =>
|
|
55
|
+
visibilityTest || access.clientHasAdminAccess(client, params.ownerType, params.owner)
|
|
56
|
+
},
|
|
57
|
+
properties: {
|
|
58
|
+
role: {
|
|
59
|
+
type: String,
|
|
60
|
+
validation: ['nonEmpty']
|
|
61
|
+
},
|
|
62
|
+
message: {
|
|
63
|
+
type: String,
|
|
64
|
+
validation: []
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
indexes: {
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
module.exports = { Access, PublicAccess, AccessRequest }
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@live-change/access-control-service",
|
|
3
|
+
"version": "0.2.19",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "NODE_ENV=test tape tests/*"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-services.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/live-change/live-change-services/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-services",
|
|
18
|
+
"author": {
|
|
19
|
+
"email": "michal@laszczewski.pl",
|
|
20
|
+
"name": "Michał Łaszczewski",
|
|
21
|
+
"url": "https://www.viamage.com/"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@live-change/framework": "^0.5.7"
|
|
25
|
+
},
|
|
26
|
+
"gitHead": "c2833a9660374ee17dd3def99fd1cdf47f6b1531"
|
|
27
|
+
}
|