From 7900796be01d7082becb1ac22f39e2158a82a8ca Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Fri, 13 Nov 2026 20:13:15 -0400 Subject: [PATCH 1/5] fix: only enable again the users disabled for billing Signed-off-by: YvesCesar --- CHANGELOG.md | 4 +++ lib/Controller/AdminGroupController.php | 38 +++++++++++++++++-------- openapi.json | 2 +- src/types/openapi/openapi.ts | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) 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"]; From 7c1fa32b3135002c75b8944e51f3f45e6aa49126 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Fri, 13 Nov 2026 20:12:18 -0400 Subject: [PATCH 2/5] fix: record the WordPress login link when creating the group admin account Signed-off-by: YvesCesar --- lib/Controller/AdminGroupController.php | 3 +++ tests/psalm-baseline.xml | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 3d77cd3..831b25b 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -22,6 +22,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Group\ISubAdmin; use OCP\IAppConfig; +use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; use OCP\IRequest; @@ -46,6 +47,7 @@ public function __construct( protected IEventDispatcher $eventDispatcher, protected ISecureRandom $secureRandom, protected IJobList $jobList, + protected IConfig $config, ) { parent::__construct($appName, $request); } @@ -188,6 +190,7 @@ private function createUser($userId, $displayName, $email): IUser { $password = $passwordEvent->getPassword() ?? $this->secureRandom->generate(20); $user = $this->userManager->createUser($userId, $password); + $this->config->setUserValue($user->getUID(), 'wordpress_login_backend', 'wordpress_login', $user->getUID()); } if ($displayName !== '') { diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 51c048f..6a61042 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,9 +1,6 @@ - - - From 645dedac4b1cf144b117ad3ffd1fca58b04bf53b Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Wed, 18 Nov 2026 16:26:00 -0400 Subject: [PATCH 3/5] fix: drop the billing mark when a user is enabled again by any means Signed-off-by: YvesCesar --- lib/AppInfo/Application.php | 3 ++ lib/Controller/AdminGroupController.php | 3 +- lib/Listener/UserEnabledListener.php | 37 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/Listener/UserEnabledListener.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index ba0ede9..3a99724 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,12 +9,14 @@ namespace OCA\AdminGroupManager\AppInfo; use OCA\AdminGroupManager\Listener\BeforeUserAddedListener; +use OCA\AdminGroupManager\Listener\UserEnabledListener; use OCA\AdminGroupManager\Middleware\InjectionMiddleware; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Group\Events\BeforeUserAddedEvent; +use OCP\User\Events\UserChangedEvent; /** * @codeCoverageIgnore @@ -34,5 +36,6 @@ public function boot(IBootContext $context): void { public function register(IRegistrationContext $context): void { $context->registerMiddleWare(InjectionMiddleware::class); $context->registerEventListener(BeforeUserAddedEvent::class, BeforeUserAddedListener::class); + $context->registerEventListener(UserChangedEvent::class, UserEnabledListener::class); } } diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 30d782f..8ab05c2 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -35,7 +35,7 @@ use Psr\Log\LoggerInterface; class AdminGroupController extends AEnvironmentAwareOCSController { - private const DISABLED_BY_BILLING = 'disabled_by_billing'; + public const DISABLED_BY_BILLING = 'disabled_by_billing'; public function __construct( $appName, @@ -263,7 +263,6 @@ private function enableUsersDisabledByBilling(IGroup $group): void { continue; } $user->setEnabled(true); - $this->config->deleteUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING); } } diff --git a/lib/Listener/UserEnabledListener.php b/lib/Listener/UserEnabledListener.php new file mode 100644 index 0000000..6eb592f --- /dev/null +++ b/lib/Listener/UserEnabledListener.php @@ -0,0 +1,37 @@ + + */ +class UserEnabledListener implements IEventListener { + public function __construct( + private IConfig $config, + ) { + } + + #[\Override] + public function handle(Event $event): void { + if (!$event instanceof UserChangedEvent) { + return; + } + if ($event->getFeature() !== 'enabled' || $event->getValue() !== true) { + return; + } + $this->config->deleteUserValue($event->getUser()->getUID(), Application::APP_ID, AdminGroupController::DISABLED_BY_BILLING); + } +} From 5bfb5df3f337abc582e01d4a13f72bd23801cc01 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Wed, 18 Nov 2026 16:26:00 -0400 Subject: [PATCH 4/5] fix: enable again the account that owns the group when billing is restored Signed-off-by: YvesCesar --- lib/Controller/AdminGroupController.php | 12 +++++++++--- openapi.json | 2 +- src/types/openapi/openapi.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/Controller/AdminGroupController.php b/lib/Controller/AdminGroupController.php index 8ab05c2..347f444 100644 --- a/lib/Controller/AdminGroupController.php +++ b/lib/Controller/AdminGroupController.php @@ -107,7 +107,7 @@ public function createAdminGroup( /** * Set enabled status * - * Disable the enabled users of a group, or enable again only the users that this endpoint disabled. Administrators are never changed. + * Disable the enabled users of a group, or enable again the account that owns the group and 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 @@ -251,7 +251,7 @@ private function canProvision(string $groupid): bool { } $existingGroup = $this->groupManager->get($groupid); return $existingGroup instanceof IGroup - && $this->subAdmin->isSubAdminOfGroup($existingUser, $existingGroup); + && $this->ownsGroup($existingUser, $existingGroup); } private function enableUsersDisabledByBilling(IGroup $group): void { @@ -259,13 +259,19 @@ private function enableUsersDisabledByBilling(IGroup $group): void { if ($this->isAdministrator($user)) { continue; } - if ($this->config->getUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING) !== '1') { + if (!$this->ownsGroup($user, $group) + && $this->config->getUserValue($user->getUID(), Application::APP_ID, self::DISABLED_BY_BILLING) !== '1') { continue; } $user->setEnabled(true); } } + private function ownsGroup(IUser $user, IGroup $group): bool { + return $user->getUID() === $group->getGID() + && $this->subAdmin->isSubAdminOfGroup($user, $group); + } + 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 ae4fe81..cc86629 100644 --- a/openapi.json +++ b/openapi.json @@ -193,7 +193,7 @@ "post": { "operationId": "admin_group-set-enabled", "summary": "Set enabled status", - "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", + "description": "Disable the enabled users of a group, or enable again the account that owns the group and 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 ebc84fd..842e995 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 Disable the enabled users of a group, or enable again only the users that this endpoint disabled. Administrators are never changed. + * @description Disable the enabled users of a group, or enable again the account that owns the group and the users that this endpoint disabled. Administrators are never changed. * This endpoint requires admin access */ post: operations["admin_group-set-enabled"]; From 7d7706a6d131559730ae8673096d9c92fd97570c Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Wed, 18 Nov 2026 16:26:00 -0400 Subject: [PATCH 5/5] docs: describe the WordPress login link and the deploy order in the changelog Signed-off-by: YvesCesar --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf952c..1c79239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ Types of changes: ## 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. +* Enabling the users of a group, on `users-of-group/set-enabled` or when the group is provisioned again, now only enables the account that owns the group and the users that `users-of-group/set-enabled` disabled. Users disabled by the group admin stay disabled, and a user enabled again by hand loses the billing mark. Members disabled by billing before this version are not enabled again automatically; the group admin enables them in the users settings. +* The account created for the admin of a group is linked to the WordPress login of the same name, as `wordpress_login_backend` requires since its link check. Deploy this version before that one, then run `occ wordpress-login-backend:link-users --dry-run`, check the output and run it again without `--dry-run` to link the accounts created before. ## 0.1.1 - 2026-03-12 ### Changed