Skip to content

Commit 881e091

Browse files
Sukanya Pandeyrfrandse
authored andcommitted
Show error toast notification on unauthorized access
-When 403 status code which is an unauthorized access occured -show error toast notification. Signed-off-by: Sukanya Pandey <[email protected]> Change-Id: I55fa7052073f87f28c3584b68fd4e84247a4237e
1 parent a5aa0f5 commit 881e091

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

src/components/AppHeader/AppHeader.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
</template>
9595

9696
<script>
97+
import BVToastMixin from '@/components/Mixins/BVToastMixin';
9798
import IconAvatar from '@carbon/icons-vue/es/user--avatar/20';
9899
import IconClose from '@carbon/icons-vue/es/close/20';
99100
import IconMenu from '@carbon/icons-vue/es/menu/20';
@@ -111,13 +112,17 @@ export default {
111112
StatusIcon,
112113
LoadingBar
113114
},
115+
mixins: [BVToastMixin],
114116
data() {
115117
return {
116118
isNavigationOpen: false,
117119
altLogo: `${process.env.VUE_APP_COMPANY_NAME} logo`
118120
};
119121
},
120122
computed: {
123+
isAuthorized() {
124+
return this.$store.getters['global/isAuthorized'];
125+
},
121126
hostStatus() {
122127
return this.$store.getters['global/hostStatus'];
123128
},
@@ -153,6 +158,16 @@ export default {
153158
return this.$store.getters['global/username'];
154159
}
155160
},
161+
watch: {
162+
isAuthorized(value) {
163+
if (value === false) {
164+
this.errorToast(
165+
this.$t('global.toast.unAuthDescription'),
166+
this.$t('global.toast.unAuthTitle')
167+
);
168+
}
169+
}
170+
},
156171
created() {
157172
this.getHostInfo();
158173
this.getEvents();

src/locales/en-US.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"selectedItems":"%{filterCount} of %{count} items",
7373
"toDate": "To date",
7474
"viewAll": "View all"
75+
},
76+
"toast": {
77+
"unAuthTitle": "Unauthorized",
78+
"unAuthDescription": "The attempted action is not accessible from the logged in account. Contact your system administrator to check your privilege role."
7579
}
7680
},
7781
"appHeader": {
@@ -134,7 +138,6 @@
134138
"serverPowerOperations": "Server power operations",
135139
"snmpSettings": "SNMP settings",
136140
"sslCertificates": "SSL certificates",
137-
"unauthorized": "Unauthorized",
138141
"virtualMedia": "Virtual media"
139142
},
140143
"pageChangePassword": {
@@ -645,9 +648,6 @@
645648
"successReplaceCertificate": "Successfully replaced %{certificate}."
646649
}
647650
},
648-
"pageUnauthorized": {
649-
"description": "The attempted action is not accessible from the logged in account. Contact your system administrator to check your privilege role."
650-
},
651651
"pageVirtualMedia": {
652652
"configureConnection": "Configure Connection",
653653
"defaultDeviceName": "Virtual media device",

src/router/routes.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import SerialOverLanConsole from '@/views/Control/SerialOverLan/SerialOverLanCon
2323
import ServerLed from '@/views/Control/ServerLed';
2424
import ServerPowerOperations from '@/views/Control/ServerPowerOperations';
2525
import SslCertificates from '@/views/AccessControl/SslCertificates';
26-
import Unauthorized from '@/views/Unauthorized';
2726
import VirtualMedia from '@/views/Control/VirtualMedia';
2827
import i18n from '@/i18n';
2928

@@ -227,14 +226,6 @@ const routes = [
227226
title: i18n.t('appPageTitle.virtualMedia')
228227
}
229228
},
230-
{
231-
path: '/unauthorized',
232-
name: 'unauthorized',
233-
component: Unauthorized,
234-
meta: {
235-
title: i18n.t('appPageTitle.unauthorized')
236-
}
237-
},
238229
{
239230
path: '*',
240231
name: 'page-not-found',

src/store/api.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import Axios from 'axios';
2-
import router from '@/router';
3-
42
//Do not change store import.
53
//Exact match alias set to support
64
//dotenv customizations.
@@ -23,14 +21,10 @@ api.interceptors.response.use(undefined, error => {
2321
}
2422

2523
if (response.status == 403) {
26-
if (router.history.current.name === 'unauthorized') {
27-
// Check if current router location is unauthorized
28-
// to avoid NavigationDuplicated errors.
29-
// The router throws an error if trying to push to the
30-
// same/current router location.
31-
return;
32-
}
33-
router.push({ name: 'unauthorized' });
24+
// Check if action is unauthorized.
25+
// Toast error message will appear on screen
26+
// when the action is unauthorized.
27+
store.commit('global/setUnauthorized');
3428
}
3529

3630
return Promise.reject(error);

src/store/modules/GlobalStore.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ const GlobalStore = {
3535
isUtcDisplay: localStorage.getItem('storedUtcDisplay')
3636
? JSON.parse(localStorage.getItem('storedUtcDisplay'))
3737
: true,
38-
username: localStorage.getItem('storedUsername')
38+
username: localStorage.getItem('storedUsername'),
39+
isAuthorized: true
3940
},
4041
getters: {
4142
hostStatus: state => state.hostStatus,
4243
bmcTime: state => state.bmcTime,
4344
languagePreference: state => state.languagePreference,
4445
isUtcDisplay: state => state.isUtcDisplay,
45-
username: state => state.username
46+
username: state => state.username,
47+
isAuthorized: state => state.isAuthorized
4648
},
4749
mutations: {
4850
setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime),
@@ -51,7 +53,13 @@ const GlobalStore = {
5153
setLanguagePreference: (state, language) =>
5254
(state.languagePreference = language),
5355
setUsername: (state, username) => (state.username = username),
54-
setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay)
56+
setUtcTime: (state, isUtcDisplay) => (state.isUtcDisplay = isUtcDisplay),
57+
setUnauthorized: state => {
58+
state.isAuthorized = false;
59+
window.setTimeout(() => {
60+
state.isAuthorized = true;
61+
}, 100);
62+
}
5563
},
5664
actions: {
5765
async getBmcTime({ commit }) {

src/views/Unauthorized/Unauthorized.vue

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/views/Unauthorized/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)