Add linting rules
This commit is contained in:
1 parent
75a5a42296
commit
c702003c32
43 files changed
+705
-576
No files matched your search
+16
-13
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const expression = require("./expression");
|
||||
|
||||
const validators = {
|
||||
pass: require("./validators/pass"),
|
||||
test: require("./validators/test")
|
||||
@@ -16,17 +14,18 @@ class Authorizer {
|
||||
|
||||
hasAccess(resourceType, access) {
|
||||
const cacheKey = `${resourceType}-${access}`;
|
||||
if (cacheKey in this.hasAccessCache)
|
||||
return this.hasAccessCache[cacheKey];
|
||||
if (cacheKey in this.hasAccessCache) return this.hasAccessCache[cacheKey];
|
||||
|
||||
let has = false;
|
||||
for (let permissionSet of this.permissionSets) {
|
||||
for (let perm of permissionSet)
|
||||
if (perm[resourceType])
|
||||
for (const permissionSet of this.permissionSets) {
|
||||
for (const perm of permissionSet) {
|
||||
if (perm[resourceType]) {
|
||||
if (perm[resourceType].access >= access) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.hasAccessCache[cacheKey] = has;
|
||||
@@ -39,23 +38,26 @@ class Authorizer {
|
||||
|
||||
let funcs = {};
|
||||
|
||||
for (let permissionSet of this.permissionSets)
|
||||
for (let perm of permissionSet)
|
||||
for (const permissionSet of this.permissionSets) {
|
||||
for (const perm of permissionSet) {
|
||||
if (perm[resourceType]) {
|
||||
if (perm[resourceType].access >= 3) {
|
||||
if (perm[resourceType].validate)
|
||||
for (let [k, v] of Object.entries(perm[resourceType].validate))
|
||||
if (perm[resourceType].validate) {
|
||||
for (const [k, v] of Object.entries(perm[resourceType].validate))
|
||||
funcs[k] = v;
|
||||
}
|
||||
} else {
|
||||
funcs = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const validator = (mutationType, mutation, any) => {
|
||||
let valid = false;
|
||||
for (let [k, v] of Object.entries(funcs))
|
||||
for (const [k, v] of Object.entries(funcs)) {
|
||||
if (v) {
|
||||
let res = validators[k](
|
||||
const res = validators[k](
|
||||
resourceType,
|
||||
resource,
|
||||
mutationType,
|
||||
@@ -66,6 +68,7 @@ class Authorizer {
|
||||
if (res > 0) valid = true;
|
||||
else if (res < 0) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user