Refactor permission handling to utilize hierarchy levels for access control across multiple API endpoints, enhancing permission validation logic in contracts, history, application, and user management.
This commit is contained in:
@@ -17,11 +17,13 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
|||||||
//default whereclause
|
//default whereclause
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
|
|
||||||
switch ($permission) {
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
case '4':
|
|
||||||
|
switch ($hierarchy_level) {
|
||||||
|
case '0':
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||||
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (4,5)';
|
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (4,5)';
|
||||||
break;
|
break;
|
||||||
@@ -29,7 +31,11 @@ switch ($permission) {
|
|||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (1,2,3)';
|
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
break;
|
break;
|
||||||
default:
|
case '3':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%';
|
||||||
|
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (1,2,3)';
|
$whereclause = 'WHERE c.accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
|||||||
//default whereclause
|
//default whereclause
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
|
|
||||||
switch ($permission) {
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
case '4':
|
|
||||||
|
switch ($hierarchy_level) {
|
||||||
|
case '0':
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||||
break;
|
break;
|
||||||
@@ -26,11 +28,16 @@ switch ($permission) {
|
|||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type9.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type9.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
break;
|
break;
|
||||||
default:
|
case '3':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.$soldto_search;
|
||||||
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//NEW ARRAY
|
//NEW ARRAY
|
||||||
$criterias = [];
|
$criterias = [];
|
||||||
$clause = '';
|
$clause = '';
|
||||||
|
|||||||
@@ -27,11 +27,13 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
|||||||
//default whereclause
|
//default whereclause
|
||||||
$whereclause = 'WHERE';
|
$whereclause = 'WHERE';
|
||||||
|
|
||||||
switch ($permission) {
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
case '4':
|
|
||||||
|
switch ($hierarchy_level) {
|
||||||
|
case '0':
|
||||||
$whereclause .= '';
|
$whereclause .= '';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||||
$whereclause = ' e.accounthierarchy like "'.$condition.'" AND ';
|
$whereclause = ' e.accounthierarchy like "'.$condition.'" AND ';
|
||||||
break;
|
break;
|
||||||
@@ -39,7 +41,11 @@ switch ($permission) {
|
|||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
$whereclause .= ' e.accounthierarchy like "'.$condition.'" AND ';
|
$whereclause .= ' e.accounthierarchy like "'.$condition.'" AND ';
|
||||||
break;
|
break;
|
||||||
default:
|
case '3':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%';
|
||||||
|
$whereclause .= ' e.accounthierarchy like "'.$condition.'" AND ';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
$whereclause .= ' e.accounthierarchy like "'.$condition.'" AND ';
|
$whereclause .= ' e.accounthierarchy like "'.$condition.'" AND ';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -17,11 +17,13 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
|||||||
//default whereclause
|
//default whereclause
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
|
|
||||||
switch ($permission) {
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
case '4':
|
|
||||||
|
switch ($hierarchy_level) {
|
||||||
|
case '0':
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (4,5)';
|
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (4,5)';
|
||||||
break;
|
break;
|
||||||
@@ -29,7 +31,11 @@ switch ($permission) {
|
|||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
break;
|
break;
|
||||||
default:
|
case '3':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%';
|
||||||
|
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
$whereclause = 'WHERE accounthierarchy like :condition AND u.view IN (1,2,3)';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} el
|
|||||||
|
|
||||||
//default whereclause
|
//default whereclause
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
|
|
||||||
switch ($permission) {
|
switch ($hierarchy_level) {
|
||||||
case '4':
|
case '0':
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___%';
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
$whereclause = 'WHERE e.accounthierarchy like :condition ';
|
||||||
break;
|
break;
|
||||||
@@ -26,11 +27,16 @@ switch ($permission) {
|
|||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type9.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type9.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
break;
|
break;
|
||||||
default:
|
case '3':
|
||||||
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.$soldto_search;
|
||||||
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||||
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
$whereclause = 'WHERE e.accounthierarchy like :condition AND (type = "'.$type1.'" or type = "'.$type2.'" or type = "'.$type3.'" or type = "'.$type14.'" or type = "'.$type16.'")';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//NEW ARRAY
|
//NEW ARRAY
|
||||||
$criterias = [];
|
$criterias = [];
|
||||||
$clause = '';
|
$clause = '';
|
||||||
|
|||||||
@@ -154,12 +154,15 @@ else {
|
|||||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||||
//RESET VIEW/PERMISSION BASED ON USER PERMISSION
|
//RESET VIEW/PERMISSION BASED ON USER PERMISSION
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++
|
//+++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
$hierarchy_level = getHierarchyLevel($partner);
|
||||||
|
|
||||||
if($post_content['view']){
|
if($post_content['view']){
|
||||||
switch ($permission) {
|
switch ($hierarchy_level) {
|
||||||
case '4':
|
case '0':
|
||||||
//ADMIN+ no override
|
//ADMIN+ no override
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '1':
|
||||||
//ADMINS cannot set ADMIN+ => reset to admin
|
//ADMINS cannot set ADMIN+ => reset to admin
|
||||||
$post_content['view'] = ($post_content['view'] == 5) ? 4 : $post_content['view'];
|
$post_content['view'] = ($post_content['view'] == 5) ? 4 : $post_content['view'];
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user