@cocreate/authorize 1.3.14 → 1.4.0
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/CHANGELOG.md +15 -0
- package/CoCreate.config.js +2 -2
- package/docs/index.html +8 -8
- package/package.json +4 -4
- package/src/index.js +36 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.14...v1.4.0) (2023-08-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* crud attributes renamed ([6c66db2](https://github.com/CoCreate-app/CoCreate-authorize/commit/6c66db2efd13914e1315df639335624cf75d433a))
|
|
7
|
+
* Refactored *-target to *-selector ([bc6e173](https://github.com/CoCreate-app/CoCreate-authorize/commit/bc6e173f053d8441c60d85382db0c277259b78ce))
|
|
8
|
+
* typo crud.sent updated to crud.send ([a705592](https://github.com/CoCreate-app/CoCreate-authorize/commit/a7055922b05c82be1f4786552c7df60c7e7ed11d))
|
|
9
|
+
* webpack.config and package.json make use of mode=production instead of process.env ([94334dc](https://github.com/CoCreate-app/CoCreate-authorize/commit/94334dc7ebfa724383c477eb6833eb9f6c3461e2))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* name attribute and variable renamed to key ([e09073e](https://github.com/CoCreate-app/CoCreate-authorize/commit/e09073e69ab810d8fbd08b37ae955df324a0be72))
|
|
15
|
+
|
|
1
16
|
## [1.3.14](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.13...v1.3.14) (2023-06-14)
|
|
2
17
|
|
|
3
18
|
|
package/CoCreate.config.js
CHANGED
package/docs/index.html
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
sizes="32x32"
|
|
12
12
|
href="https://cocreate.app/images/favicon.ico" />
|
|
13
13
|
<meta
|
|
14
|
-
|
|
14
|
+
key="description"
|
|
15
15
|
content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
|
|
16
16
|
<meta
|
|
17
|
-
|
|
17
|
+
key="keywords"
|
|
18
18
|
content="helper classes, utility classes, css framework, css library, inline style classes" />
|
|
19
19
|
<meta name="robots" content="index,follow" />
|
|
20
20
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
</head>
|
|
29
29
|
|
|
30
30
|
<body>
|
|
31
|
-
<div
|
|
31
|
+
<div array="" object="" key="" id="cocreate-authorize">
|
|
32
32
|
<div
|
|
33
33
|
class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
|
|
34
34
|
<div class="display:flex align-items:center">
|
|
@@ -153,9 +153,9 @@
|
|
|
153
153
|
<textarea
|
|
154
154
|
type="code"
|
|
155
155
|
lang="html"
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
array="demos"
|
|
157
|
+
object=""
|
|
158
|
+
key="demo"
|
|
159
159
|
save="false"
|
|
160
160
|
id="demo"
|
|
161
161
|
class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
show="#eye-slash"
|
|
179
179
|
hide="#eye, #demo-preview"
|
|
180
180
|
toggle="code-height"
|
|
181
|
-
toggle-
|
|
181
|
+
toggle-selector="#demo-code"
|
|
182
182
|
><i class="far fa-eye"></i
|
|
183
183
|
></a>
|
|
184
184
|
<a
|
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
show="#eye, #demo-preview"
|
|
189
189
|
hide="#eye-slash"
|
|
190
190
|
toggle="code-height"
|
|
191
|
-
toggle-
|
|
191
|
+
toggle-selector="#demo-code"
|
|
192
192
|
><i class="fas fa-eye-slash"></i
|
|
193
193
|
></a>
|
|
194
194
|
<a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/authorize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A simple authorize component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authorize",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"start": "npx webpack --config webpack.config.js",
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "npx webpack --mode=production --config webpack.config.js",
|
|
29
29
|
"dev": "npx webpack --config webpack.config.js --watch",
|
|
30
30
|
"postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\""
|
|
31
31
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"main": "./src/index.js",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@cocreate/crud-client": "^1.21.
|
|
49
|
-
"@cocreate/utils": "^1.21.
|
|
48
|
+
"@cocreate/crud-client": "^1.21.24",
|
|
49
|
+
"@cocreate/utils": "^1.21.16"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/index.js
CHANGED
|
@@ -18,24 +18,24 @@
|
|
|
18
18
|
const permissions = new Map()
|
|
19
19
|
|
|
20
20
|
if (isBrowser) {
|
|
21
|
-
crud.listen('
|
|
21
|
+
crud.listen('update.object', function (data) {
|
|
22
22
|
updatePermission(data)
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
crud.listen('
|
|
25
|
+
crud.listen('delete.object', function (data) {
|
|
26
26
|
deletePermission(data)
|
|
27
27
|
});
|
|
28
28
|
} else {
|
|
29
|
-
process.on('changed-
|
|
29
|
+
process.on('changed-object', async (data) => {
|
|
30
30
|
updatePermission(data)
|
|
31
31
|
})
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async function updatePermission(data) {
|
|
35
|
-
const {
|
|
35
|
+
const { array, object, organization_id } = data
|
|
36
36
|
|
|
37
|
-
if (
|
|
38
|
-
let permission =
|
|
37
|
+
if (array === 'keys' && object) {
|
|
38
|
+
let permission = object[0]
|
|
39
39
|
if (permission && permission.key && hasPermission(permission.key)) {
|
|
40
40
|
let newPermission = await readPermisson(permission.key, organization_id)
|
|
41
41
|
setPermission(permission.key, newPermission)
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async function deletePermission(data) {
|
|
47
|
-
const {
|
|
47
|
+
const { array, object, organization_id } = data
|
|
48
48
|
|
|
49
|
-
if (
|
|
50
|
-
let permission =
|
|
49
|
+
if (array === 'keys' && object) {
|
|
50
|
+
let permission = object[0]
|
|
51
51
|
if (permission && permission.key && hasPermission(permission.key)) {
|
|
52
52
|
permissions.delete(permission.key)
|
|
53
53
|
}
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
return null;
|
|
79
79
|
|
|
80
80
|
let request = {
|
|
81
|
-
|
|
81
|
+
array: 'keys',
|
|
82
82
|
organization_id,
|
|
83
83
|
filter: {
|
|
84
84
|
query: []
|
|
@@ -86,17 +86,17 @@
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (key)
|
|
89
|
-
request.filter.query.push({
|
|
89
|
+
request.filter.query.push({ key: 'key', value: key, operator: '$eq' })
|
|
90
90
|
else
|
|
91
|
-
request.filter.query.push({
|
|
91
|
+
request.filter.query.push({ key: 'default', value: true, operator: '$eq' })
|
|
92
92
|
|
|
93
93
|
|
|
94
|
-
let permission = await crud.
|
|
95
|
-
if (permission && permission.
|
|
96
|
-
permission = permission.
|
|
94
|
+
let permission = await crud.send(request)
|
|
95
|
+
if (permission && permission.object && permission.object[0]) {
|
|
96
|
+
permission = permission.object[0]
|
|
97
97
|
|
|
98
|
-
if (!permission.
|
|
99
|
-
permission.
|
|
98
|
+
if (!permission.arrays) {
|
|
99
|
+
permission.arrays = {};
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
if (permission && permission.roles) {
|
|
@@ -108,10 +108,10 @@
|
|
|
108
108
|
|
|
109
109
|
delete request.filter
|
|
110
110
|
delete request.request
|
|
111
|
-
request.
|
|
111
|
+
request.object = role_ids
|
|
112
112
|
|
|
113
|
-
let roles = await crud.
|
|
114
|
-
roles = roles.
|
|
113
|
+
let roles = await crud.send(request)
|
|
114
|
+
roles = roles.object
|
|
115
115
|
|
|
116
116
|
permission = createPermissionObject(permission, roles)
|
|
117
117
|
}
|
|
@@ -162,26 +162,25 @@
|
|
|
162
162
|
return permission;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
async function check(
|
|
165
|
+
async function check(data, user_id) {
|
|
166
166
|
let permission = false
|
|
167
167
|
if (user_id) {
|
|
168
168
|
permission = await checkPermissionObject({
|
|
169
169
|
key: user_id,
|
|
170
|
-
action,
|
|
171
170
|
data
|
|
172
171
|
})
|
|
173
172
|
}
|
|
174
173
|
if (!permission || permission.error) {
|
|
175
174
|
permission = await checkPermissionObject({
|
|
176
175
|
key: data.key,
|
|
177
|
-
action,
|
|
178
176
|
data
|
|
179
177
|
})
|
|
180
178
|
}
|
|
181
179
|
return permission;
|
|
182
180
|
}
|
|
183
181
|
|
|
184
|
-
async function checkPermissionObject({ key,
|
|
182
|
+
async function checkPermissionObject({ key, data }) {
|
|
183
|
+
let action = data.method
|
|
185
184
|
let { organization_id, filter, endPoint } = data
|
|
186
185
|
if (!key || !organization_id) return false;
|
|
187
186
|
|
|
@@ -331,7 +330,7 @@
|
|
|
331
330
|
} else if (typeof dataValue === "object") {
|
|
332
331
|
let checkKeys = true
|
|
333
332
|
if (dataValue['_id']) {
|
|
334
|
-
if (authorized.
|
|
333
|
+
if (authorized.object.includes(dataValue['_id']))
|
|
335
334
|
checkKeys = true
|
|
336
335
|
}
|
|
337
336
|
if (checkKeys) {
|
|
@@ -347,21 +346,21 @@
|
|
|
347
346
|
return keyStatus
|
|
348
347
|
}
|
|
349
348
|
|
|
350
|
-
async function checkFilter(authorized, data,
|
|
349
|
+
async function checkFilter(authorized, data, apikey, unauthorize) {
|
|
351
350
|
if (data.filter && data.filter.query) {
|
|
352
|
-
let
|
|
353
|
-
if (data.filter.type == '
|
|
354
|
-
|
|
355
|
-
else if (data.filter.type == '
|
|
356
|
-
|
|
357
|
-
if (
|
|
358
|
-
for (let value of authorized[
|
|
359
|
-
if (value[
|
|
360
|
-
value = value[
|
|
351
|
+
let key
|
|
352
|
+
if (data.filter.type == 'object')
|
|
353
|
+
key = '_id'
|
|
354
|
+
else if (data.filter.type == 'array')
|
|
355
|
+
key = 'name'
|
|
356
|
+
if (key) {
|
|
357
|
+
for (let value of authorized[apikey]) {
|
|
358
|
+
if (value[key])
|
|
359
|
+
value = value[key]
|
|
361
360
|
if (unauthorize)
|
|
362
|
-
data.filter.query.push({
|
|
361
|
+
data.filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' })
|
|
363
362
|
else
|
|
364
|
-
data.filter.query.push({
|
|
363
|
+
data.filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' })
|
|
365
364
|
}
|
|
366
365
|
if (!unauthorize)
|
|
367
366
|
return true
|