Files
raven-client/ayanova/src/api/authorizationroles.js
2019-04-25 20:04:42 +00:00

169 lines
6.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* eslint-disable */
import _ from "../libs/lodash.min.js";
import store from "../store";
import ayt from "./ayatype";
import rights from "./bizroles";
export default {
AYATYPE: ayt,
ROLE_RIGHTS: rights,
AUTHORIZATION_ROLES: {
///<summary>No role set</summary>
NoRole: 0,
///<summary>BizAdminLimited</summary>
BizAdminLimited: 1,
///<summary>BizAdminFull</summary>
BizAdminFull: 2,
///<summary>DispatchLimited</summary>
DispatchLimited: 4,
///<summary>DispatchFull</summary>
DispatchFull: 8,
///<summary>InventoryLimited</summary>
InventoryLimited: 16,
///<summary>InventoryFull</summary>
InventoryFull: 32,
///<summary>AccountingFull</summary>
AccountingFull: 64, //No limited role, not sure if there is a need
///<summary>TechLimited</summary>
TechLimited: 128,
///<summary>TechFull</summary>
TechFull: 256,
///<summary>SubContractorLimited</summary>
SubContractorLimited: 512,
///<summary>SubContractorFull</summary>
SubContractorFull: 1024,
///<summary>ClientLimited</summary>
ClientLimited: 2048,
///<summary>ClientFull</summary>
ClientFull: 4096,
///<summary>OpsAdminLimited</summary>
OpsAdminLimited: 8192,
///<summary>OpsAdminFull</summary>
OpsAdminFull: 16384
},
hasRole(role) {
if (!store.state.roles || store.state.roles === 0) {
return false;
}
return role === (store.state.roles & role);
},
/////////////////////////////////
//
//
getRights(vm, oType, ownerId) {
//NOTE: this is to mirror the functionality of BizRoles.cs where all rights by role are specified in server project
//any change there needs to be mirrored here
//from bizroles.cs:
//HOW THIS WORKS / WHATS EXPECTED
//Change = CREATE, RETRIEVE, UPDATE, DELETE - Full rights
//EditOwn = special subset of CHANGE: You can create and if it's one you created then you have rights to edit it or delete, but you can't edit ones others have created
//ReadFullRecord = You can read *all* the fields of the record, but can't modify it. Change is automatically checked for so only add different roles from change
//PICKLIST NOTE: this does not control getting a list of names for selection which is role independent because it's required for so much indirectly
//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.)
//TODO: get this working, then decompose it into several files to make it cleaner
var ret = {
change: false,
read: false,
delete: false
};
//Get the type name from the type enum value
var typeName = _.findKey(vm.$gztype, function(o) {
return o == oType;
});
//Get the AyaNova stock role rights for that object
var theRight = this.ROLE_RIGHTS[typeName];
//get the logged in user's role
var userRole = vm.$store.state.roles;
var isSelfOwned=ownerId==vm.$store.state.userId;
//calculate the effective rights taking into consideration self owned etc
role === (store.state.roles & role);
// Change: 34
//
// EditOwn: 256
//
// ReadFullRecord: 17
/**
*
* What to do:
* Object is to return ret fully set as per rights
*
* Look up AyaType key name from value (i.e. 2="Widget")
* Use the type key name to find the object in AYANOVA_RIGHTS by key name
* Error if not found of course
* Using the object found check if can do each thing in RET and return RET
*
* To check need to do just like HasRole, i.e. this: role === (store.state.roles & role);
*
* AyaNova7Import: Object { Change: 16384, EditOwn: 0, ReadFullRecord: 0 }
DataFilter: Object { Change: 2, EditOwn: 32767, ReadFullRecord: 32767 }
FormCustom: Object { Change: 2, EditOwn: 0, ReadFullRecord: 32767 }
JobOperations: Object { Change: 16384, EditOwn: 0, ReadFullRecord: 8195 }
License: Object { Change: 16386, EditOwn: 0, ReadFullRecord: 8193 }
Locale: Object { Change: 16386, EditOwn: 0, ReadFullRecord: 32767 }
LogFile: Object { Change: 0, EditOwn: 0, ReadFullRecord: 24576 }
Metrics: Object { Change: 0, EditOwn: 0, ReadFullRecord: 24576 }
ServerState: Object { Change: 16384, EditOwn: 0, ReadFullRecord: 32767 }
User: Object { Change: 2, EditOwn: 0, ReadFullRecord: 1 }
UserOptions: Object { Change: 2, EditOwn: 0, ReadFullRecord: 1 }
Widget: Object { Change: 34, EditOwn: 256, ReadFullRecord: 17 }
<prototype>: Object { … }
authorizationroles.js:72
userRole
"32767"
objType
2
*
*/
// switch (objType) {
// case ayatype.Widget:
// //WIDGET
// // Change = AuthorizationRoles.BizAdminFull | AuthorizationRoles.InventoryFull,
// // EditOwn = AuthorizationRoles.TechFull,
// // ReadFullRecord = AuthorizationRoles.BizAdminLimited | AuthorizationRoles.InventoryLimited
// ret.change =
// this.hasrole(this.AUTHORIZATION_ROLES.BizAdminFull) ||
// this.hasrole(this.AUTHORIZATION_ROLES.InventoryFull);
// ret.editOwn =
// objId == store.state.userId &&
// this.hasrole(this.AUTHORIZATION_ROLES.TechFull);
// ret.readFull =
// this.hasrole(this.AUTHORIZATION_ROLES.BizAdminLimited) ||
// this.hasRole(this.AUTHORIZATION_ROLES.InventoryLimited);
// ret.delete = ret.change || ret.editOwn;
// // ////////////////////////////////////////////////////////////
// break;
// default:
// throw new "authorizationroles::rights - not coded for object type "() +
// objType;
// }
return ret;
}
};
/*
{"User":{"Change":2,"EditOwn":0,"ReadFullRecord":1},"UserOptions":{"Change":2,"EditOwn":0,"ReadFullRecord":1},"Widget":{"Change":34,"EditOwn":256,"ReadFullRecord":17},"ServerState":{"Change":16384,"EditOwn":0,"ReadFullRecord":32767},"License":{"Change":16386,"EditOwn":0,"ReadFullRecord":8193},"LogFile":{"Change":0,"EditOwn":0,"ReadFullRecord":24576},"JobOperations":{"Change":16384,"EditOwn":0,"ReadFullRecord":8195},"AyaNova7Import":{"Change":16384,"EditOwn":0,"ReadFullRecord":0},"Metrics":{"Change":0,"EditOwn":0,"ReadFullRecord":24576},"Locale":{"Change":16386,"EditOwn":0,"ReadFullRecord":32767},"DataFilter":{"Change":2,"EditOwn":32767,"ReadFullRecord":32767},"FormCustom":{"Change":2,"EditOwn":0,"ReadFullRecord":32767}}
*/