@cocreate/authorize
Advanced tools
Comparing version 1.3.14 to 1.4.0
@@ -0,1 +1,16 @@ | ||
# [1.4.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.14...v1.4.0) (2023-08-16) | ||
### Bug Fixes | ||
* crud attributes renamed ([6c66db2](https://github.com/CoCreate-app/CoCreate-authorize/commit/6c66db2efd13914e1315df639335624cf75d433a)) | ||
* Refactored *-target to *-selector ([bc6e173](https://github.com/CoCreate-app/CoCreate-authorize/commit/bc6e173f053d8441c60d85382db0c277259b78ce)) | ||
* typo crud.sent updated to crud.send ([a705592](https://github.com/CoCreate-app/CoCreate-authorize/commit/a7055922b05c82be1f4786552c7df60c7e7ed11d)) | ||
* webpack.config and package.json make use of mode=production instead of process.env ([94334dc](https://github.com/CoCreate-app/CoCreate-authorize/commit/94334dc7ebfa724383c477eb6833eb9f6c3461e2)) | ||
### Features | ||
* name attribute and variable renamed to key ([e09073e](https://github.com/CoCreate-app/CoCreate-authorize/commit/e09073e69ab810d8fbd08b37ae955df324a0be72)) | ||
## [1.3.14](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.3.13...v1.3.14) (2023-06-14) | ||
@@ -2,0 +17,0 @@ |
@@ -7,4 +7,4 @@ module.exports = { | ||
{ | ||
"collection": "files", | ||
"document": { | ||
"array": "files", | ||
"object": { | ||
"_id": "637ca55150234ef1671ce324", | ||
@@ -11,0 +11,0 @@ "name": "index.html", |
{ | ||
"name": "@cocreate/authorize", | ||
"version": "1.3.14", | ||
"version": "1.4.0", | ||
"description": "A simple authorize component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"start": "npx webpack --config webpack.config.js", | ||
"build": "NODE_ENV=production npx webpack --config webpack.config.js", | ||
"build": "npx webpack --mode=production --config webpack.config.js", | ||
"dev": "npx webpack --config webpack.config.js --watch", | ||
@@ -49,5 +49,5 @@ "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); } }\"" | ||
"dependencies": { | ||
"@cocreate/crud-client": "^1.21.23", | ||
"@cocreate/utils": "^1.21.15" | ||
"@cocreate/crud-client": "^1.21.24", | ||
"@cocreate/utils": "^1.21.16" | ||
} | ||
} |
@@ -21,11 +21,11 @@ (function (root, factory) { | ||
if (isBrowser) { | ||
crud.listen('updateDocument', function (data) { | ||
crud.listen('update.object', function (data) { | ||
updatePermission(data) | ||
}); | ||
crud.listen('deleteDocument', function (data) { | ||
crud.listen('delete.object', function (data) { | ||
deletePermission(data) | ||
}); | ||
} else { | ||
process.on('changed-document', async (data) => { | ||
process.on('changed-object', async (data) => { | ||
updatePermission(data) | ||
@@ -36,6 +36,6 @@ }) | ||
async function updatePermission(data) { | ||
const { collection, document, organization_id } = data | ||
const { array, object, organization_id } = data | ||
if (collection === 'keys' && document) { | ||
let permission = document[0] | ||
if (array === 'keys' && object) { | ||
let permission = object[0] | ||
if (permission && permission.key && hasPermission(permission.key)) { | ||
@@ -49,6 +49,6 @@ let newPermission = await readPermisson(permission.key, organization_id) | ||
async function deletePermission(data) { | ||
const { collection, document, organization_id } = data | ||
const { array, object, organization_id } = data | ||
if (collection === 'keys' && document) { | ||
let permission = document[0] | ||
if (array === 'keys' && object) { | ||
let permission = object[0] | ||
if (permission && permission.key && hasPermission(permission.key)) { | ||
@@ -84,3 +84,3 @@ permissions.delete(permission.key) | ||
let request = { | ||
collection: 'keys', | ||
array: 'keys', | ||
organization_id, | ||
@@ -93,13 +93,13 @@ filter: { | ||
if (key) | ||
request.filter.query.push({ name: 'key', value: key, operator: '$eq' }) | ||
request.filter.query.push({ key: 'key', value: key, operator: '$eq' }) | ||
else | ||
request.filter.query.push({ name: 'default', value: true, operator: '$eq' }) | ||
request.filter.query.push({ key: 'default', value: true, operator: '$eq' }) | ||
let permission = await crud.readDocument(request) | ||
if (permission && permission.document && permission.document[0]) { | ||
permission = permission.document[0] | ||
let permission = await crud.send(request) | ||
if (permission && permission.object && permission.object[0]) { | ||
permission = permission.object[0] | ||
if (!permission.collections) { | ||
permission.collections = {}; | ||
if (!permission.arrays) { | ||
permission.arrays = {}; | ||
} | ||
@@ -116,6 +116,6 @@ | ||
delete request.request | ||
request.document = role_ids | ||
request.object = role_ids | ||
let roles = await crud.readDocument(request) | ||
roles = roles.document | ||
let roles = await crud.send(request) | ||
roles = roles.object | ||
@@ -171,3 +171,3 @@ permission = createPermissionObject(permission, roles) | ||
async function check(action, data, user_id) { | ||
async function check(data, user_id) { | ||
let permission = false | ||
@@ -177,3 +177,2 @@ if (user_id) { | ||
key: user_id, | ||
action, | ||
data | ||
@@ -185,3 +184,2 @@ }) | ||
key: data.key, | ||
action, | ||
data | ||
@@ -193,3 +191,4 @@ }) | ||
async function checkPermissionObject({ key, action, data }) { | ||
async function checkPermissionObject({ key, data }) { | ||
let action = data.method | ||
let { organization_id, filter, endPoint } = data | ||
@@ -344,3 +343,3 @@ if (!key || !organization_id) return false; | ||
if (dataValue['_id']) { | ||
if (authorized.document.includes(dataValue['_id'])) | ||
if (authorized.object.includes(dataValue['_id'])) | ||
checkKeys = true | ||
@@ -361,17 +360,17 @@ } | ||
async function checkFilter(authorized, data, key, unauthorize) { | ||
async function checkFilter(authorized, data, apikey, unauthorize) { | ||
if (data.filter && data.filter.query) { | ||
let name | ||
if (data.filter.type == 'document') | ||
name = '_id' | ||
else if (data.filter.type == 'collection') | ||
name = 'name' | ||
if (name) { | ||
for (let value of authorized[key]) { | ||
if (value[name]) | ||
value = value[name] | ||
let key | ||
if (data.filter.type == 'object') | ||
key = '_id' | ||
else if (data.filter.type == 'array') | ||
key = 'name' | ||
if (key) { | ||
for (let value of authorized[apikey]) { | ||
if (value[key]) | ||
value = value[key] | ||
if (unauthorize) | ||
data.filter.query.push({ name, value, operator: '$ne', logicalOperator: 'or' }) | ||
data.filter.query.push({ key, value, operator: '$ne', logicalOperator: 'or' }) | ||
else | ||
data.filter.query.push({ name, value, operator: '$eq', logicalOperator: 'or' }) | ||
data.filter.query.push({ key, value, operator: '$eq', logicalOperator: 'or' }) | ||
} | ||
@@ -378,0 +377,0 @@ if (!unauthorize) |
Sorry, the diff of this file is not supported yet
72663
373
Updated@cocreate/utils@^1.21.16