From 528f3680d2683cb49f81c86e239f63daf83d3621 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 12 Jun 2025 10:01:01 +0200 Subject: [PATCH] added new permissions and changed handling of ADBWohneinheitController.php/duplicate --- Layout/default/AddressDB/Index.php | 3 ++ Layout/default/User/Form.php | 9 +++++ .../ADBWohneinheitController.php | 30 +++++++++++---- .../ADBWohneinheit/ADBWohneinheitModel.php | 37 +++++++++++++------ application/User/UserController.php | 1 + ...worker_permission_add_can_adb_extended.php | 30 +++++++++++++++ .../ADBWohneinheitDuplicate.js | 7 +--- 7 files changed, 91 insertions(+), 26 deletions(-) create mode 100644 db/migrations/20250612100000_worker_permission_add_can_adb_extended.php diff --git a/Layout/default/AddressDB/Index.php b/Layout/default/AddressDB/Index.php index cfce6d799..b57172f53 100644 --- a/Layout/default/AddressDB/Index.php +++ b/Layout/default/AddressDB/Index.php @@ -179,6 +179,9 @@ 1])?>">Filter zurücksetzen + can("ADBExtended")): ?> + "> Doppelte Homes + diff --git a/Layout/default/User/Form.php b/Layout/default/User/Form.php index 60bd27061..7aa8e27ce 100644 --- a/Layout/default/User/Form.php +++ b/Layout/default/User/Form.php @@ -449,6 +449,15 @@ $siteTitle = "Benutzer"; anzeigen + +
+
+ can("ADBExtended")) ? "checked='checked'" : ""?> /> + +
+

diff --git a/application/ADBWohneinheit/ADBWohneinheitController.php b/application/ADBWohneinheit/ADBWohneinheitController.php index 44a1f8161..1289a5e6e 100644 --- a/application/ADBWohneinheit/ADBWohneinheitController.php +++ b/application/ADBWohneinheit/ADBWohneinheitController.php @@ -186,9 +186,19 @@ class ADBWohneinheitController extends mfBaseController { } protected function duplicateAction() { - $duplicateHomes = array_merge(ADBWohneinheitModel::searchDuplicateExtref(), - ADBWohneinheitModel::searchDuplicateOAID(), - ADBWohneinheitModel::getRimoDeletedHomes() + // if me is not admin or netowner, redirect to dashboard + if(!$this->me->is("Admin") && !$this->me->can("ADBExtended")) { + $this->redirect("Dashboard"); + } + + $address_id = null; + if (!$this->me->is("Admin")) { + $address_id = $this->me->address->id; + } + + $duplicateHomes = array_merge(ADBWohneinheitModel::searchDuplicateExtref([], $address_id), + ADBWohneinheitModel::searchDuplicateOAID([], $address_id), + ADBWohneinheitModel::getRimoDeletedHomes([], $address_id) ); $ADBNetzgebiete = array_map(function($network) { @@ -198,10 +208,13 @@ class ADBWohneinheitController extends mfBaseController { ]; }, ADBNetzgebietModel::getAll()); - $filteredNetzgebiete = []; - foreach ($ADBNetzgebiete as $network) { - if (!strstr($network["text"], "SBIDI") && !strstr($network["text"], "Liezen")) { - $filteredNetzgebiete[] = $network; + $networkOwners = []; + foreach ($duplicateHomes as $home) { + if ($home['netzgebiet_owner'] && !in_array($home['netzgebiet_owner'], array_column($networkOwners, 'value'))) { + $networkOwners[] = [ + "value" => $home['netzgebiet_owner'], + "text" => $home['netzgebiet_owner'], + ]; } } @@ -214,7 +227,8 @@ class ADBWohneinheitController extends mfBaseController { ["text" => "Doppelte Homes", "href" => self::getUrl("ADBWohneinheit", "duplicate")], ], "DUPLICATE_HOMES" => $duplicateHomes, - "ADB_NETZGEBIETE" => $filteredNetzgebiete, + "ADB_NETZGEBIETE" => $ADBNetzgebiete, + "NETWORK_OWNERS" => $networkOwners, "IS_ADMIN" => $this->me->is("Admin"), ]; diff --git a/application/ADBWohneinheit/ADBWohneinheitModel.php b/application/ADBWohneinheit/ADBWohneinheitModel.php index f4aa5d092..b9c031b9f 100644 --- a/application/ADBWohneinheit/ADBWohneinheitModel.php +++ b/application/ADBWohneinheit/ADBWohneinheitModel.php @@ -292,15 +292,19 @@ class ADBWohneinheitModel { return $where; } - public static function searchDuplicateExtref($filter = []) { + public static function searchDuplicateExtref($filter = [], $network_owner = null) { $duplicates = []; $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link; $where = self::getSqlFilter($filter); - $sql = "SELECT Wohneinheit.extref, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name + if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'"; + + $sql = "SELECT Wohneinheit.extref, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner FROM Wohneinheit LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) - LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id) + LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id) + LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id) + LEFT JOIN thetool.Address ON (Network.owner_id = Address.id) WHERE $where AND Wohneinheit.extref IS NOT NULL AND Netzgebiet.name NOT LIKE 'SBIDI%' GROUP BY Wohneinheit.extref, Hausnummer.netzgebiet_id HAVING COUNT(*) > 1 @@ -310,12 +314,13 @@ class ADBWohneinheitModel { $duplicateExtrefs = []; while($data = $res->fetch_assoc()) { + if (!$data['netzgebiet_owner']) continue; // Skip if no owner is set $duplicateExtrefs[] = $data['extref']; $duplicates[$data['extref']] = [ "duplicateType" => "extref", 'extref' => $data['extref'], 'netzgebiet_id' => $data['netzgebiet_id'], - 'netzgebiet_owner' => strstr($data['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK', + 'netzgebiet_owner' => $data['netzgebiet_owner'], 'count' => $data['count'], 'homeData' => [] ]; @@ -354,16 +359,20 @@ class ADBWohneinheitModel { return array_values($duplicates); } - public static function searchDuplicateOAID($filter = []) { + public static function searchDuplicateOAID($filter = [], $network_owner = null) { $duplicates = []; $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link; $where = self::getSqlFilter($filter); - $sql = "SELECT Wohneinheit.oaid, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name + if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'"; + + $sql = "SELECT Wohneinheit.oaid, COUNT(*) as count, Hausnummer.netzgebiet_id as netzgebiet_id, Netzgebiet.name as netzgebiet_name, Address.company as netzgebiet_owner FROM Wohneinheit LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id) - WHERE $where AND Wohneinheit.oaid IS NOT NULL AND Netzgebiet.name NOT LIKE 'SBIDI%' + LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id) + LEFT JOIN thetool.Address ON (Network.owner_id = Address.id) + WHERE $where AND Wohneinheit.oaid IS NOT NULL GROUP BY Wohneinheit.oaid, Hausnummer.netzgebiet_id HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC"; @@ -372,13 +381,14 @@ class ADBWohneinheitModel { $duplicateOaids = []; while($data = $res->fetch_assoc()) { + if (!$data['netzgebiet_owner']) continue; // Skip if no owner is set $duplicateOaids[] = $data['oaid']; $duplicates[$data['oaid']] = [ "duplicateType" => "oaid", 'oaid' => $data['oaid'], 'count' => $data['count'], 'netzgebiet_id' => $data['netzgebiet_id'], - 'netzgebiet_owner' => strstr($data['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK', + 'netzgebiet_owner' => $data['netzgebiet_owner'], 'homeData' => [] ]; } @@ -416,30 +426,33 @@ class ADBWohneinheitModel { return array_values($duplicates); } - public static function getRimoDeletedHomes($filter = []) { + public static function getRimoDeletedHomes($filter = [], $network_owner = null) { $deletedHomes = []; $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME)->link; $where = self::getSqlFilter($filter); - $detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref, Netzgebiet.name AS netzgebiet_name + if ($network_owner) $where .= " AND Network.owner_id = '" . FronkDB::singleton()->escape($network_owner) . "'"; + + $detailSql = "SELECT Wohneinheit.*, thetool.Address.company AS company, Hausnummer.rimo_id AS hausnummer_extref, Netzgebiet.name AS netzgebiet_name, Netzgebiet.id AS netzgebiet_id, Address.company as netzgebiet_owner FROM Wohneinheit LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) LEFT JOIN Netzgebiet ON (Netzgebiet.id = Hausnummer.netzgebiet_id) LEFT JOIN thetool.Network ON (Network.adb_netzgebiet_id = Netzgebiet.id) LEFT JOIN thetool.Address ON (Network.owner_id = Address.id) - WHERE $where AND Wohneinheit.rimo_deleted = 1 AND Netzgebiet.name NOT LIKE 'SBIDI%' + WHERE $where AND Wohneinheit.rimo_deleted = 1 ORDER BY Wohneinheit.oaid"; $counter = 0; $detailRes = $db->query($detailSql); while($homeData = $detailRes->fetch_assoc()) { + if (!$homeData['netzgebiet_owner']) continue; // Skip if no owner is set $counter++; $deletedHomes[$counter] = [ "duplicateType" => "rimo_deleted", 'oaid' => $homeData['oaid'] ?? 'Keine OAID', 'extref' => $homeData['extref'], 'netzgebiet_id' => $homeData['netzgebiet_id'], - 'netzgebiet_owner' => strstr($homeData['netzgebiet_name'], 'Liezen') ? 'RML' : 'ESTMK', + 'netzgebiet_owner' => $homeData['netzgebiet_owner'], 'count' => 1, // Each entry is unique in this context 'homeData' => [] ]; diff --git a/application/User/UserController.php b/application/User/UserController.php index 54dff8dee..4d33f2a8a 100644 --- a/application/User/UserController.php +++ b/application/User/UserController.php @@ -262,6 +262,7 @@ class UserController extends mfBaseController $user->permissions->canWarehouseAdmin = "false"; $user->permissions->canWarehouseEShop = "false"; $user->permissions->canWarehouseUser = "false"; + $user->permissions->canADBExtended = "false"; if($r->get("can") && is_array($r->can)) { foreach($r->can as $key => $can) { diff --git a/db/migrations/20250612100000_worker_permission_add_can_adb_extended.php b/db/migrations/20250612100000_worker_permission_add_can_adb_extended.php new file mode 100644 index 000000000..3dc100896 --- /dev/null +++ b/db/migrations/20250612100000_worker_permission_add_can_adb_extended.php @@ -0,0 +1,30 @@ +getEnvironment() == "thetool") { + $table = $this->table("WorkerPermission"); + $table->addColumn("canADBExtended", "enum", ["null" => false, "values" => 'false,true', "default" => "false", "after" => "canSuperexpert"]); + $table->update(); + } + + if ($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void { + if ($this->getEnvironment() == "thetool") { + $table = $this->table("WorkerPermission"); + $table->removeColumn("canADBExtended"); + $table->save(); + } + + if ($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js b/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js index f08a131e2..bb9602b10 100644 --- a/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js +++ b/public/js/pages/ADBWohneinheitDuplicate/ADBWohneinheitDuplicate.js @@ -70,12 +70,7 @@ Vue.component('a-d-b-wohneinheit-duplicate', { defaultPageSize: 10, headers: [ {text: 'Netzgebiet', key: 'netzgebiet_id', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions: window['TT_CONFIG']['ADB_NETZGEBIETE']}, - {text: 'Firma', key: 'netzgebiet_owner', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions: - [ - {text: 'RML', value: 'RML'}, - {text: 'ESTMK', value: 'ESTMK'}, - ] - }, + {text: 'Firma', key: 'netzgebiet_owner', sortable: true, class: 'text-nowrap', priority: 11, filter: 'select', filterOptions: window['TT_CONFIG']['NETWORK_OWNERS']}, {text: 'HomeID/OAID', key: 'extref', sortable: true, class: 'text-nowrap', priority: 10}, {text: 'Check-Typ', key: 'duplicateType', sortable: true, class: 'text-nowrap', priority: 9, filter: 'select', filterOptions: [ {text: 'HomeID', value: 'extref'},