Optimize permission defaults (#5323)

* Update permission.php
This commit is contained in:
agree
2020-06-26 09:58:00 -06:00
committed by GitHub
parent 39646284ea
commit f5a8a3b998
+16 -13
View File
@@ -121,6 +121,11 @@
//delete the group permissions //delete the group permissions
$this->delete(); $this->delete();
//get the remaining group permissions
$sql = "select permission_name, group_name from v_group_permissions ";
$database = new database;
$remianing_group_permissions = $database->select($sql, null, 'all');
//get the $apps array from the installed apps from the core and mod directories //get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php"); $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
@@ -150,20 +155,18 @@
} }
} }
} }
if (!$group_protected) { if (!$group_protected) {
//if the item uuid is not currently in the db then add it // check if the item is not currently in the db
$sql = "select count(*) from v_group_permissions "; $exists = false;
$sql .= "where permission_name = :permission_name "; foreach ($remianing_group_permissions as $i => $group_permission) {
$sql .= "and group_name = :group_name "; if ($group_permission['permission_name'] == $permission['name']) {
$parameters['permission_name'] = $permission['name']; if ($group_permission['group_name'] == $group_name) {
$parameters['group_name'] = $group_name; $exists = true;
break;
$database = new database; }
$num_rows = $database->select($sql, $parameters, 'column'); }
unset($sql, $parameters); }
if (!$exists) {
if ($num_rows == 0) {
//build default permissions insert array //build default permissions insert array
$array['group_permissions'][$x]['group_permission_uuid'] = uuid(); $array['group_permissions'][$x]['group_permission_uuid'] = uuid();
$array['group_permissions'][$x]['permission_name'] = $permission['name']; $array['group_permissions'][$x]['permission_name'] = $permission['name'];