Reset default/active group when deleting a group

This commit is contained in:
Bubka 2021-10-09 19:17:05 +02:00
parent aa7321ce81
commit bb76f851d8

View File

@ -97,6 +97,25 @@ public function update(Group $group, array $data) : Group
*/
public function delete($ids) : int
{
$ids = is_array($ids) ? $ids : func_get_args();
// A group is possibly set as the default group in Settings.
// In this case we reset the setting to "No group" (groupId = 0)
$defaultGroupId = $this->settingService->get('defaultGroup');
if (in_array($defaultGroupId, $ids)) {
$this->settingService->set('defaultGroup', 0);
}
// A group is also possibly set as the active group if the user
// configured 2FAuth to memorize the active group.
// In this case we reset the setting to the pseudo "All" group (groupId = 0)
$activeGroupId = $this->settingService->get('activeGroup');
if (in_array($activeGroupId, $ids)) {
$this->settingService->set('activeGroup', 0);
}
$deleted = Group::destroy($ids);
return $deleted;