Skip to content

fix(files): only disable template creation when both skeleton directories are empty#58786

Open
benjaminfrueh wants to merge 1 commit intomasterfrom
fix/templates_enabled
Open

fix(files): only disable template creation when both skeleton directories are empty#58786
benjaminfrueh wants to merge 1 commit intomasterfrom
fix/templates_enabled

Conversation

@benjaminfrueh
Copy link
Contributor

@benjaminfrueh benjaminfrueh commented Mar 7, 2026

Problem

When templatedirectory was set to an empty string, clicking "Create templates folder" resulted in a "folder not found" error, when skeletondirectory was still configured (not an empty string).

Root cause

initializeTemplateDirectory() returns early when only templatedirectory is empty, while the frontend showed the button with an || condition, so if either of them is not an empty string.

Fix

As it is documented in config.sample.php:

To disable creating a template directory, set both skeletondirectory and templatedirectory to empty strings.

The early return now only happens when both are empty, and only for automatic initialization, not when the user manually requests template folder creation.

Note

skeletondirectory and templatedirectory are used for provisioning files during initialization. In my opinion it should not take the manual "Create templates folder" feature away from users, that could remain in the users control while still preventing the automatic creation as expected from the config. Every user can create and use their own templates. If an admin wants to explicitly disable this feature, there should be a new config option for that, not a side effect of the file provisioning configuration.

Open for discussion, I am happy to hear if there is a different opinion on how this should be handled.

…d templatedirectory are empty

Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
@benjaminfrueh benjaminfrueh requested a review from a team as a code owner March 7, 2026 23:43
@benjaminfrueh benjaminfrueh added bug 3. to review Waiting for reviews labels Mar 7, 2026
@benjaminfrueh benjaminfrueh requested review from CarlSchwan, come-nc, leftybournes and salmart-dev and removed request for a team March 7, 2026 23:43
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about setting the condition in the UI as well on if the templatedirectory is empty only ?
skeletondirectory should only matter for user initialization, no?

}

$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_enabled', true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the button appear even if it may do nothing?

Copy link
Contributor Author

@benjaminfrueh benjaminfrueh Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests the button always works correctly even if both configurations are empty. It manually creates a template directory in the users directory and is only available for users who don't have a template directory configured yet.

This wasn't working before because the condition in initializeTemplateDirectory was blocking it even when coming from a manual user request, not from the automatic initialization on new user setup.

The change was originally implemented to prevent the automatic creation of the template folder, the manual creation is a feature a user could always opt-in and use.

So in my opinion the manual creation could always be possible regardless of both configurations. If the nextcloud configurated templatedirectory is a empty string, no files will be seeded automatically from there, but the user can still create it and add their own templates to it.

@benjaminfrueh benjaminfrueh requested a review from come-nc March 16, 2026 06:58
$userLang = $this->l10nFactory->getUserLanguage($this->userManager->get($this->userId));

if ($skeletonTemplatePath === '') {
if ($path === null && $skeletonTemplatePath === '' && $skeletonPath === '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is $path also checked now?

Copy link
Contributor Author

@benjaminfrueh benjaminfrueh Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path check is to prevent the template dir creation only for the automatic initialization setup (when a user is created). For the manual creation with the button in the Web UI, there is always a path given. The same path check is used a few lines later to detect initial user setup.

@benjaminfrueh
Copy link
Contributor Author

@come-nc @provokateurin I think the main confusion here is, both configurations, skeletondirectory and templatedirectory are only needed for seeding the template folder and template files automatically from a shared source, but they are both not needed for manually creating a empty template directory via the web ui, where the user can then add his own templates to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants