Skip to content

Commit

Permalink
Merge pull request #3250 from nextcloud/refactor/deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Sep 19, 2024
2 parents 532f734 + 950d0ec commit 48ca2bd
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 85 deletions.
6 changes: 3 additions & 3 deletions lib/ACL/ACLManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
namespace OCA\GroupFolders\ACL;

use OCA\GroupFolders\Trash\TrashManager;
use OCP\IConfig;
use OCP\IAppConfig;
use OCP\IUser;
use Psr\Log\LoggerInterface;

class ACLManagerFactory {
public function __construct(
private RuleManager $ruleManager,
private TrashManager $trashManager,
private IConfig $config,
private IAppConfig $config,
private LoggerInterface $logger,
private \Closure $rootFolderProvider,
) {
Expand All @@ -31,7 +31,7 @@ public function getACLManager(IUser $user, ?int $rootStorageId = null): ACLManag
$user,
$this->rootFolderProvider,
$rootStorageId,
$this->config->getAppValue('groupfolders', 'acl-inherit-per-user', 'false') === 'true',
$this->config->getValueString('groupfolders', 'acl-inherit-per-user', 'false') === 'true',
);
}
}
35 changes: 15 additions & 20 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace OCA\GroupFolders\AppInfo;

use OC\Files\Node\LazyFolder;
use OC\Group;
use OCA\Circles\Events\CircleDestroyedEvent;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
Expand Down Expand Up @@ -42,20 +41,21 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -103,9 +103,10 @@ public function register(IRegistrationContext $context): void {
$rootProvider = function () use ($c): Folder {
return $c->get('GroupAppFolder');
};
$config = $c->get(IConfig::class);
$allowRootShare = $config->getAppValue('groupfolders', 'allow_root_share', 'true') === 'true';
$enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true';
/** @var IAppConfig $config */
$config = $c->get(IAppConfig::class);
$allowRootShare = $config->getValueString('groupfolders', 'allow_root_share', 'true') === 'true';
$enableEncryption = $config->getValueString('groupfolders', 'enable_encryption', 'false') === 'true';

return new MountProvider(
$c->get(FolderManager::class),
Expand Down Expand Up @@ -164,6 +165,7 @@ public function register(IRegistrationContext $context): void {
if ($hasVersionApp && $hasTrashApp) {
return new ExpireGroupVersionsTrash(
$c->get(GroupVersionsExpireManager::class),
$c->get(IEventDispatcher::class),
$c->get(TrashBackend::class),
$c->get(Expiration::class)
);
Expand All @@ -172,6 +174,7 @@ public function register(IRegistrationContext $context): void {
if ($hasVersionApp) {
return new ExpireGroupVersions(
$c->get(GroupVersionsExpireManager::class),
$c->get(IEventDispatcher::class),
);
}

Expand Down Expand Up @@ -204,7 +207,7 @@ public function register(IRegistrationContext $context): void {
return new ExpireGroupTrashJob(
$c->get(TrashBackend::class),
$c->get(Expiration::class),
$c->get(IConfig::class),
$c->get(IAppConfig::class),
$c->get(ITimeFactory::class)
);
}
Expand All @@ -220,7 +223,7 @@ public function register(IRegistrationContext $context): void {
return new ACLManagerFactory(
$c->get(RuleManager::class),
$c->get(TrashManager::class),
$c->get(IConfig::class),
$c->get(IAppConfig::class),
$c->get(LoggerInterface::class),
$rootFolderProvider
);
Expand All @@ -232,21 +235,13 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
$context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, Group\Manager $groupManager): void {
$mountProviderCollection->registerProvider($this->getMountProvider());
$context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, IEventDispatcher $eventDispatcher): void {
$mountProviderCollection->registerProvider(Server::get(MountProvider::class));

$groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group): void {
$this->getFolderManager()->deleteGroup($group->getGID());
$eventDispatcher->addListener(GroupDeletedEvent::class, function (GroupDeletedEvent $event): void {
Server::get(FolderManager::class)->deleteGroup($event->getGroup()->getGID());
});
$cacheListener->listen();
});
}

public function getMountProvider(): MountProvider {
return $this->getContainer()->get(MountProvider::class);
}

public function getFolderManager(): FolderManager {
return $this->getContainer()->get(FolderManager::class);
}
}
15 changes: 15 additions & 0 deletions lib/Attribute/RequireGroupFolderAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\GroupFolders\Attribute;

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
class RequireGroupFolderAdmin {
}
11 changes: 5 additions & 6 deletions lib/AuthorizedAdminSettingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
namespace OCA\GroupFolders;

use Exception;
use OCA\GroupFolders\Attribute\RequireGroupFolderAdmin;
use OCA\GroupFolders\Service\DelegationService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IRequest;
use ReflectionMethod;

class AuthorizedAdminSettingMiddleware extends Middleware {
public function __construct(
private DelegationService $delegatedService,
private IControllerMethodReflector $reflector,
private IRequest $request,
) {
}
Expand All @@ -29,10 +29,9 @@ public function __construct(
* Throws an error when the user is not allowed to use the app's APIs
*/
public function beforeController(Controller $controller, string $methodName): void {
if ($this->reflector->hasAnnotation('RequireGroupFolderAdmin')) {
if (!$this->delegatedService->hasApiAccess()) {
throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting');
}
$method = new ReflectionMethod($controller, $methodName);
if ($method->getAttributes(RequireGroupFolderAdmin::class) !== [] && !$this->delegatedService->hasApiAccess()) {
throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting');
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/BackgroundJob/ExpireGroupTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
use OCA\GroupFolders\Trash\TrashBackend;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IConfig;
use OCP\IAppConfig;

class ExpireGroupTrash extends TimedJob {
public function __construct(
private TrashBackend $trashBackend,
private Expiration $expiration,
private IConfig $config,
private IAppConfig $config,
ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
Expand All @@ -27,7 +27,7 @@ public function __construct(
}

protected function run(mixed $argument): void {
$backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes');
$backgroundJob = $this->config->getValueString('files_trashbin', 'background_job_expire_trash', 'yes');
if ($backgroundJob === 'no') {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/CacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use OCA\GroupFolders\Mount\GroupFolderStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheInsertEvent;
use OCP\Files\Cache\CacheUpdateEvent;
use OCP\Files\Cache\CacheEntryInsertedEvent;
use OCP\Files\Cache\CacheEntryUpdatedEvent;
use OCP\Files\Cache\ICacheEvent;

class CacheListener {
Expand All @@ -20,8 +20,8 @@ public function __construct(
}

public function listen(): void {
$this->eventDispatcher->addListener(CacheInsertEvent::class, $this->onCacheEvent(...), 99999);
$this->eventDispatcher->addListener(CacheUpdateEvent::class, $this->onCacheEvent(...), 99999);
$this->eventDispatcher->addListener(CacheEntryInsertedEvent::class, $this->onCacheEvent(...), 99999);
$this->eventDispatcher->addListener(CacheEntryUpdatedEvent::class, $this->onCacheEvent(...), 99999);
}

public function onCacheEvent(ICacheEvent $event): void {
Expand Down
20 changes: 12 additions & 8 deletions lib/Command/ExpireGroup/ExpireGroupVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

namespace OCA\GroupFolders\Command\ExpireGroup;

use OCA\Files_Versions\Versions\IVersion;
use OCA\GroupFolders\Event\GroupVersionsExpireDeleteFileEvent;
use OCA\GroupFolders\Event\GroupVersionsExpireDeleteVersionEvent;
use OCA\GroupFolders\Event\GroupVersionsExpireEnterFolderEvent;
use OCA\GroupFolders\Versions\GroupVersionsExpireManager;
use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -19,6 +22,7 @@
class ExpireGroupVersions extends ExpireGroupBase {
public function __construct(
private GroupVersionsExpireManager $expireManager,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct();
}
Expand All @@ -31,17 +35,17 @@ protected function configure(): void {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->expireManager->listen(GroupVersionsExpireManager::class, 'enterFolder', function (array $folder) use ($output): void {
$output->writeln("<info>Expiring version in '{$folder['mount_point']}'</info>");
$this->eventDispatcher->addListener(GroupVersionsExpireEnterFolderEvent::class, function (GroupVersionsExpireEnterFolderEvent $event) use ($output): void {
$output->writeln("<info>Expiring version in '{$event->folder['mount_point']}'</info>");
});
$this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteVersion', function (IVersion $version) use ($output): void {
$id = $version->getRevisionId();
$file = $version->getSourceFileName();
$this->eventDispatcher->addListener(GroupVersionsExpireDeleteVersionEvent::class, function (GroupVersionsExpireDeleteVersionEvent $event) use ($output): void {
$id = $event->version->getRevisionId();
$file = $event->version->getSourceFileName();
$output->writeln("<info>Expiring version $id for '$file'</info>");
});

$this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteFile', function (int $id) use ($output): void {
$output->writeln("<info>Cleaning up versions for no longer existing file with id $id</info>");
$this->eventDispatcher->addListener(GroupVersionsExpireDeleteFileEvent::class, function (GroupVersionsExpireDeleteFileEvent $event) use ($output): void {
$output->writeln('<info>Cleaning up versions for no longer existing file with id ' . $event->fileId . '</info>');
});

$this->expireManager->expireAll();
Expand Down
4 changes: 3 additions & 1 deletion lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
use OCA\Files_Trashbin\Expiration;
use OCA\GroupFolders\Trash\TrashBackend;
use OCA\GroupFolders\Versions\GroupVersionsExpireManager;
use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ExpireGroupVersionsTrash extends ExpireGroupVersions {
public function __construct(
GroupVersionsExpireManager $expireManager,
IEventDispatcher $eventDispatcher,
private TrashBackend $trashBackend,
private Expiration $expiration,
) {
parent::__construct($expireManager);
parent::__construct($expireManager, $eventDispatcher);
}

protected function configure(): void {
Expand Down
4 changes: 3 additions & 1 deletion lib/Command/Trashbin/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use OC\Core\Command\Base;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Trash\TrashBackend;
use OCP\App\IAppManager;
use OCP\Server;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -23,7 +25,7 @@ class Cleanup extends Base {

public function __construct(FolderManager $folderManager) {
parent::__construct();
if (\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')) {
if (Server::get(IAppManager::class)->isEnabledForUser('files_trashbin')) {
$this->trashBackend = \OCP\Server::get(TrashBackend::class);
$this->folderManager = $folderManager;
}
Expand Down
9 changes: 4 additions & 5 deletions lib/Controller/DelegationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\GroupFolders\Controller;

use OCA\Circles\CirclesManager;
use OCA\GroupFolders\Attribute\RequireGroupFolderAdmin;
use OCA\GroupFolders\Service\DelegationService;
use OCA\Settings\Service\AuthorizedGroupService;
use OCP\App\IAppManager;
Expand Down Expand Up @@ -38,9 +39,8 @@ public function __construct(

/**
* Returns the list of all groups
*
* @RequireGroupFolderAdmin
*/
#[RequireGroupFolderAdmin]
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/groups')]
public function getAllGroups(): DataResponse {
Expand All @@ -61,9 +61,8 @@ public function getAllGroups(): DataResponse {

/**
* Returns the list of all visible circles
*
* @RequireGroupFolderAdmin
*/
#[RequireGroupFolderAdmin]
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/circles')]
public function getAllCircles(): DataResponse {
Expand Down Expand Up @@ -102,8 +101,8 @@ public function getAllCircles(): DataResponse {
* - OCA\GroupFolders\Settings\Admin : It's reference to fields in Admin Priveleges.
* - OCA\GroupFolders\Controller\DelegationController : It's just to specific the subadmins.
* They can only manage groupfolders in which they are added in the Advanced Permissions (groups only)
* @RequireGroupFolderAdmin
*/
#[RequireGroupFolderAdmin]
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/delegation/authorized-groups')]
public function getAuthorizedGroups(string $classname = ''): DataResponse {
Expand Down
Loading

0 comments on commit 48ca2bd

Please sign in to comment.