diff options
| author | Simon Rettberg | 2025-07-04 13:59:08 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2025-07-04 13:59:08 +0200 |
| commit | 360898a12db7846b383352f9b215bda8142f7f4a (patch) | |
| tree | 33eec793f453a67a5de8da5ae661183ea00f44df | |
| parent | [locationinfo] Work around HisInOne returning incomplete iCal files (diff) | |
| download | slx-admin-360898a12db7846b383352f9b215bda8142f7f4a.tar.gz slx-admin-360898a12db7846b383352f9b215bda8142f7f4a.tar.xz slx-admin-360898a12db7846b383352f9b215bda8142f7f4a.zip | |
[locations] Copy permissions to children when deleting location
When deleting a location without recusively deleting its children too,
copy all the permissions assigned to the location in question to all its
child locations.
| -rw-r--r-- | modules-available/locations/pages/details.inc.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php index 6111d1a0..26f32e68 100644 --- a/modules-available/locations/pages/details.inc.php +++ b/modules-available/locations/pages/details.inc.php @@ -157,6 +157,7 @@ class SubPage { $locationId = (int)$location['locationid']; if (Request::post('recursive', false) === 'on') { + // Recursively delete all child locations too $locs = Location::getLocationsAssoc(); if (!isset($locs[$locationId])) { ErrorHandler::traceError("LocationID not found: $locationId"); @@ -164,14 +165,28 @@ class SubPage $deleteIds = $locs[$locationId]['children']; $deleteIds[] = $locationId; } else { + // Do not delete child locations $deleteIds = [$locationId]; - } - Database::exec('UPDATE location SET parentlocationid = :newparent + // Move any permissions down + if (Module::get('permissionmanager') !== false) { + // Get all permissions attached to location + $perms = Database::simpleQuery("SELECT roleid FROM role_x_location WHERE locationid = :lid", + ['lid' => $locationId]); + // Iterate over them, add same permission to child locations + foreach ($perms as $perm) { + Database::exec("INSERT IGNORE INTO role_x_location (roleid, locationid) + SELECT :rid, locationid FROM location WHERE parentlocationid = :lid", + ['rid' => $perm['roleid'], 'lid' => $locationId]); + } + } + // Re-parent child locations + Database::exec('UPDATE location SET parentlocationid = :newparent WHERE parentlocationid = :oldparent AND locationid NOT IN (:ids)', array( - 'ids' => $deleteIds, - 'newparent' => $location['parentlocationid'], - 'oldparent' => $location['locationid'] - )); + 'ids' => $deleteIds, + 'newparent' => $location['parentlocationid'], + 'oldparent' => $location['locationid'] + )); + } $locs = Database::exec("DELETE FROM location WHERE locationid IN (:ids)", ['ids' => $deleteIds]); AutoLocation::rebuildAll($deleteIds); Message::addSuccess('location-deleted', $locs, implode(', ', $deleteIds)); |
