Skip to content

Commit ff279fd

Browse files
committed
fix(sharing): list accounts with matches in email
* Show users with matches in the email address. * List email addresses in sharing dialog. `NcSelect` filters the options based on matches in `label` and `subname`. By using the email address as a subname we ensure options with a matching email address are shown. Signed-off-by: Max <max@nextcloud.com>
1 parent 07da8b7 commit ff279fd

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

cypress/e2e/sharingFeatures.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { randUser } from '../utils/index.js'
22
import { sampleBoard } from '../utils/sampleBoard'
33
const user = randUser()
44
const recipient = randUser()
5+
const domain = Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 10)
56

67
describe('Board', function() {
78
before(function() {
89
cy.createUser(user)
910
cy.createUser(recipient)
11+
cy.login(recipient)
12+
cy.setUserEmail(recipient, `${recipient.userId}@${domain}.com`)
1013
})
1114

1215
beforeEach(function() {
@@ -30,6 +33,24 @@ describe('Board', function() {
3033
})
3134
})
3235

36+
it('Share a board to a user by email', function() {
37+
const board = sampleBoard('Shared by email')
38+
cy.createExampleBoard({ user, board }).then((board) => {
39+
const boardId = board.id
40+
cy.visit(`/apps/deck/#/board/${boardId}`)
41+
cy.get('.board-title').contains(board.title)
42+
43+
// domain is only in the email address - not in user ids.
44+
cy.shareBoardWithUi(domain, recipient.userId)
45+
46+
cy.login(recipient)
47+
cy.visit(`/apps/deck/#/board/${boardId}`)
48+
cy.get('.board-title').contains(board.title)
49+
cy.get('.button-vue[aria-label*="Add card"]')
50+
.should('not.exist')
51+
})
52+
})
53+
3354
it('Share a board to a user as writable', function() {
3455
const board = sampleBoard('Editable board')
3556
cy.createExampleBoard({ user, board }).then((board) => {

cypress/support/commands.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@
2121
*/
2222

2323
import { addCommands } from '@nextcloud/cypress'
24+
import axios from '@nextcloud/axios'
2425

2526
addCommands()
2627

2728
const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
2829
Cypress.env('baseUrl', url)
2930

31+
// prepare main cypress window so we can use axios there
32+
// and it will successfully fetch csrf tokens when needed.
33+
window.OC = {
34+
config: { modRewriteWorking: false },
35+
}
36+
// Prevent @nextcloud/router from reading window.location
37+
window._oc_webroot = url
38+
3039
Cypress.Commands.add('openLeftSidebar', () => {
3140
cy.get('.app-navigation button.app-navigation-toggle').click()
3241
})
@@ -106,16 +115,24 @@ Cypress.Commands.add('getNavigationEntry', (boardTitle) => {
106115
.find('a.app-navigation-entry-link')
107116
})
108117

109-
Cypress.Commands.add('shareBoardWithUi', (userId) => {
110-
cy.intercept({ method: 'GET', url: `**/ocs/v2.php/apps/files_sharing/api/v1/sharees?search=${userId}*` }).as('fetchRecipients')
118+
Cypress.Commands.add('shareBoardWithUi', (query, userId=query) => {
119+
cy.intercept({ method: 'GET', url: `**/ocs/v2.php/apps/files_sharing/api/v1/sharees?search=${query}*` }).as('fetchRecipients')
111120
cy.get('[aria-label="Open details"]').click()
112121
cy.get('.app-sidebar').should('be.visible')
113122
cy.get('.select input').click()
114-
cy.get('.select input').type(`${userId}`)
123+
cy.get('.select input').type(`${query}`)
115124
cy.wait('@fetchRecipients', { timeout: 7000 })
116125

117-
cy.get('.vs__dropdown-menu .option').first().contains(userId)
126+
cy.get('.vs__dropdown-menu .option').first().contains(query)
118127
cy.get('.select input').type('{enter}')
119128

120129
cy.get('.shareWithList').contains(userId)
121130
})
131+
132+
Cypress.Commands.add('setUserEmail', (user, value) => {
133+
Cypress.log()
134+
return axios.put(
135+
`${url}/ocs/v2.php/cloud/users/${user.userId}`,
136+
{ key: 'email', value },
137+
)
138+
})

src/components/board/SharingTabSidebar.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ export default {
137137
},
138138
formatedSharees() {
139139
return this.unallocatedSharees.map(item => {
140+
const subname = item.label === item.shareWithDisplayNameUnique
141+
? ''
142+
: item.shareWithDisplayNameUnique
140143
const sharee = {
141144
user: item.value.shareWith,
142145
displayName: item.label,
146+
subname,
143147
icon: 'icon-user',
144148
multiselectKey: item.shareType + ':' + item.primaryKey,
145149
}

0 commit comments

Comments
 (0)