2021-07-22 05:41:29 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2024-06-03 04:23:34 -04:00
|
|
|
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-07-22 05:41:29 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Settings\Controller;
|
|
|
|
|
|
|
|
|
|
use OC\Settings\AuthorizedGroup;
|
|
|
|
|
use OCA\Settings\Service\AuthorizedGroupService;
|
|
|
|
|
use OCA\Settings\Service\NotFoundException;
|
2023-11-23 04:22:34 -05:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2021-07-22 05:41:29 -04:00
|
|
|
use OCP\DB\Exception;
|
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
|
|
class AuthorizedGroupController extends Controller {
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
2025-09-27 13:02:16 -04:00
|
|
|
string $appName,
|
2024-10-18 06:04:22 -04:00
|
|
|
IRequest $request,
|
|
|
|
|
private AuthorizedGroupService $authorizedGroupService,
|
|
|
|
|
) {
|
2025-09-27 13:02:16 -04:00
|
|
|
parent::__construct($appName, $request);
|
2021-07-22 05:41:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws NotFoundException
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function saveSettings(array $newGroups, string $class): DataResponse {
|
|
|
|
|
$currentGroups = $this->authorizedGroupService->findExistingGroupsForClass($class);
|
|
|
|
|
|
|
|
|
|
foreach ($currentGroups as $group) {
|
|
|
|
|
/** @var AuthorizedGroup $group */
|
|
|
|
|
$removed = true;
|
|
|
|
|
foreach ($newGroups as $groupData) {
|
|
|
|
|
if ($groupData['gid'] === $group->getGroupId()) {
|
|
|
|
|
$removed = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($removed) {
|
|
|
|
|
$this->authorizedGroupService->delete($group->getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($newGroups as $groupData) {
|
|
|
|
|
$added = true;
|
|
|
|
|
foreach ($currentGroups as $group) {
|
|
|
|
|
/** @var AuthorizedGroup $group */
|
|
|
|
|
if ($groupData['gid'] === $group->getGroupId()) {
|
|
|
|
|
$added = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($added) {
|
|
|
|
|
$this->authorizedGroupService->create($groupData['gid'], $class);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2021-07-22 05:41:29 -04:00
|
|
|
return new DataResponse(['valid' => true]);
|
|
|
|
|
}
|
|
|
|
|
}
|