Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Types of changes:
- *Security* in case of vulnerabilities.

<!-- changelog-linker -->
## 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.
Expand Down
38 changes: 26 additions & 12 deletions lib/Controller/AdminGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
2 changes: 1 addition & 1 deletion src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
Loading