fix(files): only disable template creation when both skeleton directories are empty#58786
fix(files): only disable template creation when both skeleton directories are empty#58786benjaminfrueh wants to merge 1 commit intomasterfrom
Conversation
…d templatedirectory are empty Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
come-nc
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This will make the button appear even if it may do nothing?
There was a problem hiding this comment.
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.
| $userLang = $this->l10nFactory->getUserLanguage($this->userManager->get($this->userId)); | ||
|
|
||
| if ($skeletonTemplatePath === '') { | ||
| if ($path === null && $skeletonTemplatePath === '' && $skeletonPath === '') { |
There was a problem hiding this comment.
Why is $path also checked now?
There was a problem hiding this comment.
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.
|
@come-nc @provokateurin I think the main confusion here is, both configurations, |
Problem
When
templatedirectorywas set to an empty string, clicking "Create templates folder" resulted in a "folder not found" error, whenskeletondirectorywas still configured (not an empty string).Root cause
initializeTemplateDirectory()returns early when onlytemplatedirectoryis 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: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
skeletondirectoryandtemplatedirectoryare 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.