Added permission checks for Buildings and terminations

This commit is contained in:
Frank Schubert
2021-08-05 20:11:15 +02:00
parent 4a74e15300
commit c06bb156c7
18 changed files with 246 additions and 91 deletions
@@ -71,7 +71,7 @@ class TerminationController extends mfBaseController {
protected function delete() {
if(!$this->me->is("Admin")) {
if(!$this->me->is(["Admin", "netowner", "pipeplanner"])) {
$this->layout()->setFlash("Keine Berechtigung", "error");
$this->redirect("Building");
}
@@ -91,6 +91,36 @@ class TerminationController extends mfBaseController {
$building_id = $term->building_id;
// if user is not admin, check if they have permission for this network
if(!$this->me->is("Admin")) {
$allowed = false;
$building = $term->building;
$network = $building->network;
foreach(["netowner", "pipeplanner"] as $type) {
$perms = $network->getTypeAddresses($type);
foreach($perms as $address_id => $perm) {
if($this->me->address_id != $address_id) {
continue;
}
$allowed = true;
}
}
if(!$allowed) {
$this->layout()->setFlash("Keine Berechtigung", "error");
$this->redirect("Building", "Index", [], "building=".$building_id);
}
}
// check for dependencies
if(OrderProductModel::search(["termination_id" => $id])) {
$this->layout()->setFlash("Anschluss kann nicht gelöscht werden, da abhängige Objekte gefunden wurden.", "error");
$this->redirect("Building", "Index", [], "building=".$building_id);
}
$term->delete();
$this->layout()->setFlash("Anschluss gelöscht", "success");
@@ -148,4 +178,4 @@ class TerminationController extends mfBaseController {
return ["msg" => "Saved successfully"];
}
}
}