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>
diff --git a/src/router/index.js b/src/router/index.js
index bcb2c7a..5b6d909 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -42,13 +42,9 @@
   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 0dca183..5727015 100644
--- a/src/store/modules/Authentication/AuthenticanStore.js
+++ b/src/store/modules/Authentication/AuthenticanStore.js
@@ -61,10 +61,13 @@
         .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 96b4c9e..db475c5 100644
--- a/src/views/Login/Login.vue
+++ b/src/views/Login/Login.vue
@@ -124,15 +124,12 @@
           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));