Skip to content
Snippets Groups Projects
Commit eaf04f71 authored by Simon Leipold's avatar Simon Leipold
Browse files

[Projekt: Entwicklung - Neon][TicketNr.: 1048382][Permission - Refactoring]

parent 92250d00
No related branches found
No related tags found
No related merge requests found
...@@ -206,15 +206,15 @@ function PermissionUtil () {} ...@@ -206,15 +206,15 @@ function PermissionUtil () {}
* *
* @param {String} [pEntityName] name of the entity, can be null * @param {String} [pEntityName] name of the entity, can be null
* *
* @param {String} [pRole] name of the role, can be null * @param {String} [pRoleName] name of the role, can be null
* *
* @result {Integer} returns number of permissions linked to the entity-role-combination. * @result {Integer} returns number of permissions linked to the entity-role-combination.
*/ */
PermissionUtil.getNumberOfPermissions = function(pEntityName, pRole) { PermissionUtil.getNumberOfPermissions = function(pEntityName, pRoleName) {
return newSelect("COUNT(*)", alias) return newSelect("COUNT(*)", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.whereIfSet("ASYS_PERMISSIONSET.ENTITY_ID", pEntityName) .whereIfSet("ASYS_PERMISSIONSET.ENTITY_ID", pEntityName)
.andIfSet("ASYS_PERMISSIONSET.ROLE_ID", pRole) .andIfSet("ASYS_PERMISSIONSET.ROLE_ID", pRoleName)
.cell(true, "0"); .cell(true, "0");
} }
...@@ -295,7 +295,7 @@ function PermissionUtil () {} ...@@ -295,7 +295,7 @@ function PermissionUtil () {}
/** /**
* Gets the permission set id of a given role-entity-accesstype-combination. * Gets the permission set id of a given role-entity-accesstype-combination.
* *
* @param {String} pRole name of the role * @param {String} pRoleName name of the role
* *
* @param {String} pEntity name of the entity * @param {String} pEntity name of the entity
* *
...@@ -305,11 +305,11 @@ function PermissionUtil () {} ...@@ -305,11 +305,11 @@ function PermissionUtil () {}
* *
* @result {String} returns id of the matching permission set. The result can never be null. * @result {String} returns id of the matching permission set. The result can never be null.
*/ */
PermissionUtil.getSet = function(pRole, pEntity, pAccessType, pField) { PermissionUtil.getSet = function(pRoleName, pEntity, pAccessType, pField) {
var query = newSelect("ASYS_PERMISSIONSETID", alias) var query = newSelect("ASYS_PERMISSIONSETID", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.where("ASYS_PERMISSIONSET.ROLE_ID", pRole) .where("ASYS_PERMISSIONSET.ROLE_ID", pRoleName)
.and("ASYS_PERMISSIONSET.ENTITY_ID", pEntity) .and("ASYS_PERMISSIONSET.ENTITY_ID", pEntity)
.and("ASYS_PERMISSIONSET.ACCESSTYPE", pAccessType); .and("ASYS_PERMISSIONSET.ACCESSTYPE", pAccessType);
...@@ -322,16 +322,16 @@ function PermissionUtil () {} ...@@ -322,16 +322,16 @@ function PermissionUtil () {}
/** /**
* Gets the root permission set of a entity-role-combination. * Gets the root permission set of a entity-role-combination.
* *
* @param {String} pRole id of a role * @param {String} pRoleName id of a role
* *
* @param {String} pEntity id of an entity * @param {String} pEntity id of an entity
* *
* @result {String} returns id of the root permission set of the given entity-role-combination. Never 'null', empty string if there is no result. * @result {String} returns id of the root permission set of the given entity-role-combination. Never 'null', empty string if there is no result.
*/ */
PermissionUtil.getSetRoot = function(pRole, pEntity) { PermissionUtil.getSetRoot = function(pRoleName, pEntity) {
return newSelect("ASYS_PERMISSIONSETID", alias) return newSelect("ASYS_PERMISSIONSETID", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.where("ASYS_PERMISSIONSET.ROLE_ID", pRole) .where("ASYS_PERMISSIONSET.ROLE_ID", pRoleName)
.and("ASYS_PERMISSIONSET.ENTITY_ID", pEntity) .and("ASYS_PERMISSIONSET.ENTITY_ID", pEntity)
.and("ASYS_PERMISSIONSET.ACCESSTYPE", "E") .and("ASYS_PERMISSIONSET.ACCESSTYPE", "E")
.cell(); .cell();
...@@ -417,7 +417,7 @@ function PermissionUtil () {} ...@@ -417,7 +417,7 @@ function PermissionUtil () {}
* *
* @param {String} pEntity entity to which the PermissionSet is linked, mandatory * @param {String} pEntity entity to which the PermissionSet is linked, mandatory
* *
* @param {String} pRole Role to which the PermissionSet is linked, mandatory * @param {String} pRoleName Name of the role to which the PermissionSet is linked, mandatory
* *
* @param {String} pField Field to which the PermissionSet is linked, empty if no field permission * @param {String} pField Field to which the PermissionSet is linked, empty if no field permission
* *
...@@ -425,7 +425,7 @@ function PermissionUtil () {} ...@@ -425,7 +425,7 @@ function PermissionUtil () {}
* *
* @result {Integer} returns id of the inserted permission set * @result {Integer} returns id of the inserted permission set
*/ */
PermissionUtil.insertSet = function(pParentPermSetId, pEntity, pRole, pField, pAccessType) { PermissionUtil.insertSet = function(pParentPermSetId, pEntity, pRoleName, pField, pAccessType) {
var table = "ASYS_PERMISSIONSET"; var table = "ASYS_PERMISSIONSET";
var cols = [ var cols = [
"FIELD_ID", "FIELD_ID",
...@@ -436,7 +436,7 @@ function PermissionUtil () {} ...@@ -436,7 +436,7 @@ function PermissionUtil () {}
"ENTITY_ID" "ENTITY_ID"
]; ];
var setId = util.getNewUUID(); var setId = util.getNewUUID();
var vals = [pField, pAccessType, pRole, setId, pParentPermSetId, pEntity]; var vals = [pField, pAccessType, pRoleName, setId, pParentPermSetId, pEntity];
db.insertData(table, cols, null, vals, alias); db.insertData(table, cols, null, vals, alias);
return setId; return setId;
} }
...@@ -562,7 +562,7 @@ function PermissionUtil () {} ...@@ -562,7 +562,7 @@ function PermissionUtil () {}
/** /**
* Returns permissionid of the permission with fitting parameters, otherwise returns empty string * Returns permissionid of the permission with fitting parameters, otherwise returns empty string
* *
* @param {String} pRole name of the role * @param {String} pRoleName name of the role
* *
* @param {String} pEntity name of the entity * @param {String} pEntity name of the entity
* *
...@@ -577,12 +577,12 @@ function PermissionUtil () {} ...@@ -577,12 +577,12 @@ function PermissionUtil () {}
* @result {String} Returns the id of the permission with fitting parameters, otherwise returns empty string, can never be null * @result {String} Returns the id of the permission with fitting parameters, otherwise returns empty string, can never be null
* *
*/ */
PermissionUtil.getPermission = function(pRole, pEntity, pField, pAccesstype, pCondition, pCondtype) { PermissionUtil.getPermission = function(pRoleName, pEntity, pField, pAccesstype, pCondition, pCondtype) {
var permissionSelect = newSelect("ASYS_PERMISSION.ASYS_PERMISSIONID", alias) var permissionSelect = newSelect("ASYS_PERMISSION.ASYS_PERMISSIONID", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.join("ASYS_PERMISSION", "ASYS_PERMISSION.ASYS_PERMISSIONSET_ID = ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID") .join("ASYS_PERMISSION", "ASYS_PERMISSION.ASYS_PERMISSIONSET_ID = ASYS_PERMISSIONSET.ASYS_PERMISSIONSETID")
.where("ASYS_PERMISSIONSET.ENTITY_ID", pEntity) .where("ASYS_PERMISSIONSET.ENTITY_ID", pEntity)
.and("ASYS_PERMISSIONSET.ROLE_ID", pRole) .and("ASYS_PERMISSIONSET.ROLE_ID", pRoleName)
.and("ASYS_PERMISSIONSET.ACCESSTYPE", pAccesstype) .and("ASYS_PERMISSIONSET.ACCESSTYPE", pAccesstype)
var emptyCond = PermissionUtil.getEmptyCondString(pEntity); var emptyCond = PermissionUtil.getEmptyCondString(pEntity);
...@@ -702,40 +702,40 @@ function PermissionUtil () {} ...@@ -702,40 +702,40 @@ function PermissionUtil () {}
} }
/** /**
* Delete all links to child roles of pRole. * Delete all links to child roles of pRoleName.
* *
* @param {String} pRole role which should be deleted, mandatory * @param {String} pRoleName role which should be deleted, mandatory
* *
* @result {Integer} returns number of deleted records * @result {Integer} returns number of deleted records
*/ */
PermissionUtil.removeParentRoleLinks = function(pRole) { PermissionUtil.removeParentRoleLinks = function(pRoleName) {
return newWhereIfSet("ASYS_ROLES_CHILDREN.PARENT_ROLE", pRole, undefined, undefined, alias) return newWhereIfSet("ASYS_ROLES_CHILDREN.PARENT_ROLE", pRoleName, undefined, undefined, alias)
.deleteData(true, "ASYS_ROLES_CHILDREN"); .deleteData(true, "ASYS_ROLES_CHILDREN");
} }
/** /**
* Delete all links to parent roles of pRole. * Delete all links to parent roles of pRoleName.
* *
* @param {String} pRole role which should be deleted, mandatory * @param {String} pRoleName role which should be deleted, mandatory
* *
* @result {Integer} returns number of deleted records * @result {Integer} returns number of deleted records
*/ */
PermissionUtil.removeChildRoleLinks = function(pRole) { PermissionUtil.removeChildRoleLinks = function(pRoleName) {
return newWhereIfSet("ASYS_ROLES_CHILDREN.CHILD_ROLE", pRole, undefined, undefined, alias) return newWhereIfSet("ASYS_ROLES_CHILDREN.CHILD_ROLE", pRoleName, undefined, undefined, alias)
.deleteData(true, "ASYS_ROLES_CHILDREN"); .deleteData(true, "ASYS_ROLES_CHILDREN");
} }
/** /**
* Removing all all links to parent roles. * Removing all all links to parent roles.
* *
* @param {String} pRole role which should be deleted, mandatory * @param {String} pRoleName role which should be deleted, mandatory
* *
* @result {Integer} returns number of deleted records * @result {Integer} returns number of deleted records
*/ */
PermissionUtil.removeHirarchyRoleLinks = function(pRole) { PermissionUtil.removeHirarchyRoleLinks = function(pRoleName) {
var affectedEntrys = 0; var affectedEntrys = 0;
affectedEntrys += this.removeParentRoleLinks(pRole); affectedEntrys += this.removeParentRoleLinks(pRoleName);
affectedEntrys += this.removeChildRoleLinks(pRole); affectedEntrys += this.removeChildRoleLinks(pRoleName);
return affectedEntrys; return affectedEntrys;
} }
...@@ -767,14 +767,14 @@ function PermissionUtil () {} ...@@ -767,14 +767,14 @@ function PermissionUtil () {}
/** /**
* Deletes all permissions sets, permissions and permission actions linked to a role. * Deletes all permissions sets, permissions and permission actions linked to a role.
* *
* @param {String} pRole name of the role, mandatory * @param {String} pRoleName name of the role, mandatory
* *
* @result {String} returns number of deleted entrys * @result {String} returns number of deleted entrys
*/ */
PermissionUtil.deleteEverythingLinkedToRole = function(pRole) { PermissionUtil.deleteEverythingLinkedToRole = function(pRoleName) {
var sets = newSelect("ASYS_PERMISSIONSETID", alias) var sets = newSelect("ASYS_PERMISSIONSETID", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.where("ASYS_PERMISSIONSET.ROLE_ID", pRole).arrayColumn(true); .where("ASYS_PERMISSIONSET.ROLE_ID", pRoleName).arrayColumn(true);
var perms = this.getPermissions(sets); var perms = this.getPermissions(sets);
var actions = this.getActions(perms); var actions = this.getActions(perms);
var affectedEntrys = 0; var affectedEntrys = 0;
...@@ -791,7 +791,7 @@ function PermissionUtil () {} ...@@ -791,7 +791,7 @@ function PermissionUtil () {}
affectedEntrys += this.deleteSet(set); affectedEntrys += this.deleteSet(set);
} }
affectedEntrys += this.removeHirarchyRoleLinks(pRole); affectedEntrys += this.removeHirarchyRoleLinks(pRoleName);
return affectedEntrys; return affectedEntrys;
} }
...@@ -799,15 +799,15 @@ function PermissionUtil () {} ...@@ -799,15 +799,15 @@ function PermissionUtil () {}
/** /**
* Checks if the given role is deletable. This includes checks for linked permissions and hierarchies. * Checks if the given role is deletable. This includes checks for linked permissions and hierarchies.
* *
* @param {String} pRole name of the role, mandatory * @param {String} pRoleName name of the role, mandatory
* *
* @result {Boolean} returns true if role is deletable, otherwise false * @result {Boolean} returns true if role is deletable, otherwise false
*/ */
PermissionUtil.roleIsDeletable = function(pRole) { PermissionUtil.roleIsDeletable = function(pRoleName) {
// check for linked permissions // check for linked permissions
var sets = newSelect("ASYS_PERMISSIONSETID", alias) var sets = newSelect("ASYS_PERMISSIONSETID", alias)
.from("ASYS_PERMISSIONSET") .from("ASYS_PERMISSIONSET")
.where("ASYS_PERMISSIONSET.ROLE_ID", pRole) .where("ASYS_PERMISSIONSET.ROLE_ID", pRoleName)
.arrayColumn(true); .arrayColumn(true);
var perms = this.getPermissions(sets); var perms = this.getPermissions(sets);
var actions = this.getActions(perms); var actions = this.getActions(perms);
...@@ -817,16 +817,16 @@ function PermissionUtil () {} ...@@ -817,16 +817,16 @@ function PermissionUtil () {}
} }
// check for linked hierarchies // check for linked hierarchies
// hierarchies where pRole is child // hierarchies where pRoleName is child
var parentHierarchies = newSelect("PARENT_ROLE", alias) var parentHierarchies = newSelect("PARENT_ROLE", alias)
.from("ASYS_ROLES_CHILDREN") .from("ASYS_ROLES_CHILDREN")
.where("ASYS_ROLES_CHILDREN.CHILD_ROLE", pRole) .where("ASYS_ROLES_CHILDREN.CHILD_ROLE", pRoleName)
.arrayColumn(true); .arrayColumn(true);
// hierarchies where pRole is parent // hierarchies where pRoleName is parent
var childHierarchies = newSelect("CHILD_ROLE", alias) var childHierarchies = newSelect("CHILD_ROLE", alias)
.from("ASYS_ROLES_CHILDREN") .from("ASYS_ROLES_CHILDREN")
.where("ASYS_ROLES_CHILDREN.PARENT_ROLE", pRole) .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", pRoleName)
.arrayColumn(true); .arrayColumn(true);
if (parentHierarchies.length != 0 || childHierarchies != 0) { if (parentHierarchies.length != 0 || childHierarchies != 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment