Skip to content

Commit e5e423c

Browse files
authored
Merge pull request #60522 from nextcloud/backport/60187/stable33
[stable33] fix(files): only show template picker menu entries if possible
2 parents eeb9f93 + 5b24748 commit e5e423c

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

apps/files/src/newMenu/newFromTemplate.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { Folder, NewMenuEntry, Node } from '@nextcloud/files'
6+
import type { IFolder, INode, NewMenuEntry } from '@nextcloud/files'
77
import type { ComponentInstance } from 'vue'
88
import type { TemplateFile } from '../types.ts'
99

@@ -22,7 +22,7 @@ let TemplatePicker: ComponentInstance & { open: (n: string, t: TemplateFile) =>
2222
*
2323
* @param context
2424
*/
25-
async function getTemplatePicker(context: Folder) {
25+
async function getTemplatePicker(context: IFolder) {
2626
if (TemplatePicker === null) {
2727
// Create document root
2828
const mountingPoint = document.createElement('div')
@@ -63,13 +63,18 @@ export function registerTemplateEntries() {
6363
addNewFileMenuEntry({
6464
id: `template-new-${provider.app}-${index}`,
6565
displayName: provider.label,
66-
iconClass: provider.iconClass || 'icon-file',
6766
iconSvgInline: provider.iconSvgInline,
68-
enabled(context: Folder): boolean {
69-
return (context.permissions & Permission.CREATE) !== 0
67+
enabled(context: IFolder): boolean {
68+
if (context.attributes['is-encrypted']) {
69+
return false
70+
}
71+
72+
// templates are only supported in folders where the user has read and create permissions
73+
return (context.permissions & Permission.READ) !== 0
74+
&& (context.permissions & Permission.CREATE) !== 0
7075
},
7176
order: 11,
72-
async handler(context: Folder, content: Node[]) {
77+
async handler(context: IFolder, content: INode[]) {
7378
const templatePicker = getTemplatePicker(context)
7479
const name = await newNodeName(`${provider.label}${provider.extension}`, content, {
7580
label: t('files', 'Filename'),

dist/files-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)