mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
fix(files): Use proper DI for ApiController
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
896b54b8ee
commit
865cf5f2a7
3 changed files with 9 additions and 36 deletions
|
|
@ -14,7 +14,6 @@ use OCA\Files\Capabilities;
|
|||
use OCA\Files\Collaboration\Resources\Listener;
|
||||
use OCA\Files\Collaboration\Resources\ResourceProvider;
|
||||
use OCA\Files\ConfigLexicon;
|
||||
use OCA\Files\Controller\ApiController;
|
||||
use OCA\Files\Dashboard\FavoriteWidget;
|
||||
use OCA\Files\DirectEditingCapabilities;
|
||||
use OCA\Files\Event\LoadSearchPlugins;
|
||||
|
|
@ -29,8 +28,6 @@ use OCA\Files\Listener\UserFirstTimeLoggedInListener;
|
|||
use OCA\Files\Notification\Notifier;
|
||||
use OCA\Files\Search\FilesSearchProvider;
|
||||
use OCA\Files\Service\TagService;
|
||||
use OCA\Files\Service\UserConfig;
|
||||
use OCA\Files\Service\ViewConfig;
|
||||
use OCP\Activity\IManager as IActivityManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
|
|
@ -45,19 +42,12 @@ use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
|
|||
use OCP\Files\Events\Node\NodeCopiedEvent;
|
||||
use OCP\Files\Events\NodeAddedToFavorite;
|
||||
use OCP\Files\Events\NodeRemovedFromFavorite;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IPreview;
|
||||
use OCP\IRequest;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\ITagManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IManager as IShareManager;
|
||||
use OCP\User\Events\UserFirstTimeLoggedInEvent;
|
||||
use OCP\Util;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'files';
|
||||
|
|
@ -68,30 +58,6 @@ class Application extends App implements IBootstrap {
|
|||
|
||||
#[\Override]
|
||||
public function register(IRegistrationContext $context): void {
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
$context->registerService('APIController', function (ContainerInterface $c) {
|
||||
/** @var IServerContainer $server */
|
||||
$server = $c->get(IServerContainer::class);
|
||||
|
||||
return new ApiController(
|
||||
$c->get('AppName'),
|
||||
$c->get(IRequest::class),
|
||||
$c->get(IUserSession::class),
|
||||
$c->get(TagService::class),
|
||||
$c->get(IPreview::class),
|
||||
$c->get(IShareManager::class),
|
||||
$c->get(IConfig::class),
|
||||
$server->getUserFolder(),
|
||||
$c->get(UserConfig::class),
|
||||
$c->get(ViewConfig::class),
|
||||
$c->get(IL10N::class),
|
||||
$c->get(IRootFolder::class),
|
||||
$c->get(LoggerInterface::class),
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Services
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ use Throwable;
|
|||
* @package OCA\Files\Controller
|
||||
*/
|
||||
class ApiController extends Controller {
|
||||
private ?Folder $userFolder = null;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
|
|
@ -61,7 +63,6 @@ class ApiController extends Controller {
|
|||
private IPreview $previewManager,
|
||||
private IManager $shareManager,
|
||||
private IConfig $config,
|
||||
private ?Folder $userFolder,
|
||||
private UserConfig $userConfig,
|
||||
private ViewConfig $viewConfig,
|
||||
private IL10N $l10n,
|
||||
|
|
@ -69,6 +70,10 @@ class ApiController extends Controller {
|
|||
private LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user) {
|
||||
$this->userFolder = $this->rootFolder->getUserFolder($user->getUID());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ class ApiControllerTest extends TestCase {
|
|||
$this->viewConfig = $this->createMock(ViewConfig::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->rootFolder = $this->createMock(IRootFolder::class);
|
||||
$this->rootFolder->expects($this->any())
|
||||
->method('getUserFolder')
|
||||
->willReturn($this->userFolder);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->apiController = new ApiController(
|
||||
|
|
@ -87,7 +90,6 @@ class ApiControllerTest extends TestCase {
|
|||
$this->preview,
|
||||
$this->shareManager,
|
||||
$this->config,
|
||||
$this->userFolder,
|
||||
$this->userConfig,
|
||||
$this->viewConfig,
|
||||
$this->l10n,
|
||||
|
|
|
|||
Loading…
Reference in a new issue