diff --git a/CHANGELOG.md b/CHANGELOG.md index dd3405b..ebf952c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Types of changes: - *Security* in case of vulnerabilities. +## Unreleased +### Security +* Enabling the users of a group, on `users-of-group/set-enabled` or when the group is provisioned again, now only enables the users that `users-of-group/set-enabled` disabled. Users disabled by the group admin stay disabled. Users disabled by billing before this version are not enabled again automatically; the group admin enables them in the users settings. + ## 0.1.1 - 2026-03-12 ### Changed * Declare compatibility with Nextcloud 33. diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 831b25b..30d782f 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -8,6 +8,7 @@ namespace OCA\AdminGroupManager\Controller; +use OCA\AdminGroupManager\AppInfo\Application; use OCA\AdminGroupManager\BackgroundJob\EnableAppsForGroup; use OCA\AdminGroupManager\Controller\Attribute\RestrictIp; use OCA\Settings\Settings\Admin\Users; @@ -34,6 +35,8 @@ use Psr\Log\LoggerInterface; class AdminGroupController extends AEnvironmentAwareOCSController { + private const DISABLED_BY_BILLING = 'disabled_by_billing'; + public function __construct( $appName, IRequest $request, @@ -104,7 +107,7 @@ public function createAdminGroup( /** * Set enabled status * - * Change the status of all users of a group to be enabled or not. + * Disable the enabled users of a group, or enable again only the users that this endpoint disabled. Administrators are never changed. * * @param string $groupid ID of the group * @param int<0, 1> $enabled 1 or 0 @@ -126,12 +129,16 @@ public function setEnabled( if (!$group instanceof IGroup) { return new DataResponse([], Http::STATUS_NOT_FOUND); } - $users = $group->getUsers(); - foreach ($users as $user) { - if ($this->isAdministrator($user)) { + if ($enabled) { + $this->enableUsersDisabledByBilling($group); + return new DataResponse(); + } + foreach ($group->getUsers() as $user) { + if ($this->isAdministrator($user) || !$user->isEnabled()) { continue; } - $user->setEnabled((bool)$enabled); + $this->config->setUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING, '1'); + $user->setEnabled(false); } return new DataResponse(); } @@ -216,13 +223,7 @@ private function addGroup(string $groupid, string $displayname = ''): IGroup { // Check if it exists $group = $this->groupManager->get($groupid); if ($group instanceof IGroup) { - $users = $group->getUsers(); - foreach ($users as $user) { - if ($this->isAdministrator($user)) { - continue; - } - $user->setEnabled(true); - } + $this->enableUsersDisabledByBilling($group); } else { $group = $this->groupManager->createGroup($groupid); } @@ -253,6 +254,19 @@ private function canProvision(string $groupid): bool { && $this->subAdmin->isSubAdminOfGroup($existingUser, $existingGroup); } + private function enableUsersDisabledByBilling(IGroup $group): void { + foreach ($group->getUsers() as $user) { + if ($this->isAdministrator($user)) { + continue; + } + if ($this->config->getUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING) !== '1') { + continue; + } + $user->setEnabled(true); + $this->config->deleteUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING); + } + } + private function isAdministrator(IUser $user): bool { return $this->groupManager->isAdmin($user->getUID()) || $this->groupManager->isDelegatedAdmin($user->getUID()); diff --git a/openapi.json b/openapi.json index a7cbe3b..ae4fe81 100644 --- a/openapi.json +++ b/openapi.json @@ -193,7 +193,7 @@ "post": { "operationId": "admin_group-set-enabled", "summary": "Set enabled status", - "description": "Change the status of all users of a group to be enabled or not.\nThis endpoint requires admin access", + "description": "Disable the enabled users of a group, or enable again only the users that this endpoint disabled. Administrators are never changed.\nThis endpoint requires admin access", "tags": [ "admin_group" ], diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index dee222e..ebc84fd 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -36,7 +36,7 @@ export type paths = { put?: never; /** * Set enabled status - * @description Change the status of all users of a group to be enabled or not. + * @description Disable the enabled users of a group, or enable again only the users that this endpoint disabled. Administrators are never changed. * This endpoint requires admin access */ post: operations["admin_group-set-enabled"];