@cocreate/authorize 1.11.0 → 1.12.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 +7 -0
- package/package.json +1 -1
- package/src/index.js +14 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.12.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.11.0...v1.12.0) (2023-12-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* use dotNotation for merging keys ([ac1177a](https://github.com/CoCreate-app/CoCreate-authorize/commit/ac1177a7445060ab679a3922bbfe544c11d807dc))
|
|
7
|
+
|
|
1
8
|
# [1.11.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.10.0...v1.11.0) (2023-11-25)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -109,7 +109,9 @@
|
|
|
109
109
|
let roles = await crud.send(request)
|
|
110
110
|
roles = roles.object
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
for (let role of roles) {
|
|
113
|
+
authorization = dotNotationToObject(authorization, role)
|
|
114
|
+
}
|
|
113
115
|
}
|
|
114
116
|
return authorization;
|
|
115
117
|
} else
|
|
@@ -121,41 +123,6 @@
|
|
|
121
123
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
async function createAuthorization(authorization, roles) {
|
|
125
|
-
roles.map(role => {
|
|
126
|
-
for (const roleKey in role) {
|
|
127
|
-
if (!["_id", "type", "name", "organization_id"].includes(roleKey)) {
|
|
128
|
-
if (!authorization[roleKey]) {
|
|
129
|
-
authorization[roleKey] = role[roleKey]
|
|
130
|
-
} else {
|
|
131
|
-
if (Array.isArray(role[roleKey])) {
|
|
132
|
-
for (let item of role[roleKey]) {
|
|
133
|
-
if (!authorization[roleKey].includes(item))
|
|
134
|
-
authorization[roleKey].push(item)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (typeof role[roleKey] == 'object') {
|
|
138
|
-
for (const c of Object.keys(role[roleKey])) {
|
|
139
|
-
if (!authorization[roleKey][c]) {
|
|
140
|
-
authorization[roleKey][c] = role[roleKey][c]
|
|
141
|
-
} else {
|
|
142
|
-
if (typeof role[roleKey][c] == 'object') {
|
|
143
|
-
authorization[roleKey][c] = { ...authorization[roleKey][c], ...role[roleKey][c] }
|
|
144
|
-
} else {
|
|
145
|
-
authorization[roleKey][c] = role[roleKey][c]
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
authorization[roleKey] = role[roleKey]
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
return authorization;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
126
|
async function check(data, user_id) {
|
|
160
127
|
let authorization = false
|
|
161
128
|
if (user_id) {
|
|
@@ -277,6 +244,17 @@
|
|
|
277
244
|
data.$filter.query.push(query)
|
|
278
245
|
|
|
279
246
|
} else {
|
|
247
|
+
if (key === '$array' && value === 'questions') {
|
|
248
|
+
if (typeof data.array === 'string') {
|
|
249
|
+
if (typeof value === 'string') {
|
|
250
|
+
return data.array === value
|
|
251
|
+
} else if (Array.isArray(value)) {
|
|
252
|
+
return value.includes(data.array)
|
|
253
|
+
}
|
|
254
|
+
} else if (Array.isArray(data.array)) {
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
}
|
|
280
258
|
// TODO: sanitize data by removing items user does not have access to.
|
|
281
259
|
// console.log('key is a query operator', key)
|
|
282
260
|
}
|