Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rancher UI branding customisation is not persistent on the login screen #10796

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cypress/e2e/po/components/password.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ export default class PasswordPo extends ComponentPo {
return this.self()
.find('input');
}

/**
* Return the SHOW anchor element
* @returns HTML Element
*/
showBtn(): Cypress.Chainable {
return this.self()
.find('.addon a');
}
}
2 changes: 1 addition & 1 deletion cypress/e2e/po/pages/login-page.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class LoginPagePo extends PagePo {
});
}

private submitButton(): AsyncButtonPo {
submitButton(): AsyncButtonPo {
aalves08 marked this conversation as resolved.
Show resolved Hide resolved
return new AsyncButtonPo('[data-testid="login-submit"]', this.self());
}

Expand Down
24 changes: 24 additions & 0 deletions cypress/e2e/tests/pages/global-settings/branding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ describe('Branding', { testIsolation: 'off' }, () => {
expect(background).to.satisfy((b) => b.startsWith(settings.primaryColor.newRGB));
});

// check that login page has new styles applied
// https://github.com/rancher/dashboard/issues/10788
loginPage.goTo();

loginPage.submitButton().self().should('have.css', 'background').should((background: string) => {
expect(background).to.satisfy((b) => b.startsWith(settings.primaryColor.newRGB));
});

cy.login();
aalves08 marked this conversation as resolved.
Show resolved Hide resolved
HomePagePo.goToAndWaitForGet();
BrandingPagePo.navTo();

// Reset
brandingPage.primaryColorPicker().set(settings.primaryColor.original);
brandingPage.primaryColorCheckbox().set();
Expand All @@ -395,6 +407,18 @@ describe('Branding', { testIsolation: 'off' }, () => {
brandingPage.linkColorPicker().value().should('eq', settings.linkColor.new);
brandingPage.linkColorPicker().previewColor().should('eq', settings.linkColor.newRGB);

// check that login page has new styles applied
// https://github.com/rancher/dashboard/issues/10788
loginPage.goTo();

loginPage.password().showBtn().should('have.css', 'color').should((color: string) => {
expect(color).to.satisfy((b) => b.startsWith(settings.linkColor.newRGB));
});

cy.login();
HomePagePo.goToAndWaitForGet();
BrandingPagePo.navTo();

// Reset
brandingPage.linkColorPicker().set(settings.linkColor.original);
brandingPage.linkColorCheckbox().set();
Expand Down
113 changes: 67 additions & 46 deletions shell/mixins/brand.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ export default {

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

// Setting this up front will remove `computed` churn, and we only care that we've initialised them
this.haveAppsAndSettings = !!this.apps && !!this.globalSettings;
},

data() {
return {
apps: null, globalSettings: null, haveAppsAndSettings: null
};
return { apps: null, haveAppsAndSettings: null };
},

computed: {
...mapGetters({ loggedIn: 'auth/loggedIn' }),

// added to fix https://github.com/rancher/dashboard/issues/10788
// because on logout the brand mixin is mounted, but then a management store reset happens
// since login view get loaded, another fetchInitialSettings get's done
// which in turn will populate again globalSettings
globalSettings() {
return this.$store.getters['management/all'](MANAGEMENT.SETTING);
},

brand() {
const setting = this.globalSettings?.find((gs) => gs.id === SETTING.BRAND);

Expand Down Expand Up @@ -89,57 +95,72 @@ export default {
},

watch: {
color(neu) {
if (neu) {
this.setCustomColor(neu);
} else {
this.removeCustomColor();
}
color: {
handler(neu) {
if (neu) {
this.setCustomColor(neu);
} else {
this.removeCustomColor();
}
},
immediate: true
},
linkColor(neu) {
if (neu) {
this.setCustomColor(neu, 'link');
} else {
this.removeCustomColor('link');
}
linkColor: {
handler(neu) {
if (neu) {
this.setCustomColor(neu, 'link');
} else {
this.removeCustomColor('link');
}
},
immediate: true
},
theme() {
if (this.color) {
this.setCustomColor(this.color);
}
if (this.linkColor) {
this.setCustomColor(this.linkColor, 'link');
}
this.setBodyClass();
theme: {
handler() {
if (this.color) {
this.setCustomColor(this.color);
}
if (this.linkColor) {
this.setCustomColor(this.linkColor, 'link');
}
this.setBodyClass();
},
immediate: true
},

cspAdapter(neu) {
if (!this.canCalcCspAdapter) {
return;
}

// The brand setting will only get updated if...
if (neu && !this.brand) {
// 1) There should be a brand... but there's no brand setting
const brandSetting = this.globalSettings?.find((gs) => gs.id === SETTING.BRAND);
cspAdapter: {
handler(neu) {
if (!this.canCalcCspAdapter) {
return;
}

if (brandSetting) {
brandSetting.value = 'csp';
brandSetting.save();
} else {
const schema = this.$store.getters['management/schemaFor'](MANAGEMENT.SETTING);
const url = schema?.linkFor('collection');
// The brand setting will only get updated if...
if (neu && !this.brand) {
// 1) There should be a brand... but there's no brand setting
const brandSetting = this.globalSettings?.find((gs) => gs.id === SETTING.BRAND);

if (url) {
this.$store.dispatch('management/create', {
type: MANAGEMENT.SETTING, metadata: { name: SETTING.BRAND }, value: 'csp', default: ''
}).then((setting) => setting.save());
if (brandSetting) {
brandSetting.value = 'csp';
brandSetting.save();
} else {
const schema = this.$store.getters['management/schemaFor'](MANAGEMENT.SETTING);
const url = schema?.linkFor('collection');

if (url) {
this.$store.dispatch('management/create', {
type: MANAGEMENT.SETTING, metadata: { name: SETTING.BRAND }, value: 'csp', default: ''
}).then((setting) => setting.save());
}
}
}
}
},
immediate: true
},
brand() {
this.setBodyClass();
brand: {
handler() {
this.setBodyClass();
},
immediate: true
}

},
Expand Down
Loading