Skip to content

Commit

Permalink
enh: refactor items for searching users and groups
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <[email protected]>
  • Loading branch information
enjeck committed Jun 15, 2024
1 parent 2606ef0 commit ef7e9f2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 80 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/tables-table.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Manage a table', () => {
cy.get('[data-cy="editTableModal"]').should('not.exist')
cy.get('[data-cy="transferTableModal"]').should('be.visible')
cy.get('[data-cy="transferTableModal"] input[type="search"]').clear().type(targetUserTransfer.userId)
cy.get(`.vs__dropdown-menu [user="${targetUserTransfer.userId}"]`).click()
cy.get(`.vs__dropdown-menu [id="${targetUserTransfer.userId}"]`).click()
cy.get('[data-cy="transferTableButton"]').should('be.enabled').click()
cy.get('.toastify.toast-success').should('be.visible')
cy.get('.app-navigation__list').contains('test table').should('not.exist')
Expand Down
2 changes: 1 addition & 1 deletion src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default {
sharing = sharing.filter((share) => getCurrentUser().uid !== share.receiver)
const receivers = sharing.map((share) => {
return {
user: share.receiver,
id: share.receiver,
displayName: share.receiver_display_name,
icon: share.receiver_type === 'user' ? 'icon-user' : 'icon-group',
isUser: share.receiver_type === 'user',
Expand Down
28 changes: 14 additions & 14 deletions src/modules/sidebar/partials/ShareForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ import debounce from 'debounce'
import { NcSelect } from '@nextcloud/vue'
import { mapState } from 'vuex'
import formatting from '../../../shared/mixins/formatting.js'
import ShareTypes from '../../../shared/mixins/shareTypesMixin.js'
import { SHARE_TYPES } from '../../../shared/constants.js'
export default {
name: 'ShareForm',
components: {
NcSelect,
},
mixins: [ShareTypes, formatting],
mixins: [formatting],
props: {
shares: {
Expand Down Expand Up @@ -160,8 +160,8 @@ export default {
this.loading = true
const shareType = [
this.SHARE_TYPES.SHARE_TYPE_USER,
this.SHARE_TYPES.SHARE_TYPE_GROUP,
SHARE_TYPES.SHARE_TYPE_USER,
SHARE_TYPES.SHARE_TYPE_GROUP,
]
const request = await axios.get(generateOcsUrl('apps/files_sharing/api/v1/sharees'), {
Expand Down Expand Up @@ -248,7 +248,7 @@ export default {
try {
// filter out current user
if (share.value.shareType === this.SHARE_TYPES.SHARE_TYPE_USER
if (share.value.shareType === SHARE_TYPES.SHARE_TYPE_USER
&& share.value.shareWith === getCurrentUser().uid) {
return arr
}
Expand All @@ -274,7 +274,7 @@ export default {
shareWith: result.value.shareWith,
shareType: result.value.shareType,
user: result.uuid || result.value.shareWith,
isNoUser: result.value.shareType !== this.SHARE_TYPES.SHARE_TYPE_USER,
isNoUser: result.value.shareType !== SHARE_TYPES.SHARE_TYPE_USER,
displayName: result.name || result.label,
icon: this.shareTypeToIcon(result.value.shareType),
// Vue unique binding to render within Multiselect's AvatarSelectOption
Expand All @@ -290,20 +290,20 @@ export default {
*/
shareTypeToIcon(type) {
switch (type) {
case this.SHARE_TYPES.SHARE_TYPE_GUEST:
case SHARE_TYPES.SHARE_TYPE_GUEST:
// default is a user, other icons are here to differenciate
// themselves from it, so let's not display the user icon
// case this.SHARE_TYPES.SHARE_TYPE_REMOTE:
// case this.SHARE_TYPES.SHARE_TYPE_USER:
// case SHARE_TYPES.SHARE_TYPE_REMOTE:
// case SHARE_TYPES.SHARE_TYPE_USER:
return 'icon-user'
case this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP:
case this.SHARE_TYPES.SHARE_TYPE_GROUP:
case SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP:
case SHARE_TYPES.SHARE_TYPE_GROUP:
return 'icon-group'
case this.SHARE_TYPES.SHARE_TYPE_EMAIL:
case SHARE_TYPES.SHARE_TYPE_EMAIL:
return 'icon-mail'
case this.SHARE_TYPES.SHARE_TYPE_CIRCLE:
case SHARE_TYPES.SHARE_TYPE_CIRCLE:
return 'icon-circle'
case this.SHARE_TYPES.SHARE_TYPE_ROOM:
case SHARE_TYPES.SHARE_TYPE_ROOM:
return 'icon-room'
default:
Expand Down
16 changes: 5 additions & 11 deletions src/shared/components/ncContextResource/ResourceSharees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import { NcSelect } from '@nextcloud/vue'
import formatting from '../../../shared/mixins/formatting.js'
import searchUserGroup from '../../../shared/mixins/searchUserGroup.js'
import ShareTypes from '../../mixins/shareTypesMixin.js'
import '@nextcloud/dialogs/style.css'
export default {
Expand All @@ -31,7 +30,7 @@ export default {
NcSelect,
},
mixins: [ShareTypes, formatting, searchUserGroup],
mixins: [formatting, searchUserGroup],
props: {
receivers: {
Expand All @@ -50,9 +49,8 @@ export default {
data() {
return {
value: '',
preExistingSharees: [...this.receivers],
localSharees: this.receivers.map(userObject => userObject.user),
localSharees: this.receivers.map(userObject => userObject.id),
}
},
Expand All @@ -62,19 +60,15 @@ export default {
return this.localSharees
},
set(v) {
this.localSharees = v.map(userObject => userObject.user)
this.localSharees = v.map(userObject => userObject.id)
this.$emit('update', v)
},
},
},
methods: {
addShare(selectedItem) {
if (selectedItem) {
this.localValue = selectedItem
} else {
this.localValue = []
}
this.localValue = selectedItem
},
filterOutUnwantedItems(list) {
Expand All @@ -83,7 +77,7 @@ export default {
},
filterOutSelectedUsers(list) {
return list.filter((item) => !(item.isUser && this.localSharees.includes(item.user)))
return list.filter((item) => !(item.isUser && this.localSharees.includes(item.id)))
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<script>
import { NcSelect } from '@nextcloud/vue'
import formatting from '../../../shared/mixins/formatting.js'
import ShareTypes from '../../mixins/shareTypesMixin.js'
import '@nextcloud/dialogs/style.css'
import searchUserGroup from '../../../shared/mixins/searchUserGroup.js'
Expand All @@ -24,7 +23,7 @@ export default {
NcSelect,
},
mixins: [ShareTypes, formatting, searchUserGroup],
mixins: [formatting, searchUserGroup],
props: {
newOwnerUserId: {
Expand Down Expand Up @@ -53,18 +52,14 @@ export default {
return this.newOwnerUserId
},
set(v) {
this.$emit('update:newOwnerUserId', v)
this.$emit('update:newOwnerUserId', v?.id)
},
},
},
methods: {
addTransfer(selectedItem) {
if (selectedItem) {
this.localValue = selectedItem.user
} else {
this.localValue = ''
}
this.localValue = selectedItem
},
filterOutUnwantedItems(list) {
return this.filterOutCurrentUser(list)
Expand Down
12 changes: 12 additions & 0 deletions src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ export const TYPE_SELECTION = 'selection'
export const TYPE_TEXT = 'text'
export const TYPE_NUMBER = 'number'
export const TYPE_DATETIME = 'datetime'

export const SHARE_TYPES = {
SHARE_TYPE_USER: OC.Share.SHARE_TYPE_USER,
SHARE_TYPE_GROUP: OC.Share.SHARE_TYPE_GROUP,
SHARE_TYPE_LINK: OC.Share.SHARE_TYPE_LINK,
SHARE_TYPE_EMAIL: OC.Share.SHARE_TYPE_EMAIL,
SHARE_TYPE_REMOTE: OC.Share.SHARE_TYPE_REMOTE,
SHARE_TYPE_CIRCLE: OC.Share.SHARE_TYPE_CIRCLE,
SHARE_TYPE_GUEST: OC.Share.SHARE_TYPE_GUEST,
SHARE_TYPE_REMOTE_GROUP: OC.Share.SHARE_TYPE_REMOTE_GROUP,
SHARE_TYPE_ROOM: OC.Share.SHARE_TYPE_ROOM,
}
9 changes: 5 additions & 4 deletions src/shared/mixins/searchUserGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getCurrentUser } from '@nextcloud/auth'
import debounce from 'debounce'
import { showError } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/style.css'
import { SHARE_TYPES } from '../constants.js'

export default {
data() {
Expand Down Expand Up @@ -41,10 +42,10 @@ export default {
getShareTypes() {
const types = []
if (this.selectUsers) {
types.push(this.SHARE_TYPES.SHARE_TYPE_USER)
types.push(SHARE_TYPES.SHARE_TYPE_USER)
}
if (this.selectGroups) {
types.push(this.SHARE_TYPES.SHARE_TYPE_GROUP)
types.push(SHARE_TYPES.SHARE_TYPE_GROUP)
}
return types
},
Expand Down Expand Up @@ -80,7 +81,7 @@ export default {
const res = await axios.get(url)
const rawSuggestions = res.data.ocs.data.map(autocompleteResult => {
return {
user: autocompleteResult.id,
id: autocompleteResult.id,
displayName: autocompleteResult.label,
icon: autocompleteResult.icon,
isUser: autocompleteResult.source.startsWith('users'),
Expand All @@ -99,7 +100,7 @@ export default {
}, 300),

filterOutCurrentUser(list) {
return list.filter((item) => !(item.isUser && item.user === getCurrentUser().uid))
return list.filter((item) => !(item.isUser && item.id === getCurrentUser().uid))
},
},
}
39 changes: 0 additions & 39 deletions src/shared/mixins/shareTypesMixin.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default new Vuex.Store({
try {
for (const receiver of receivers) {
share.receiverType = receiver.isUser ? 'user' : 'group'
share.receiver = receiver.user
share.receiver = receiver.id
// Avoid duplicate shares by checking if share exists first
const existingShare = previousReceivers.find((p) => p.receiver === share.receiver && p.receiver_type === share.receiverType)
if (!existingShare) {
Expand All @@ -363,7 +363,7 @@ export default new Vuex.Store({
for (const previousReceiver of previousReceivers) {
const currentShare = receivers.find((r) => {
const receiverType = r.isUser ? 'user' : 'group'
return r.user === previousReceiver.receiver && receiverType === previousReceiver.receiver_type
return r.id === previousReceiver.receiver && receiverType === previousReceiver.receiver_type
})
if (!currentShare) {
await axios.delete(generateUrl('/apps/tables/share/' + previousReceiver.share_id))
Expand Down

0 comments on commit ef7e9f2

Please sign in to comment.