From 9cc07b05a154c9af3c9fcf962bf09abddea87576 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Tue, 18 Jun 2024 00:26:22 +0100 Subject: [PATCH] fix(DavClient): Provide proper feedback for dav requests Before this commit there is no error handling whatsover for this requests and the user won't get any visual feedback whatsover irrespective of what goes down at the server level. Signed-off-by: fenn-cs --- src/client.js | 22 ++++++++++++++++++++-- src/components/SharingSidebarView.vue | 15 +++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/client.js b/src/client.js index 561201107..78aeae86f 100644 --- a/src/client.js +++ b/src/client.js @@ -252,12 +252,30 @@ class AclDavService { propPatch(model, acls) { const aclList = [] for (const i in acls) { - aclList.push({ type: ACL_PROPERTIES.PROPERTY_ACL_ENTRY, data: acls[i].getProperties() }) + aclList.push({ type: ACL_PROPERTIES.PROPERTY_ACL_ENTRY, data: acls[i].getProperties() }) } const props = {} props[ACL_PROPERTIES.PROPERTY_ACL_LIST] = aclList + return client._client.propPatch(client._client.baseUrl + model.path.replaceAll('#', '%23') + '/' + encodeURIComponent(model.name), props) - } + .then(response => { + if (response.status === 207) { + return response + } else if (response.status === 403) { + // Handle permission denied scenario + console.error('Permission denied:', response.status, response.statusText) + throw new Error(t('groupfolders', 'Permission denied. User does not have sufficient permissions.')) + } else { + // Handle unexpected status codes + console.error('Unexpected status:', response.status, response.statusText) + throw new Error(t('groupfolders', 'Unexpected status from server')) + } + }).catch(error => { + // Handle network errors or exceptions + console.error('Error in propPatch:', error) + throw error + }) + } } diff --git a/src/components/SharingSidebarView.vue b/src/components/SharingSidebarView.vue index 27a4ac9b1..75e769800 100644 --- a/src/components/SharingSidebarView.vue +++ b/src/components/SharingSidebarView.vue @@ -355,7 +355,7 @@ export default { }) }, - changePermission(item, permission, $event) { + async changePermission(item, permission, $event) { const index = this.list.indexOf(item) const inherit = $event === STATES.INHERIT_ALLOW || $event === STATES.INHERIT_DENY || $event === STATES.INHERIT_DEFAULT const allow = $event === STATES.SELF_ALLOW @@ -374,9 +374,16 @@ export default { } item.inherited = false Vue.set(this.list, index, item) - client.propPatch(this.model, this.list.filter(rule => !rule.inherited)).then(() => { - // TODO block UI during save - }) + // TODO: Block UI during save + try { + await client.propPatch(this.model, this.list.filter(rule => !rule.inherited)) + console.debug('Permissions updated successfully') + } catch (error) { + console.error('Failed to save changes:', error) + showError(error) + } finally { + // TODO: Unblock the UI after the operation completes + } }, }, }