From 39694aba8d34289f9d648a30eed718208380d24d Mon Sep 17 00:00:00 2001 From: davidjumani Date: Thu, 24 Sep 2020 17:32:46 +0530 Subject: [PATCH] Fixing login, session expired and blacklisted api requests Signed-off-by: Rohit Yadav --- ui/src/locales/en.json | 1 + ui/src/permission.js | 3 ++- ui/src/store/modules/user.js | 5 +++++ ui/src/utils/request.js | 19 ++++++++++++++++--- ui/src/views/AutogenView.vue | 18 +++++++++++------- ui/src/views/iam/DomainView.vue | 11 ++++------- 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/ui/src/locales/en.json b/ui/src/locales/en.json index b7af2d0bf28..5530fbd4f80 100644 --- a/ui/src/locales/en.json +++ b/ui/src/locales/en.json @@ -25,6 +25,7 @@ "error.release.dedicate.zone": "Failed to release dedicated zone", "error.session.expired": "Your session has expired.", "error.unable.to.reach.management.server": "Unable to reach Management Server", +"error.unable.to.proceed": "Unable to proceed. Please contact your administrator", "error.unresolved.internet.name": "Your internet name cannot be resolved.", "firewall.close": "Firewall", "force.delete.domain.warning": "Warning: Choosing this option will cause the deletion of all child domains and all associated accounts and their resources.", diff --git a/ui/src/permission.js b/ui/src/permission.js index 161a1b4c0f7..d22c00f6236 100644 --- a/ui/src/permission.js +++ b/ui/src/permission.js @@ -66,7 +66,8 @@ router.beforeEach((to, from, next) => { .catch(() => { notification.error({ message: 'Error', - description: i18n.t('message.error.discovering.feature') + description: i18n.t('message.error.discovering.feature'), + duration: 0 }) store.dispatch('Logout').then(() => { next({ path: '/user/login', query: { redirect: to.fullPath } }) diff --git a/ui/src/store/modules/user.js b/ui/src/store/modules/user.js index 76271ff60dc..aba087db58b 100644 --- a/ui/src/store/modules/user.js +++ b/ui/src/store/modules/user.js @@ -19,6 +19,7 @@ import Cookies from 'js-cookie' import Vue from 'vue' import md5 from 'md5' import message from 'ant-design-vue/es/message' +import notification from 'ant-design-vue/es/notification' import router from '@/router' import store from '@/store' import { login, logout, api } from '@/api' @@ -112,6 +113,8 @@ const user = { commit('SET_LDAP', {}) commit('SET_CLOUDIAN', {}) + notification.destroy() + resolve() }).catch(error => { reject(error) @@ -148,6 +151,8 @@ const user = { api('listZones', { listall: true }).then(json => { const zones = json.listzonesresponse.zone || [] commit('SET_ZONES', zones) + }).catch(error => { + reject(error) }) api('listApis').then(response => { const apis = {} diff --git a/ui/src/utils/request.js b/ui/src/utils/request.js index ffc62eb7ac9..9371aeee9bf 100644 --- a/ui/src/utils/request.js +++ b/ui/src/utils/request.js @@ -37,16 +37,29 @@ const err = (error) => { notification.error({ message: i18n.t('label.forbidden'), description: data.message }) } if (response.status === 401) { - if (response.config && response.config.params && ['listIdps'].includes(response.config.params.command)) { + if (response.config && response.config.params && ['listIdps', 'cloudianIsEnabled'].includes(response.config.params.command)) { return } + for (const key in response.data) { + if (key.includes('response')) { + if (response.data[key].errortext.includes('not available for user')) { + notification.error({ + message: 'Error', + description: response.data[key].errortext + ' ' + i18n.t('error.unable.to.proceed'), + duration: 0 + }) + return + } + } + } notification.error({ message: i18n.t('label.unauthorized'), description: i18n.t('message.authorization.failed'), - key: 'http-401' + key: 'http-401', + duration: 0 }) store.dispatch('Logout').then(() => { - router.go(0) + router.push({ path: '/user/login', query: { redirect: router.history.current.fullPath } }) }) } if (response.status === 404) { diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 22b42cfee1f..ed92b42d0ac 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -648,6 +648,10 @@ export default { } } }).catch(error => { + if ([401].includes(error.response.status)) { + return + } + if (Object.keys(this.searchParams).length > 0) { this.itemCount = 0 this.items = [] @@ -658,13 +662,6 @@ export default { return } - if ([401].includes(error.response.status)) { - store.dispatch('Logout').then(() => { - this.$router.push({ path: '/user/login', query: { redirect: this.$route.fullPath } }) - }) - return - } - this.$notifyError(error) if ([405].includes(error.response.status)) { @@ -892,6 +889,9 @@ export default { api(action.api, params).then(json => { this.handleResponse(json, resourceName, action, false) }).catch(error => { + if ([401].includes(error.response.status)) { + return + } this.$notifyError(error) }) }, @@ -992,6 +992,10 @@ export default { } this.closeAction() }).catch(error => { + if ([401].includes(error.response.status)) { + return + } + console.log(error) this.$notifyError(error) }).finally(f => { diff --git a/ui/src/views/iam/DomainView.vue b/ui/src/views/iam/DomainView.vue index 287ca56d5e6..12ba40b61d8 100644 --- a/ui/src/views/iam/DomainView.vue +++ b/ui/src/views/iam/DomainView.vue @@ -175,19 +175,16 @@ export default { this.resource = domains[0] || {} this.treeSelected = domains[0] || {} }).catch(error => { + if ([401].includes(error.response.status)) { + return + } + this.$notification.error({ message: this.$t('message.request.failed'), description: error.response.headers['x-description'], duration: 0 }) - if ([401].includes(error.response.status)) { - store.dispatch('Logout').then(() => { - this.$router.push({ path: '/user/login', query: { redirect: this.$route.fullPath } }) - }) - return - } - if ([405].includes(error.response.status)) { this.$router.push({ path: '/exception/403' }) }