Skip to content

Commit

Permalink
Extracting fetchInitialSettings and placing it in a routerGuard since…
Browse files Browse the repository at this point in the history
… it needs to be loaded on all pages.
  • Loading branch information
codyrancher committed May 31, 2024
1 parent 7d69ff2 commit 3e94be4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
15 changes: 15 additions & 0 deletions shell/config/router/guards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fetchInitialSettings } from '@shell/utils/settings';

/**
* All pages need access to the initial settings to get things like the favicon and color theme.
* This loads those settings for all pages so we can remove it from all other locations.
*/
export function loadInitialSettings(store) {
return async(to, from, next) => {
try {
await fetchInitialSettings(store);
} catch (ex) {}

next();
};
}
5 changes: 4 additions & 1 deletion shell/config/router/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue';
import Router from 'vue-router';
import Routes from '@shell/config/router/routes';
import { loadInitialSettings } from '@shell/config/router/guards';

Vue.use(Router);

Expand All @@ -12,9 +13,11 @@ export const routerOptions = {
fallback: false
};

export function extendRouter(config) {
export function extendRouter(config, store) {
const base = (config._app && config._app.basePath) || routerOptions.base;
const router = new Router({ ...routerOptions, base });

router.beforeEach(loadInitialSettings(store));

return router;
}
3 changes: 1 addition & 2 deletions shell/initialize/app-extended.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { installInjectedPlugins } from 'initialize/install-plugins.js';
*/
async function extendApp(vueApp) {
const config = { rancherEnv: process.env.rancherEnv, dashboardVersion: process.env.version };
const router = extendRouter(config);

const store = extendStore();
const router = extendRouter(config, store);

// Add this.$router into store actions/mutations
store.$router = router;
Expand Down
4 changes: 0 additions & 4 deletions shell/middleware/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
validateResource, setProduct, isLoggedIn, notLoggedIn, noAuth, tryInitialSetup, findMe
} from '@shell/utils/auth';
import { getClusterFromRoute, getProductFromRoute, getPackageFromRoute } from '@shell/utils/router';
import { fetchInitialSettings } from '@shell/utils/settings';

let beforeEachSetup = false;

Expand All @@ -24,9 +23,6 @@ export default async function({
let firstLogin = null;

try {
// Load settings, which will either be just the public ones if not logged in, or all if you are
await fetchInitialSettings(store);

const res = store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.FIRST_LOGIN);
const plSetting = store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.PL);

Expand Down
3 changes: 0 additions & 3 deletions shell/mixins/brand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CATALOG, MANAGEMENT } from '@shell/config/types';
import { SETTING } from '@shell/config/settings';
import { createCssVars } from '@shell/utils/color';
import { setTitle } from '@shell/config/private-label';
import { fetchInitialSettings } from '@shell/utils/settings';
import { setFavIcon, haveSetFavIcon } from '@shell/utils/favicon';

const cspAdaptorApp = ['rancher-csp-adapter', 'rancher-csp-billing-adapter'];
Expand All @@ -23,8 +22,6 @@ export default {

// Ensure we read the settings even when we are not authenticated
try {
await fetchInitialSettings(this.$store);

// The favicon is implicitly dependent on the initial settings having already been fetched
if (!haveSetFavIcon()) {
setFavIcon(this.$store);
Expand Down
3 changes: 0 additions & 3 deletions shell/pages/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
setVendor
} from '@shell/config/private-label';
import loadPlugins from '@shell/plugins/plugin';
import { fetchInitialSettings } from '@shell/utils/settings';
import Loading from '@shell/components/Loading';
export default {
Expand Down Expand Up @@ -147,8 +146,6 @@ export default {
// For newer versions this will return all settings if you are somehow logged in,
// and just the public ones if you aren't.
try {
await fetchInitialSettings(this.$store);
firstLoginSetting = this.$store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.FIRST_LOGIN);
plSetting = this.$store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.PL);
brand = this.$store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.BRAND);
Expand Down
9 changes: 1 addition & 8 deletions shell/pages/auth/setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { findBy } from '@shell/utils/array';
import { Checkbox } from '@components/Form/Checkbox';
import { getVendor, getProduct, setVendor } from '@shell/config/private-label';
import { RadioGroup } from '@components/Form/Radio';
import { fetchInitialSettings, setSetting } from '@shell/utils/settings';
import { setSetting } from '@shell/utils/settings';
import { SETTING } from '@shell/config/settings';
import { isDevBuild } from '@shell/utils/version';
import { exceptionToErrorsArray } from '@shell/utils/error';
Expand Down Expand Up @@ -74,11 +74,6 @@ export default {
},
async middleware({ store, redirect } ) {
try {
await fetchInitialSettings(store);
} catch (e) {
}
const isFirstLogin = calcIsFirstLogin(store);
const mustChangePassword = await calcMustChangePassword(store);
Expand Down Expand Up @@ -120,8 +115,6 @@ export default {
let plSetting;
try {
await fetchInitialSettings(this.$store);
plSetting = this.$store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.PL);
} catch (e) {
// Older versions used Norman API to get these
Expand Down

0 comments on commit 3e94be4

Please sign in to comment.