-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46892 from nextcloud/fix/add-note-to-recipient
fix(files_sharing): Add missing "note to recipient"
- Loading branch information
Showing
99 changed files
with
598 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { ComponentPublicInstance, VueConstructor } from 'vue' | ||
|
||
import { Folder, Header, registerFileListHeaders } from '@nextcloud/files' | ||
import Vue from 'vue' | ||
|
||
type IFilesHeaderNoteToRecipient = ComponentPublicInstance & { updateFolder: (folder: Folder) => void } | ||
|
||
/** | ||
* Register the "note to recipient" as a files list header | ||
*/ | ||
export default function registerNoteToRecipient() { | ||
let FilesHeaderNoteToRecipient: VueConstructor | ||
let instance: IFilesHeaderNoteToRecipient | ||
|
||
registerFileListHeaders(new Header({ | ||
id: 'note-to-recipient', | ||
order: 0, | ||
// Always if there is a note | ||
enabled: (folder: Folder) => Boolean(folder.attributes.note), | ||
// Update the root folder if needed | ||
updated: (folder: Folder) => { | ||
instance.updateFolder(folder) | ||
}, | ||
// render simply spawns the component | ||
render: async (el: HTMLElement, folder: Folder) => { | ||
if (FilesHeaderNoteToRecipient === undefined) { | ||
const { default: component } = await import('../views/FilesHeaderNoteToRecipient.vue') | ||
FilesHeaderNoteToRecipient = Vue.extend(component) | ||
} | ||
instance = new FilesHeaderNoteToRecipient().$mount(el) as unknown as IFilesHeaderNoteToRecipient | ||
instance.updateFolder(folder) | ||
}, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
<template> | ||
<NcNoteCard v-if="note.length > 0" | ||
class="note-to-recipient" | ||
type="info"> | ||
<p v-if="user" class="note-to-recipient__heading"> | ||
{{ t('files_sharing', 'Note from') }} | ||
<NcUserBubble :user="user.id" :display-name="user.displayName" /> | ||
</p> | ||
<p v-else class="note-to-recipient__heading"> | ||
{{ t('files_sharing', 'Note:') }} | ||
</p> | ||
<p class="note-to-recipient__text" v-text="note" /> | ||
</NcNoteCard> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { Folder } from '@nextcloud/files' | ||
import { getCurrentUser } from '@nextcloud/auth' | ||
import { t } from '@nextcloud/l10n' | ||
import { computed, ref } from 'vue' | ||
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js' | ||
import NcUserBubble from '@nextcloud/vue/dist/Components/NcUserBubble.js' | ||
const folder = ref<Folder>() | ||
const note = computed<string>(() => folder.value?.attributes.note ?? '') | ||
const user = computed(() => { | ||
const id = folder.value?.attributes?.['owner-id'] | ||
const displayName = folder.value?.attributes?.['owner-display-name'] | ||
if (id !== getCurrentUser()?.uid) { | ||
return { | ||
id, | ||
displayName, | ||
} | ||
} | ||
return null | ||
}) | ||
/** | ||
* Update the current folder | ||
* @param newFolder the new folder to show note for | ||
*/ | ||
function updateFolder(newFolder: Folder) { | ||
folder.value = newFolder | ||
} | ||
defineExpose({ updateFolder }) | ||
</script> | ||
|
||
<style scoped> | ||
.note-to-recipient { | ||
margin-inline: var(--row-height) | ||
} | ||
.note-to-recipient__text { | ||
/* respect new lines */ | ||
white-space: pre-line; | ||
} | ||
.note-to-recipient__heading { | ||
font-weight: bold; | ||
} | ||
@media screen and (max-width: 512px) { | ||
.note-to-recipient { | ||
margin-inline: var(--default-grid-baseline); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*! | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { User } from '@nextcloud/cypress' | ||
import { createShare, openSharingPanel } from './FilesSharingUtils.ts' | ||
import { getRowForFile, navigateToFolder } from '../files/FilesUtils.ts' | ||
|
||
describe('files_sharing: Note to recipient', { testIsolation: true }, () => { | ||
let user: User | ||
let sharee: User | ||
|
||
beforeEach(() => { | ||
cy.createRandomUser().then(($user) => { | ||
user = $user | ||
}) | ||
cy.createRandomUser().then(($user) => { | ||
sharee = $user | ||
}) | ||
}) | ||
|
||
it('displays the note to the sharee', () => { | ||
cy.mkdir(user, '/folder') | ||
cy.uploadContent(user, new Blob([]), 'text/plain', '/folder/file') | ||
cy.login(user) | ||
cy.visit('/apps/files') | ||
|
||
// share the folder | ||
createShare('folder', sharee.userId, { read: true, download: true, note: 'Hello, this is the note.' }) | ||
|
||
cy.logout() | ||
// Now for the sharee | ||
cy.login(sharee) | ||
|
||
// visit shared files view | ||
cy.visit('/apps/files') | ||
navigateToFolder('folder') | ||
cy.get('.note-to-recipient') | ||
.should('be.visible') | ||
.and('contain.text', 'Hello, this is the note.') | ||
}) | ||
|
||
/** | ||
* Regression test for https://github.com/nextcloud/server/issues/46188 | ||
*/ | ||
it('shows an existing note when editing a share', () => { | ||
cy.mkdir(user, '/folder') | ||
cy.login(user) | ||
cy.visit('/apps/files') | ||
|
||
// share the folder | ||
createShare('folder', sharee.userId, { read: true, download: true, note: 'Hello, this is the note.' }) | ||
|
||
// reload just to be sure | ||
cy.reload() | ||
|
||
// open the sharing tab | ||
openSharingPanel('folder') | ||
|
||
cy.get('[data-cy-sidebar]').within(() => { | ||
// Open the share | ||
cy.get('[data-cy-files-sharing-share-actions]').first().click() | ||
// Open the custom settings | ||
cy.get('[data-cy-files-sharing-share-permissions-bundle="custom"]').click() | ||
|
||
cy.findByRole('checkbox', { name: /note to recipient/i }) | ||
.and('be.checked') | ||
cy.findByRole('textbox', { name: /note to recipient/i }) | ||
.should('be.visible') | ||
.and('have.value', 'Hello, this is the note.') | ||
}) | ||
}) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2351-2351.js.license |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.