From e15654b2a5c00ce10f8e8dfd846bd36293dbed5d Mon Sep 17 00:00:00 2001 From: Mel <97147377+MelissaAutumn@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:10:16 -0800 Subject: [PATCH] Features/228 signed url store (#229) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ➕ move navbar avatar to separate component (cherry picked from commit 2d5dc901b9f5c1a515307eafd83ff7dda10dd6ad) * ➕ add signed url to user store (cherry picked from commit 5adee893e848ff9993b31d1074bd2471a315e067) --------- Co-authored-by: Andreas Müller --- frontend/src/components/NavBar.vue | 38 ++++---------------- frontend/src/components/ScheduleCreation.vue | 25 +++---------- frontend/src/components/SettingsAccount.vue | 29 ++++----------- frontend/src/elements/Avatar.vue | 19 ++++++++++ frontend/src/stores/user-store.js | 27 +++++++++++++- 5 files changed, 61 insertions(+), 77 deletions(-) create mode 100644 frontend/src/elements/Avatar.vue diff --git a/frontend/src/components/NavBar.vue b/frontend/src/components/NavBar.vue index cc7d0c32a..0d71129ef 100644 --- a/frontend/src/components/NavBar.vue +++ b/frontend/src/components/NavBar.vue @@ -37,17 +37,7 @@ diff --git a/frontend/src/components/ScheduleCreation.vue b/frontend/src/components/ScheduleCreation.vue index e517831a2..62d5b8d97 100644 --- a/frontend/src/components/ScheduleCreation.vue +++ b/frontend/src/components/ScheduleCreation.vue @@ -267,9 +267,9 @@
@@ -301,7 +301,7 @@ :open="savedConfirmation.show" :is-schedule="true" :title="savedConfirmation.title" - :public-link="publicLink" + :public-link="user.data.signedUrl" @close="closeCreatedModal" /> @@ -475,15 +475,6 @@ const resetSchedule = () => { state.value = scheduleCreationState.details; }; -// hold public availability link of user -const publicLink = ref(''); -onMounted(async () => { - const { data, error } = await call('me/signature').get().json(); - if (!error.value) { - publicLink.value = data.value.url; - } -}); - // handle actual schedule creation/update const savingInProgress = ref(false); const saveSchedule = async (withConfirmation = true) => { @@ -519,17 +510,9 @@ const saveSchedule = async (withConfirmation = true) => { return; } - if (withConfirmation) { - // Retrieve the user short url - const { data: sig_data, error: sig_error } = await call('me/signature').get().json(); - if (sig_error.value) { - savingInProgress.value = false; - return; - } - + if (withConfirmation) { // show confirmation savedConfirmation.title = data.value.name; - publicLink.value = sig_data.value.url; savedConfirmation.show = true; } diff --git a/frontend/src/components/SettingsAccount.vue b/frontend/src/components/SettingsAccount.vue index 0d59918c4..fe6fe9dfb 100644 --- a/frontend/src/components/SettingsAccount.vue +++ b/frontend/src/components/SettingsAccount.vue @@ -30,16 +30,16 @@
- +
@@ -177,9 +177,6 @@ const deleteAccountSecondModalOpen = ref(false); const refreshLinkModalOpen = ref(false); const updateUsernameModalOpen = ref(false); -// calculate signed link -const signedUserUrl = ref(''); - const closeModals = () => { downloadAccountModalOpen.value = false; deleteAccountFirstModalOpen.value = false; @@ -188,18 +185,8 @@ const closeModals = () => { updateUsernameModalOpen.value = false; }; -const getSignedUserUrl = async () => { - // Retrieve the user short url - const { data, error } = await call('me/signature').get().json(); - if (error.value) { - return; - } - - signedUserUrl.value = data.value.url; -}; - const refreshData = async () => Promise.all([ - getSignedUserUrl(), + user.updateSignedUrl(call), externalConnectionsStore.fetch(call), ]); @@ -214,6 +201,7 @@ const updateUser = async () => { if (!error.value) { // update user in store user.$patch({ data: { ...user.data, ...inputData }}); + await user.updateSignedUrl(call); errorUsername.value = false; // TODO show some confirmation await refreshData(); @@ -270,12 +258,7 @@ const refreshLink = async () => { }; const refreshLinkConfirm = async () => { - const { data, error } = await call('me/signature').post().json(); - - if (error.value) { - console.log('Error!', data.value); - } - + await user.changeSignedUrl(call); await refreshData(); closeModals(); }; diff --git a/frontend/src/elements/Avatar.vue b/frontend/src/elements/Avatar.vue new file mode 100644 index 000000000..f114e2668 --- /dev/null +++ b/frontend/src/elements/Avatar.vue @@ -0,0 +1,19 @@ + + + diff --git a/frontend/src/stores/user-store.js b/frontend/src/stores/user-store.js index c9387a59b..a62a726e3 100644 --- a/frontend/src/stores/user-store.js +++ b/frontend/src/stores/user-store.js @@ -7,6 +7,7 @@ const initialUserObject = { name: null, timezone: null, username: null, + signedUrl: null, avatarUrl: null, accessToken: null, }; @@ -42,8 +43,32 @@ export const useUserStore = defineStore('user', { } }); + return await this.signedUrl(fetch); + }, + // retrieve the current signed url and update store + async updateSignedUrl(fetch) { + const { error, data } = await fetch('me/signature').get().json(); + + if (error.value || !data.value.url) { + console.error(error.value, data.value); + return false; + } + + this.data.signedUrl = data.value.url; + return true; }, + // invalidate the current signed url and replace it with a new one + async changeSignedUrl(fetch) { + const { error, data } = await fetch('me/signature').post().json(); + + if (error.value) { + console.error(error.value, data.value); + return false; + } + + return this.updateSignedUrl(fetch); + }, async login(fetch, username, password) { this.reset(); @@ -67,7 +92,7 @@ export const useUserStore = defineStore('user', { return await this.profile(fetch); }, async logout(fetch) { - const { error, data } = await fetch('logout').get().json(); + const { error } = await fetch('logout').get().json(); if (error.value) { console.warn("Error logging out: ", error.value);