Update permission.php

This commit is contained in:
FusionPBX
2020-02-24 13:27:17 -07:00
committed by GitHub
parent 38a1e91400
commit 7c939a9301

View File

@@ -27,28 +27,66 @@
//define the permission class //define the permission class
class permission { class permission {
//delete the permissions
//delete the permissions //delete the permissions
function delete() { function delete() {
//get unprotected groups and their domain uuids (if any)
$sql = "select group_name, domain_uuid "; //get the $apps array from the installed apps from the core and mod directories
$sql .= "from v_groups "; $config_list = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_config.php");
$sql .= "where group_protected <> 'true' "; $x = 0;
$database = new database; foreach ($config_list as &$config_path) {
$result = $database->select($sql, null, 'all'); include($config_path);
if (is_array($result) && @sizeof($result) != 0) { $x++;
foreach($result as $row) { }
$unprotected_groups[$row['group_name']] = $row['domain_uuid'];
//restore default permissions
$x = 0;
foreach ($apps as $row) {
if (is_array($row['permissions']) && @sizeof($row['permissions']) != 0) {
foreach ($row['permissions'] as $permission) {
foreach ($permission['groups'] as $group_name) {
if (!in_array($group_name, $group_name_array)) {
$group_name_array[] = $group_name;
}
}
}
} }
} }
unset($sql, $result, $row); $group_names = "'".implode("','", $group_name_array)."'";
//delete unprotected system group permissions
$sql = "delete from v_group_permissions as p ";
$sql .= "where group_name in ( ";
$sql .= " select group_name ";
$sql .= " from v_groups ";
$sql .= " where group_protected <> 'true' ";
$sql .= " and group_name in (".$group_names.") ";
$sql .= ");";
$database = new database;
$result = $database->select($sql);
//get the group_permissons
/*
$sql = "select * from v_group_permissions as p ";
$sql .= "where group_name in ( ";
$sql .= " select group_name ";
$sql .= " from v_groups ";
$sql .= " where group_protected <> 'true' ";
$sql .= " and group_name in (".$group_names.") ";
$sql .= ");";
$database = new database;
$group_permissions = $database->select($sql, null, 'all');
*/
//delete unprotected group permissions //delete unprotected group permissions
if (is_array($unprotected_groups) && sizeof($unprotected_groups) > 0) { /*
if (is_array($group_permissions) && sizeof($group_permissions) > 0) {
$x = 0; $x = 0;
foreach ($unprotected_groups as $unprotected_group_name => $unprotected_domain_uuid) { foreach ($group_permissions as $row) {
//build delete array //build delete array
$array['group_permissions'][$x]['group_name'] = $unprotected_group_name; $array['group_permissions'][$x]['group_permission_uuid'] = $row['group_permission_uuid'];
$array['group_permissions'][$x]['domain_uuid'] = $unprotected_domain_uuid != '' ? $unprotected_domain_uuid : null; $array['group_permissions'][$x]['domain_uuid'] = ($row['domain_uuid'] != '') ? $row['domain_uuid'] : null;
$x++; $x++;
} }
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions //grant temporary permissions
@@ -64,6 +102,7 @@
$p->delete('group_permission_delete', 'temp'); $p->delete('group_permission_delete', 'temp');
} }
} }
*/
} }
//restore the permissions //restore the permissions
@@ -149,4 +188,4 @@
} }
?> ?>