From 3ff27505fc99961a722c9b0c62d48cb2ce0ee9a9 Mon Sep 17 00:00:00 2001 From: Cleopatra Enjeck M Date: Thu, 11 Apr 2024 08:39:42 +0100 Subject: [PATCH] enh: share context via api request Signed-off-by: Cleopatra Enjeck M --- src/modules/modals/EditContext.vue | 21 ++++++---- .../ncContextResource/NcContextResource.vue | 40 ++++++++++--------- .../ncContextResource/ResourceSharees.vue | 8 ++-- src/store/store.js | 7 +++- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/modules/modals/EditContext.vue b/src/modules/modals/EditContext.vue index 3db4d7a57..09b50cb3a 100644 --- a/src/modules/modals/EditContext.vue +++ b/src/modules/modals/EditContext.vue @@ -12,11 +12,8 @@
- + @@ -36,7 +33,7 @@
{{ t('tables', 'Resources') }}
- +
@@ -90,6 +87,7 @@ export default { description: '', errorTitle: false, resources: [], + receivers: [], } }, computed: { @@ -113,6 +111,7 @@ export default { this.setIcon(this.localContext.iconName) this.description = context.description this.resources = context ? [...this.getContextResources(context)] : [] + this.receivers = context && context?.sharing ? [...context.sharing] : [] } }, }, @@ -145,7 +144,14 @@ export default { description: this.description, nodes: dataResources, } - const res = await this.$store.dispatch('updateContext', { id: this.contextId, data }) + + const share = { + nodeType: 'context', + nodeId: this.contextId, + receiverType: 'user', + displayMode: 2, + } + const res = await this.$store.dispatch('updateContext', { id: this.contextId, data, share, receivers: this.receivers }) if (res) { showSuccess(t('tables', 'Updated context "{contextTitle}".', { contextTitle: this.title })) this.actionCancel() @@ -159,6 +165,7 @@ export default { this.icon.name = 'equalizer' this.description = '' this.resources = context ? [...this.getContextResources(context)] : [] + this.receivers = context && context?.sharing ? [...context.sharing] : [] }, getContextResources(context) { const resources = [] diff --git a/src/shared/components/ncContextResource/NcContextResource.vue b/src/shared/components/ncContextResource/NcContextResource.vue index 1c120942c..10d7fecb7 100644 --- a/src/shared/components/ncContextResource/NcContextResource.vue +++ b/src/shared/components/ncContextResource/NcContextResource.vue @@ -3,7 +3,7 @@
- +
@@ -35,7 +35,7 @@ export default { type: Array, default: () => ([]), }, - sharees: { + receivers: { type: Array, default: () => ([]), }, @@ -45,22 +45,14 @@ export default { return { loading: false, contextResource: this.resources, - // currentSharees: [...this.sharees], - currentSharees: [ - { - user: 'user2', - displayName: 'user2', - icon: 'icon-user', - isUser: true, - key: 'users-user2', - }, - { - user: 'user1', - displayName: 'user1', - icon: 'icon-user', - isUser: true, - key: 'users-user1', - }, + contextReceivers: [ + // { + // user: 'user2', + // displayName: 'user2', + // icon: 'icon-user', + // isUser: true, + // key: 'users-user2', + // }, ], } }, @@ -75,6 +67,14 @@ export default { this.$emit('update:resources', v) }, }, + localReceivers: { + get() { + return this.contextReceivers + }, + set(v) { + this.$emit('update:receivers', v) + }, + }, }, methods: { @@ -85,7 +85,9 @@ export default { addResource(resource) { this.contextResource.push(resource) this.localResource = this.contextResource - + }, + updateReceivers(receivers) { + this.localReceivers = receivers }, }, diff --git a/src/shared/components/ncContextResource/ResourceSharees.vue b/src/shared/components/ncContextResource/ResourceSharees.vue index 698bba79f..314ac5d4b 100644 --- a/src/shared/components/ncContextResource/ResourceSharees.vue +++ b/src/shared/components/ncContextResource/ResourceSharees.vue @@ -36,7 +36,7 @@ export default { mixins: [ShareTypes, formatting], props: { - sharees: { + receivers: { type: Array, default: () => ([]), }, @@ -58,8 +58,8 @@ export default { minSearchStringLength: 1, maxAutocompleteResults: 20, suggestions: [], - preExistingSharees: [...this.sharees], - localSharees: this.sharees.map(userObject => userObject.user), + preExistingSharees: [...this.receivers], + localSharees: this.receivers.map(userObject => userObject.user), } }, @@ -70,7 +70,7 @@ export default { }, set(v) { this.localSharees = v.map(userObject => userObject.user) - this.$emit('update:sharees', v) + this.$emit('update', v) }, }, diff --git a/src/store/store.js b/src/store/store.js index 0095000dc..878e0ec8a 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -339,11 +339,16 @@ export default new Vuex.Store({ return true }, - async updateContext({ state, commit, dispatch }, { id, data }) { + async updateContext({ state, commit, dispatch }, { id, data, share, receivers }) { let res = null try { res = await axios.put(generateOcsUrl('/apps/tables/api/2/contexts/' + id), data) + for (const receiver of receivers) { + share.receiverType = receiver.isUser ? 'user' : 'group' + share.receiver = receiver.user + await axios.post(generateUrl('/apps/tables/share'), share) + } } catch (e) { displayError(e, t('tables', 'Could not update application.')) return false