urlGenerator->linkToRoute('files.view.index')); } // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. try { return $this->redirectToFile((int)$fileid, $opendetails, $openfile); } catch (NotFoundException $e) { // Keep the fileid even if not found, it will be used // to detect the file could not be found and warn the user return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', ['fileid' => $fileid, 'view' => 'files'])); } } /** * @param string $dir * @param string $view * @param string $fileid * @return TemplateResponse|RedirectResponse */ #[NoAdminRequired] #[NoCSRFRequired] public function indexView($dir = '', $view = '', $fileid = null) { return $this->index($dir, $view, $fileid); } /** * @param string $dir * @param string $view * @param string $fileid * @return TemplateResponse|RedirectResponse */ #[NoAdminRequired] #[NoCSRFRequired] public function indexViewFileid($dir = '', $view = '', $fileid = null) { return $this->index($dir, $view, $fileid); } /** * @param string $dir * @param string $view * @param string $fileid * @return TemplateResponse|RedirectResponse */ #[NoAdminRequired] #[NoCSRFRequired] public function index($dir = '', $view = '', $fileid = null) { if ($fileid !== null && $view !== 'trashbin') { try { return $this->redirectToFileIfInTrashbin((int)$fileid); } catch (NotFoundException $e) { } } // Load the files we need Util::addInitScript('files', 'init'); Util::addScript('files', 'main'); $userId = $this->userSession->getUser()->getUID(); // If the file doesn't exists in the folder and // exists in only one occurrence, redirect to that file // in the correct folder if ($fileid && $dir !== '') { $baseFolder = $this->rootFolder->getUserFolder($userId); $nodes = $baseFolder->getById((int)$fileid); if (!empty($nodes)) { $nodePath = $baseFolder->getRelativePath($nodes[0]->getPath()); $relativePath = $nodePath ? dirname($nodePath) : ''; // If the requested path does not contain the file id // or if the requested path is not the file id itself if (count($nodes) === 1 && $relativePath !== $dir && $nodePath !== $dir) { return $this->redirectToFile((int)$fileid); } } } try { // If view is files, we use the directory, otherwise we use the root storage $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); } catch (\Exception $e) { $storageInfo = $this->getStorageInfo(); } $this->initialState->provideInitialState('storageStats', $storageInfo); $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); $this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs()); // File sorting user config $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true); $this->initialState->provideInitialState('filesSortingConfig', $filesSortingConfig); // Forbidden file characters (deprecated use capabilities) // TODO: Remove with next release of `@nextcloud/files` $forbiddenCharacters = $this->filenameValidator->getForbiddenCharacters(); $this->initialState->provideInitialState('forbiddenCharacters', $forbiddenCharacters); $event = new LoadAdditionalScriptsEvent(); $this->eventDispatcher->dispatchTyped($event); $this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent()); $this->eventDispatcher->dispatchTyped(new LoadSidebar()); $this->eventDispatcher->dispatchTyped(new LoadSearchPlugins()); // Load Viewer scripts if (class_exists(LoadViewer::class)) { $this->eventDispatcher->dispatchTyped(new LoadViewer()); } $this->initialState->provideInitialState('templates_enabled', ($this->config->getSystemValueString('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton') !== '') || ($this->config->getSystemValueString('templatedirectory', \OC::$SERVERROOT . '/core/skeleton/Templates') !== '')); $this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false); $this->initialState->provideInitialState('templates', $this->templateManager->listCreators()); $response = new TemplateResponse( Application::APP_ID, 'index', ); $policy = new ContentSecurityPolicy(); $policy->addAllowedFrameDomain('\'self\''); // Allow preview service worker $policy->addAllowedWorkerSrcDomain('\'self\''); $response->setContentSecurityPolicy($policy); return $response; } /** * Redirects to the trashbin file list and highlight the given file id * * @param int $fileId file id to show * @return RedirectResponse redirect response or not found response * @throws NotFoundException */ private function redirectToFileIfInTrashbin($fileId): RedirectResponse { $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); $node = $baseFolder->getFirstNodeById($fileId); $params = []; if (!$node && $this->appManager->isEnabledForUser('files_trashbin')) { /** @var Folder */ $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); $node = $baseFolder->getFirstNodeById($fileId); $params['view'] = 'trashbin'; if ($node) { $params['fileid'] = $fileId; if ($node instanceof Folder) { // set the full path to enter the folder $params['dir'] = $baseFolder->getRelativePath($node->getPath()); } else { // set parent path as dir $params['dir'] = $baseFolder->getRelativePath($node->getParent()->getPath()); } return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params)); } } throw new NotFoundException(); } /** * Redirects to the file list and highlight the given file id * * @param int $fileId file id to show * @param string|null $openDetails open details parameter * @param string|null $openFile open file parameter * @return RedirectResponse redirect response or not found response * @throws NotFoundException */ private function redirectToFile(int $fileId, ?string $openDetails = null, ?string $openFile = null): RedirectResponse { $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); $node = $baseFolder->getFirstNodeById($fileId); $params = ['view' => 'files']; try { $this->redirectToFileIfInTrashbin($fileId); } catch (NotFoundException $e) { } if ($node) { $params['fileid'] = $fileId; if ($node instanceof Folder) { // set the full path to enter the folder $params['dir'] = $baseFolder->getRelativePath($node->getPath()); } else { // set parent path as dir $params['dir'] = $baseFolder->getRelativePath($node->getParent()->getPath()); // open the file by default (opening the viewer) $params['openfile'] = 'true'; } // Forward open parameters if any. // - openfile is true by default // - opendetails is undefined by default // - both will be evaluated as truthy if ($openDetails !== null) { $params['opendetails'] = $openDetails !== 'false' ? 'true' : 'false'; } if ($openFile !== null) { $params['openfile'] = $openFile !== 'false' ? 'true' : 'false'; } return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.indexViewFileid', $params)); } throw new NotFoundException(); } } rage_full_warning'>artonge/fix/storage_full_warning Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib/Controller/HelpController.php
blob: 05bff158ee6515fcf3cea63307b6b712b27b0f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Settings\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;

#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class HelpController extends Controller {

	public function __construct(
		string $appName,
		IRequest $request,
		private INavigationManager $navigationManager,
		private IURLGenerator $urlGenerator,
		/** @var string */
		private ?string $userId,
		private IGroupManager $groupManager,
		private IL10N $l10n,
		private IConfig $config,
		private IAppConfig $appConfig,
	) {
		parent::__construct($appName, $request);
	}

	/**
	 * @return TemplateResponse
	 *
	 * @NoSubAdminRequired
	 */
	#[NoCSRFRequired]
	#[NoAdminRequired]
	public function help(string $mode = 'user'): TemplateResponse {
		$this->navigationManager->setActiveEntry('help');
		$pageTitle = $this->l10n->t('Administrator documentation');
		if ($mode !== 'admin') {
			$pageTitle = $this->l10n->t('User documentation');
			$mode = 'user';
		}

		$documentationUrl = $this->urlGenerator->getAbsoluteURL(
			$this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
		);

		$urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
		$urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);

		$knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
		if (!$knowledgebaseEmbedded) {
			$pageTitle = $this->l10n->t('Nextcloud help overview');
			$urlUserDocs = $this->urlGenerator->linkToDocs('user');
			$urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
		}

		$legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
		$privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');

		$response = new TemplateResponse('settings', 'help', [
			'admin' => $this->groupManager->isAdmin($this->userId),
			'url' => $documentationUrl,
			'urlUserDocs' => $urlUserDocs,
			'urlAdminDocs' => $urlAdminDocs,
			'mode' => $mode,
			'pageTitle' => $pageTitle,
			'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
			'legalNoticeUrl' => $legalNoticeUrl,
			'privacyUrl' => $privacyUrl,
		]);
		$policy = new ContentSecurityPolicy();
		$policy->addAllowedFrameDomain('\'self\'');
		$response->setContentSecurityPolicy($policy);
		return $response;
	}
}