Added permission checks for Buildings and terminations
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
|
||||
class Address extends mfBaseModel {
|
||||
protected $forcestr = ['street','company','zip','phone','fax','mobile','note'];
|
||||
private $parent;
|
||||
private $types;
|
||||
private $attributes;
|
||||
private $permissions;
|
||||
|
||||
|
||||
public function getFullName() {
|
||||
// Assumes "Firma1 Firma2" or "firstname lastname" as readable form
|
||||
@@ -28,17 +31,33 @@ class Address extends mfBaseModel {
|
||||
return $this->getFullName();
|
||||
}
|
||||
|
||||
private function loadAddresstypes() {
|
||||
|
||||
public function loadAddresstypes() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->types = AddresstypeModel::search(['address_id' => $this->id], true);
|
||||
if(!$this->parent_id) {
|
||||
$this->types = AddresstypeModel::search(['address_id' => $this->id], true);
|
||||
} else {
|
||||
// get types from parent
|
||||
|
||||
$parent = $this->getProperty("parent");
|
||||
$types = $parent->getProperty("types");
|
||||
$this->types = $types;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "types") {
|
||||
$this->loadAddresstypes();
|
||||
return $this->types;
|
||||
@@ -55,6 +74,16 @@ class Address extends mfBaseModel {
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
if($name == "permissions") {
|
||||
$this->permissions = NetworkAddressModel::search(['address_id' => $this->id]);
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
if($name == "parent") {
|
||||
$this->parent = new Address($this->parent_id);
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
@@ -95,10 +95,12 @@ class AddressModel {
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")");
|
||||
if($db->num_rows()) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Address($data);
|
||||
if(!array_key_exists("addresstype", $filter)) {
|
||||
$res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")");
|
||||
if($db->num_rows()) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Address($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class BuildingController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
if(!$me->is(["Admin", "netowner", "pipeplanner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,43 @@ class BuildingController extends mfBaseController {
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Building/Form");
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
|
||||
if($this->me->isAdmin()) {
|
||||
$this->layout()->set("networks", NetworkModel::getAll());
|
||||
$this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]])); // change to NetworkaddressModel
|
||||
$this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]])); // change to NetworkaddressModel
|
||||
} else {
|
||||
$this->layout()->set("networks", $this->me->my_networks);
|
||||
$pipeworkers = [];
|
||||
$lineworkers = [];
|
||||
foreach($this->me->my_networks as $network) {
|
||||
//var_dump($network->addresstypes);exit;
|
||||
if(is_array($network->addresstypes)) {
|
||||
foreach($network->getTypeAddresses("pipeworker") as $address) {
|
||||
if(!array_key_exists($address->id, $pipeworkers)) {
|
||||
$pipeworkers[$address->id] = $address;
|
||||
}
|
||||
}
|
||||
foreach($network->getTypeAddresses("lineworker") as $address) {
|
||||
if(!array_key_exists($address->id, $lineworkers)) {
|
||||
$lineworkers[$address->id] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->layout()->set("pipeworkers", $pipeworkers); // change to NetworkaddressModel
|
||||
$this->layout()->set("lineworkers", $lineworkers); // change to NetworkaddressModel
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->layout()->set("types", BuildingtypeModel::getAll());
|
||||
$this->layout()->set("statuses", BuildingstatusModel::getAll());
|
||||
$this->layout()->set("pipeworkers", AddressModel::search(["addresstype" => ["pipeworker"]]));
|
||||
$this->layout()->set("lineworkers", AddressModel::search(["addresstype" => ["lineworker"]]));
|
||||
|
||||
$this->layout()->set("networksections", NetworksectionModel::getAll());
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
@@ -71,7 +102,7 @@ class BuildingController extends mfBaseController {
|
||||
$data['network_id'] = $r->network_id;
|
||||
$data['pop_id'] = ($r->pop_id) ? $r->pop_id : null;
|
||||
$data['type_id'] = $r->type_id;
|
||||
$data['status_id'] = ($r->status_id) ? $r->status_id : null;
|
||||
$data['status_id'] = ($r->status_id) ? $r->status_id : 1;
|
||||
$data['pipeworker_id'] = ($r->pipeworker_id) ? $r->pipeworker_id : null;
|
||||
$data['lineworker_id'] = ($r->lineworker_id) ? $r->lineworker_id : null;
|
||||
$data['networksection_id'] = ($r->networksection_id) ? $r->networksection_id : null;
|
||||
@@ -98,7 +129,6 @@ class BuildingController extends mfBaseController {
|
||||
}
|
||||
|
||||
if($mode == "add") {
|
||||
$data['status_id'] = 1;
|
||||
$data['create_by'] = 1;
|
||||
$building = BuildingModel::create($data);
|
||||
} else {
|
||||
@@ -141,7 +171,8 @@ class BuildingController extends mfBaseController {
|
||||
}
|
||||
|
||||
// Anschlüsse anlegen
|
||||
if($building->units > 0) {
|
||||
|
||||
if(!$building->terminations && $building->units > 0) {
|
||||
for($i = 1; $i <= $building->units; $i++) {
|
||||
$data = [];
|
||||
$data['building_id'] = $building->id;
|
||||
|
||||
@@ -17,8 +17,11 @@ class DashboardController extends mfBaseController {
|
||||
|
||||
|
||||
protected function testAction() {
|
||||
$b = new Building(7);
|
||||
/*$b = new Building(7);
|
||||
var_dump($b->getNewObjectCode());exit;
|
||||
*/
|
||||
|
||||
$address = AddressModel::getOne(5);
|
||||
var_dump($address->types);exit;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,28 @@ class Network extends mfBaseModel {
|
||||
private $roles;
|
||||
private $sections;
|
||||
|
||||
|
||||
public function getTypeAddresses($search_type) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
$addresses = [];
|
||||
|
||||
$addresstypes = $this->getProperty("addresstypes");
|
||||
//var_dump($addresstypes);exit;
|
||||
foreach($addresstypes as $address_id => $atypes) {
|
||||
//var_dump($atypes);
|
||||
foreach($atypes as $atype) {
|
||||
//var_dump($atype);
|
||||
if($atype->type == $search_type && !array_key_exists($address_id, $addresses)) {
|
||||
$addresses[$address_id] = new Address($address_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
public function loadAddresstypes() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ class NetworkController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
if(!$me->is(["Admin", "netowner", "pipeplanner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class NetworksectionController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
if(!$me->is(["Admin", "netowner", "pipeplanner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,13 @@ class OrderProductModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("termination_id", $filter)) {
|
||||
$termination_id = $filter['termination_id'];
|
||||
if(is_numeric($termination_id)) {
|
||||
$where .= " AND termination_id=$termination_id";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class PopController extends mfBaseController {
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->isAdmin()) {
|
||||
if(!$me->is(["Admin", "netowner", "pipeplanner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ class ProductModel {
|
||||
public $productgroup_id = null;
|
||||
public $producttech_id = null;
|
||||
public $price = null;
|
||||
public $price_setup = null;
|
||||
public $price_nne = null;
|
||||
public $price_nbe = null;
|
||||
public $billing_period = null;
|
||||
|
||||
@@ -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"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ class User extends mfBaseModel {
|
||||
public $permissions;
|
||||
public $flags;
|
||||
public $address;
|
||||
|
||||
private $my_networks;
|
||||
|
||||
public function init() {
|
||||
$this->table = "Worker";
|
||||
@@ -77,12 +79,27 @@ class User extends mfBaseModel {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
if(is_object($this->permissions) && property_exists($this->permissions, "is$what")) {
|
||||
return $this->permissions->{"is$what"};
|
||||
|
||||
if(!is_array($what)) {
|
||||
$what = [$what];
|
||||
}
|
||||
if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) {
|
||||
return ($this->address->types[$what]->id) ? true : false;
|
||||
|
||||
foreach($what as $w) {
|
||||
if(is_object($this->permissions) && property_exists($this->permissions, "is$w")) {
|
||||
if($this->permissions->{"is$w"} === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//var_dump($this->address->types);exit;
|
||||
if(is_object($this->address) && property_exists($this->address, "types") && is_array($this->address->types)) {
|
||||
if($this->address->types[$w]->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isAdmin() {
|
||||
@@ -96,4 +113,49 @@ class User extends mfBaseModel {
|
||||
public function __toString() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "my_networks") {
|
||||
$this->my_networks = $this->getMyNetworks();
|
||||
return $this->my_networks;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
|
||||
private function getMyNetworks() {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$my_networks = [];
|
||||
|
||||
$network_list = NetworkAddressModel::search(['address_id' => $this->address_id]);
|
||||
foreach($network_list as $n) {
|
||||
if(!array_key_exists($n->network_id, $my_networks)) {
|
||||
$my_networks[$n->network_id] = new Network($n->network_id);
|
||||
}
|
||||
}
|
||||
|
||||
return $my_networks;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ class UserController extends mfBaseController {
|
||||
|
||||
$addresses = AddressModel::getAll();
|
||||
$this->layout()->set("addresses", $addresses);
|
||||
|
||||
if($this->request->address_id) {
|
||||
$this->layout()->set("address_id", $this->request->address_id);
|
||||
}
|
||||
}
|
||||
|
||||
protected function editAction($request) {
|
||||
|
||||
Reference in New Issue
Block a user