Skip to content

Commit cfd7e99

Browse files
authored
Merge pull request #44844 from nextcloud/backport/44834/stable28
[stable28] fix(files): Inherit some node attributes when creating new nodes to preserve shared state
2 parents cab9fc2 + 96e200f commit cfd7e99

File tree

14 files changed

+51
-21
lines changed

14 files changed

+51
-21
lines changed

apps/files/src/actions/downloadAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const isDownloadable = function(node: Node) {
4848

4949
// If the mount type is a share, ensure it got download permissions.
5050
if (node.attributes['mount-type'] === 'shared') {
51-
const downloadAttribute = JSON.parse(node.attributes['share-attributes']).find((attribute: { scope: string; key: string }) => attribute.scope === 'permissions' && attribute.key === 'download')
51+
const shareAttributes = JSON.parse(node.attributes['share-attributes'] ?? 'null')
52+
const downloadAttribute = shareAttributes?.find?.((attribute: { scope: string; key: string }) => attribute.scope === 'permissions' && attribute.key === 'download')
5253
if (downloadAttribute !== undefined && downloadAttribute.enabled === false) {
5354
return false
5455
}

apps/files/src/components/FileEntry/FileEntryActions.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@
9393
</template>
9494

9595
<script lang="ts">
96-
import { DefaultType, FileAction, Node, NodeStatus, View, getFileActions } from '@nextcloud/files'
96+
import type { FileAction, Node, View } from '@nextcloud/files'
97+
import type { PropType } from 'vue'
98+
9799
import { showError, showSuccess } from '@nextcloud/dialogs'
100+
import { DefaultType, NodeStatus, getFileActions } from '@nextcloud/files'
98101
import { translate as t } from '@nextcloud/l10n'
99-
import Vue, { PropType } from 'vue'
102+
import Vue, { defineComponent } from 'vue'
100103
101104
import ArrowLeftIcon from 'vue-material-design-icons/ArrowLeft.vue'
102-
import ChevronRightIcon from 'vue-material-design-icons/ChevronRight.vue'
103105
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
104106
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
105107
import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator.js'
@@ -112,12 +114,11 @@ import logger from '../../logger.js'
112114
// The registered actions list
113115
const actions = getFileActions()
114116
115-
export default Vue.extend({
117+
export default defineComponent({
116118
name: 'FileEntryActions',
117119
118120
components: {
119121
ArrowLeftIcon,
120-
ChevronRightIcon,
121122
CustomElementRender,
122123
NcActionButton,
123124
NcActions,
@@ -335,7 +336,7 @@ export default Vue.extend({
335336
// Focus the previous menu action button
336337
this.$nextTick(() => {
337338
// Focus the action button
338-
const menuAction = this.$refs[`action-${action.id}`][0]
339+
const menuAction = this.$refs[`action-${action.id}`]?.[0]
339340
if (menuAction) {
340341
menuAction.$el.querySelector('button')?.focus()
341342
}

apps/files/src/newMenu/newFolder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export const entry = {
7474
owner: getCurrentUser()?.uid || null,
7575
permissions: Permission.ALL,
7676
root: context?.root || '/files/' + getCurrentUser()?.uid,
77+
// Include mount-type from parent folder as this is inherited
78+
attributes: {
79+
'mount-type': context.attributes?.['mount-type'],
80+
'owner-id': context.attributes?.['owner-id'],
81+
'owner-display-name': context.attributes?.['owner-display-name'],
82+
},
7783
})
7884

7985
showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))

apps/files/src/newMenu/newFromTemplate.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Vue, { defineAsyncComponent } from 'vue'
3636
const TemplatePickerVue = defineAsyncComponent(() => import('../views/TemplatePicker.vue'))
3737
let TemplatePicker: ComponentInstance & { open: (n: string, t: TemplateFile) => void } | null = null
3838

39-
const getTemplatePicker = async () => {
39+
const getTemplatePicker = async (context: Folder) => {
4040
if (TemplatePicker === null) {
4141
// Create document root
4242
const mountingPoint = document.createElement('div')
@@ -45,7 +45,15 @@ const getTemplatePicker = async () => {
4545

4646
// Init vue app
4747
TemplatePicker = new Vue({
48-
render: (h) => h(TemplatePickerVue, { ref: 'picker' }),
48+
render: (h) => h(
49+
TemplatePickerVue,
50+
{
51+
ref: 'picker',
52+
props: {
53+
parent: context,
54+
},
55+
},
56+
),
4957
methods: { open(...args) { this.$refs.picker.open(...args) } },
5058
el: mountingPoint,
5159
})
@@ -71,7 +79,7 @@ export function registerTemplateEntries() {
7179
},
7280
order: 11,
7381
async handler(context: Folder, content: Node[]) {
74-
const templatePicker = getTemplatePicker()
82+
const templatePicker = getTemplatePicker(context)
7583
const name = await newNodeName(`${provider.label}${provider.extension}`, content, {
7684
label: t('files', 'Filename'),
7785
name: provider.label,

apps/files/src/views/TemplatePicker.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ export default defineComponent({
9090
TemplatePreview,
9191
},
9292
93+
props: {
94+
/**
95+
* The parent folder where to create the node
96+
*/
97+
parent: {
98+
type: Object,
99+
default: () => null,
100+
},
101+
},
102+
93103
data() {
94104
return {
95105
// Check empty template by default
@@ -109,7 +119,7 @@ export default defineComponent({
109119
nameWithoutExt() {
110120
// Strip extension from name if defined
111121
return !this.extension
112-
? this.name
122+
? this.name!
113123
: this.name!.slice(0, 0 - this.extension.length)
114124
},
115125
@@ -236,6 +246,10 @@ export default defineComponent({
236246
size: fileInfo.size,
237247
permissions: fileInfo.permissions,
238248
attributes: {
249+
// Inherit some attributes from parent folder like the mount type and real owner
250+
'mount-type': this.parent?.attributes?.['mount-type'],
251+
'owner-id': this.parent?.attributes?.['owner-id'],
252+
'owner-display-name': this.parent?.attributes?.['owner-display-name'],
239253
...fileInfo,
240254
'has-preview': fileInfo.hasPreview,
241255
},

dist/2379-2379.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/2379-2379.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)