From db90a8cde4cd67857718c557834ac87c106b211e Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 15 Jan 2021 20:56:51 +0100 Subject: [PATCH] Fix caldav url not containing the api url if the frontend and api are on the same domain --- src/views/user/Settings.vue | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/views/user/Settings.vue b/src/views/user/Settings.vue index aa49f4b40..1bd5afe8f 100644 --- a/src/views/user/Settings.vue +++ b/src/views/user/Settings.vue @@ -299,8 +299,6 @@ export default { totpDisableForm: false, totpDisablePassword: '', - caldavUrl: '', - settings: UserSettingsModel, userSettingsService: UserSettingsService, } @@ -325,17 +323,29 @@ export default { }) this.totpStatus() - this.buildCaldavUrl() }, mounted() { this.setTitle('Settings') }, - computed: mapState({ - totpEnabled: state => state.config.totpEnabled, - migratorsEnabled: state => state.config.availableMigrators !== null && state.config.availableMigrators.length > 0, - caldavEnabled: state => state.config.caldavEnabled, - userInfo: state => state.auth.info, - }), + computed: { + caldavUrl() { + let apiBase = window.API_URL.replace('/api/v1', '') + if (apiBase === '') { // Frontend and api on the same host which means we need to prefix the frontend url + apiBase = this.$store.state.config.frontendUrl + } + if (apiBase.endsWith('/')) { + apiBase = apiBase.substr(0, apiBase.length - 1) + } + + return `${apiBase}/dav/principals/${this.userInfo.username}/` + }, + ...mapState({ + totpEnabled: state => state.config.totpEnabled, + migratorsEnabled: state => state.config.availableMigrators !== null && state.config.availableMigrators.length > 0, + caldavEnabled: state => state.config.caldavEnabled, + userInfo: state => state.auth.info, + }) + }, methods: { updatePassword() { if (this.passwordConfirm !== this.passwordUpdate.newPassword) { @@ -416,10 +426,6 @@ export default { }) .catch(e => this.error(e, this)) }, - buildCaldavUrl() { - const apiBase = window.API_URL.replace('/api/v1', '') - this.caldavUrl = `${apiBase}/dav/principals/${this.userInfo.username}/` - }, copy(text) { copy(text) },