@cocreate/authorize
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -0,1 +1,8 @@ | ||
# [1.12.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.11.0...v1.12.0) (2023-12-21) | ||
### Features | ||
* use dotNotation for merging keys ([ac1177a](https://github.com/CoCreate-app/CoCreate-authorize/commit/ac1177a7445060ab679a3922bbfe544c11d807dc)) | ||
# [1.11.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.10.0...v1.11.0) (2023-11-25) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@cocreate/authorize", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "A simple authorize component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -112,3 +112,5 @@ (function (root, factory) { | ||
authorization = await createAuthorization(authorization, roles) | ||
for (let role of roles) { | ||
authorization = dotNotationToObject(authorization, role) | ||
} | ||
} | ||
@@ -125,37 +127,2 @@ return authorization; | ||
async function createAuthorization(authorization, roles) { | ||
roles.map(role => { | ||
for (const roleKey in role) { | ||
if (!["_id", "type", "name", "organization_id"].includes(roleKey)) { | ||
if (!authorization[roleKey]) { | ||
authorization[roleKey] = role[roleKey] | ||
} else { | ||
if (Array.isArray(role[roleKey])) { | ||
for (let item of role[roleKey]) { | ||
if (!authorization[roleKey].includes(item)) | ||
authorization[roleKey].push(item) | ||
} | ||
} | ||
else if (typeof role[roleKey] == 'object') { | ||
for (const c of Object.keys(role[roleKey])) { | ||
if (!authorization[roleKey][c]) { | ||
authorization[roleKey][c] = role[roleKey][c] | ||
} else { | ||
if (typeof role[roleKey][c] == 'object') { | ||
authorization[roleKey][c] = { ...authorization[roleKey][c], ...role[roleKey][c] } | ||
} else { | ||
authorization[roleKey][c] = role[roleKey][c] | ||
} | ||
} | ||
} | ||
} else { | ||
authorization[roleKey] = role[roleKey] | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
return authorization; | ||
} | ||
async function check(data, user_id) { | ||
@@ -282,2 +249,13 @@ let authorization = false | ||
} else { | ||
if (key === '$array' && value === 'questions') { | ||
if (typeof data.array === 'string') { | ||
if (typeof value === 'string') { | ||
return data.array === value | ||
} else if (Array.isArray(value)) { | ||
return value.includes(data.array) | ||
} | ||
} else if (Array.isArray(data.array)) { | ||
} | ||
} | ||
// TODO: sanitize data by removing items user does not have access to. | ||
@@ -284,0 +262,0 @@ // console.log('key is a query operator', key) |
82528
300