Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide "Create templates folder" option if templates are disabled #50215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-FileCopyrightText: 2025 Informatyka Boguslawski sp. z o.o. sp.k.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files\Controller;
Expand Down Expand Up @@ -194,6 +195,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$this->eventDispatcher->dispatchTyped(new LoadViewer());
}

$this->initialState->provideInitialState('templates_enabled', ($this->config->getSystemValueString('skeletondirectory', '') !== '') || ($this->config->getSystemValueString('templatedirectory', '') !== ''));
$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());

Expand Down
7 changes: 5 additions & 2 deletions apps/files/src/newMenu/newTemplatesFolder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2025 Informatyka Boguslawski sp. z o.o. sp.k.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Entry, Folder, Node } from '@nextcloud/files'
Expand All @@ -17,7 +18,9 @@
import axios from '@nextcloud/axios'
import logger from '../logger.ts'

let templatesEnabled = loadState<boolean>('files', 'templates_enabled', true)

Check failure on line 21 in apps/files/src/newMenu/newTemplatesFolder.ts

View workflow job for this annotation

GitHub Actions / NPM lint

'templatesEnabled' is never reassigned. Use 'const' instead
let templatesPath = loadState<string|false>('files', 'templates_path', false)
logger.debug('Templates folder enabled', { templatesEnabled })
logger.debug('Initial templates folder', { templatesPath })

/**
Expand Down Expand Up @@ -57,8 +60,8 @@
iconSvgInline: PlusSvg,
order: 30,
enabled(context: Folder): boolean {
// Templates folder already initialized
if (templatesPath) {
// Templates disabled or templates folder already initialized
if (!templatesEnabled || templatesPath) {
return false
}
// Allow creation on your own folders only
Expand Down
14 changes: 7 additions & 7 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-FileCopyrightText: 2025 Informatyka Boguslawski sp. z o.o. sp.k.
* SPDX-License-Identifier: AGPL-3.0-only
*/

Expand Down Expand Up @@ -288,8 +289,9 @@

/**
* The directory where the skeleton files are located. These files will be
* copied to the data directory of new users. Leave empty to not copy any
* skeleton files.
* copied to the data directory of new users. Set empty string to not copy any
* skeleton files. If unset and templatedirectory is empty string, shipped
* templates will be used to create a template directory for the user.
* ``{lang}`` can be used as a placeholder for the language of the user.
* If the directory does not exist, it falls back to non dialect (from ``de_DE``
* to ``de``). If that does not exist either, it falls back to ``default``
Expand All @@ -298,18 +300,16 @@
*/
'skeletondirectory' => '/path/to/nextcloud/core/skeleton',


/**
* The directory where the template files are located. These files will be
* copied to the template directory of new users. Leave empty to not copy any
* copied to the template directory of new users. Set empty string to not copy any
* template files.
* ``{lang}`` can be used as a placeholder for the language of the user.
* If the directory does not exist, it falls back to non dialect (from ``de_DE``
* to ``de``). If that does not exist either, it falls back to ``default``
*
* If this is not set creating a template directory will only happen if no custom
* ``skeletondirectory`` is defined, otherwise the shipped templates will be used
* to create a template directory for the user.
* To disable creating a template directory, set both skeletondirectory and
* templatedirectory to empty strings.
*/
'templatedirectory' => '/path/to/nextcloud/templates',

Expand Down
Loading