summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Fertser <fercerpav@gmail.com>2024-04-10 19:27:53 +0300
committerGunnar Mills <gunnar@gmills.xyz>2024-04-25 23:16:55 +0300
commitbceafface3899539006e8f04717e7fd5bf491ac5 (patch)
tree304d8d8138a2387946b5bafaf708bcbec6ad0b6f /src
parent51abe87feea7261ec6f7589d8214af3d8019e71e (diff)
downloadwebui-vue-bceafface3899539006e8f04717e7fd5bf491ac5.tar.xz
Deduplicate and simplify RoleId handling
To improve UX for users of accounts with restricted permissions the frontend determines the current RoleId. Knowing that it can hide menus and inhibit transitions that are not allowed by the backend in any case. This patch unifies the handling by moving processing of the API reply containing RoleId in the single place, right where `authentication/getUserInfo` store gets it. This makes the program flow easier to understand and change if needed without worrying of where another copy of the code might be and how it would need to be amended. No functional change. Tested: logging in and out, navigating the pages, getting an error message when wrong credentials are used, reloading the page with an established session. All while observing Network and Console tabs in Web Developer tools, no unexpected API requests are made and no unexpected errors reported. Confirmed in debugger that the retrieved role gets stored and used for routing restrictions. Change-Id: Ia8782f44cb6bf813954d30b8bf3a620a626ad455 Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/router/index.js10
-rw-r--r--src/store/modules/Authentication/AuthenticanStore.js7
-rw-r--r--src/views/Login/Login.vue5
3 files changed, 9 insertions, 13 deletions
diff --git a/src/router/index.js b/src/router/index.js
index bcb2c7a2..5b6d9099 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -42,13 +42,9 @@ router.beforeEach((to, from, next) => {
if (!currentUserRole && store.getters['authentication/isLoggedIn']) {
// invoke API call to get the role ID
let username = localStorage.getItem('storedUsername');
- store.dispatch('authentication/getUserInfo', username).then((response) => {
- if (response?.RoleId) {
- // set role ID
- store.commit('global/setPrivilege', response.RoleId);
- // allow the route to continue
- allowRouterToNavigate(to, next, response.RoleId);
- }
+ store.dispatch('authentication/getUserInfo', username).then(() => {
+ let currentUserRole = store.getters['global/userPrivilege'];
+ allowRouterToNavigate(to, next, currentUserRole);
});
} else {
allowRouterToNavigate(to, next, currentUserRole);
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js
index 0dca1832..57270159 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -61,10 +61,13 @@ const AuthenticationStore = {
.then(() => router.push('/login'))
.catch((error) => console.log(error));
},
- getUserInfo(_, username) {
+ getUserInfo({ commit }, username) {
return api
.get(`/redfish/v1/AccountService/Accounts/${username}`)
- .then(({ data }) => data)
+ .then(({ data }) => {
+ commit('global/setPrivilege', data.RoleId, { root: true });
+ return data;
+ })
.catch((error) => console.log(error));
},
resetStoreState({ state }) {
diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue
index 96b4c9e8..db475c56 100644
--- a/src/views/Login/Login.vue
+++ b/src/views/Login/Login.vue
@@ -124,15 +124,12 @@ export default {
this.$store.commit('global/setLanguagePreference', i18n.locale);
return this.$store.dispatch('authentication/getUserInfo', username);
})
- .then(({ PasswordChangeRequired, RoleId }) => {
+ .then(({ PasswordChangeRequired }) => {
if (PasswordChangeRequired) {
this.$router.push('/change-password');
} else {
this.$router.push('/');
}
- if (RoleId) {
- this.$store.commit('global/setPrivilege', RoleId);
- }
})
.catch((error) => console.log(error))
.finally(() => (this.disableSubmitButton = false));