HUGE REFACTOR / CLEANUP

if there is a issue it's probably something in here that was changed
This commit is contained in:
2021-09-28 20:19:44 +00:00
parent 51eddfede9
commit d0afdd9855
238 changed files with 3127 additions and 8614 deletions

View File

@@ -1,5 +1,3 @@
/* xeslint-disable */
import bizrolerights from "./biz-role-rights";
export default {
@@ -118,15 +116,9 @@ export default {
//DELETE = SAME AS CHANGE FOR NOW (There is no specific delete right for now though it's checked for by routes in Authorized.cs in case we want to add it in future as a separate right from create.)
//NOTE: biz rules can supersede this, this is just for general rights purposes, if an object has restrictive business rules they will take precedence every time.
let ret = this.defaultRightsObject();
const ret = this.defaultRightsObject();
//Get the type name from the type enum value
//de-lodash
// let typeName = window.$gz. _.findKey(window.$gz.type, function(o) {
// return o == aType;
// });
//my _.findKey replacement:
let typeName = undefined;
for (const [key, value] of Object.entries(window.$gz.type)) {
if (value == aType) {
@@ -136,7 +128,7 @@ export default {
}
//Get the AyaNova stock REQUIRED role rights for that object
let objectRoleRights = this.ROLE_RIGHTS[typeName];
const objectRoleRights = this.ROLE_RIGHTS[typeName];
if (!objectRoleRights) {
throw new Error(
`authorizationroles::getRights type ${aType} not found in roles collection`
@@ -144,11 +136,11 @@ export default {
}
//get the logged in user's role
let userRole = window.$gz.store.state.roles;
const userRole = window.$gz.store.state.roles;
//calculate the effective rights
//a non zero result of the bitwise calculation means true and zero means false so using !! to force it into a boolean value
//(contrary to some style guides that say !! is obscure but I say it saves a lot of typing)
let canChange = !!(userRole & objectRoleRights.Change);
const canChange = !!(userRole & objectRoleRights.Change);
//sometimes rights to read are false if change is true since change trumps read anyway so accordingly:
let canReadFullRecord = canChange;
if (!canReadFullRecord) {
@@ -167,7 +159,7 @@ export default {
// (i.e. grids, history etc, initialization of main menu etc)
//
canOpen(aType) {
let r = this.getRights(aType);
const r = this.getRights(aType);
//convention is change might be defined but not read so canOpen is true eitehr way
return r.change == true || r.read == true;
},
@@ -176,46 +168,7 @@ export default {
// (i.e. grids, history etc, initialization of main menu etc)
//
canChange(aType) {
let r = this.getRights(aType);
const r = this.getRights(aType);
return r.change == true;
}
};
/*
USING BITWISE OPERATORS CHEAT SHEET
//https://codeburst.io/using-javascript-bitwise-operators-in-real-life-f551a731ff5
// Test whether your bit number has a single attribute. '&' ensures
// an intersection between them.
if (myBitNumber & HAS_FOO1) {
// False, in this example
}
if (myBitNumber & HAS_FOO2) {
// True!
}
// Test whether your bit number has ANY of the specified attributes
if (myBitNumber & (HAS_FOO1 | HAS_FOO2)) {
// True!
}
if (myBitNumber & (HAS_FOO1 | HAS_FOO3)) {
// False
}
// Test whether your bit number contains ONLY the specified attributes
if (myBitNumber == (HAS_FOO2 | HAS_FOO4)) {
// True
}
if (myBitNumber == (HAS_FOO2 | HAS_FOO3 | HAS_FOO4)) {
// False
}
// Test whether your bit number contains ALL of the given
// attributes. This is slightly tricky: the union of ATTRIBUTES
// can't supersede `myBitNumber` alone, otherwise it contains a bit
// that `myBitNumber` doesn't.
if (myBitNumber == (myBitNumber | (HAS_FOO2 | HAS_FOO4))) {
// True
}
if (myBitNumber == (myBitNumber | (HAS_FOO2 | HAS_FOO3 | HAS_FOO4))) {
// False
}
*/