Add role cloning functionality and adjust permission methods.

Introduced a method to clone groups with their permissions and added a corresponding API endpoint for role cloning. Adjusted existing permission methods to ensure consistent behavior and naming, swapping the implementation of add/remove permissions. Improved permission fetching logic for cleaner data handling.
This commit is contained in:
Jepp9350
2025-02-28 09:27:06 +01:00
parent 491f268108
commit 2fca599599
3 changed files with 56 additions and 9 deletions
+26 -8
View File
@@ -66,19 +66,37 @@ class groups_o extends db
}
/**
* Add a permission to a group
* Remove a permission from a group
*
* @param string $permission_id
* @return self $this
* @throws Exception If the permission was not added successfully
* @throws Exception If the permission was not removed successfully
*/
public function addPermission(string $permission_id): self
public function removePermission(string $permission_id): self
{
self::requireSelected();
(new groups_permissions_o())->add($this->id, $permission_id);
(new groups_permissions_o())->remove($this->id, $permission_id);
return $this;
}
/**
* Clone a group with all its permissions
* @param string $name
* @param string $description
* @return void
* @throws Exception
*/
public function clone(string $name, string $description): void
{
self::requireSelected();
$group = new groups_o();
$group->add($name, $description);
$permissions = (new groups_permissions_o())->getGroupPermissions($this->id);
foreach ( $permissions as $permission ) {
$group->addPermission($permission['permission']);
}
}
/**
* Add a group
* @param string $name
@@ -114,16 +132,16 @@ class groups_o extends db
}
/**
* Remove a permission from a group
* Add a permission to a group
*
* @param string $permission_id
* @return self $this
* @throws Exception If the permission was not removed successfully
* @throws Exception If the permission was not added successfully
*/
public function removePermission(string $permission_id): self
public function addPermission(string $permission_id): self
{
self::requireSelected();
(new groups_permissions_o())->remove($this->id, $permission_id);
(new groups_permissions_o())->add($this->id, $permission_id);
return $this;
}
}