Skip to content

Commit

Permalink
rename supportSiteUrl to helpSiteUrl and change helpSiteUrl of acme
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Nov 21, 2024
1 parent 11cc672 commit b474c70
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 36 deletions.
3 changes: 1 addition & 2 deletions backend/src/main/java/ch/puzzle/okr/dto/ClientConfigDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import java.util.Map;

public record ClientConfigDto(String activeProfile, String issuer, String clientId, String favicon, String logo,
String triangles, String backgroundLogo, String title, String supportSiteUrl,
Map<String, String> customStyles) {
String triangles, String backgroundLogo, String title, String helpSiteUrl, Map<String, String> customStyles) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.util.Map;

public record TenantClientCustomization(String favicon, String logo, String triangles, String backgroundLogo,
String title, String supportSiteUrl, Map<String, String> customStyles) {
String title, String helpSiteUrl, Map<String, String> customStyles) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private TenantClientCustomization readClientCustomizationConfig(String tenantId)
env.getProperty(MessageFormat.format("okr.tenants.{0}.clientcustomization.triangles", tenantId)),
env.getProperty(MessageFormat.format("okr.tenants.{0}.clientcustomization.background-logo", tenantId)),
env.getProperty(MessageFormat.format("okr.tenants.{0}.clientcustomization.title", tenantId)),
env.getProperty(MessageFormat.format("okr.tenants.{0}.clientcustomization.supportSiteUrl", tenantId)),
env.getProperty(MessageFormat.format("okr.tenants.{0}.clientcustomization.helpSiteUrl", tenantId)),
getCustomCssStyles(tenantId) //
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ClientConfigDto getConfigBasedOnActiveEnv(String hostName) {
tenantClientCustomization.get().triangles(), //
tenantClientCustomization.get().backgroundLogo(), //
tenantClientCustomization.get().title(), //
tenantClientCustomization.get().supportSiteUrl(), //
tenantClientCustomization.get().helpSiteUrl(), //
tenantClientCustomization.get().customStyles()); //
}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ okr.tenants.pitc.clientcustomization.triangles=assets/images/triangles-okr-heade
okr.tenants.pitc.clientcustomization.background-logo=assets/images/puzzle-p.svg
okr.tenants.pitc.clientcustomization.favicon=assets/favicon.png
okr.tenants.pitc.clientcustomization.title=Puzzle OKR
okr.tenants.pitc.clientcustomization.supportSiteUrl=https://wiki.puzzle.ch/Puzzle/OKRs
okr.tenants.pitc.clientcustomization.helpSiteUrl=https://wiki.puzzle.ch/Puzzle/OKRs
okr.tenants.pitc.clientcustomization.customstyles.okr-topbar-background-color=#1e5a96
okr.tenants.pitc.clientcustomization.customstyles.okr-banner-background-color=#dcedf9

Expand All @@ -58,6 +58,6 @@ okr.tenants.acme.clientcustomization.triangles=assets/images/triangles-okr-acme-
okr.tenants.acme.clientcustomization.background-logo=assets/images/acme.svg
okr.tenants.acme.clientcustomization.favicon=assets/favicon-acme.png
okr.tenants.acme.clientcustomization.title=ACME OKR
okr.tenants.acme.clientcustomization.supportSiteUrl=https://google.com
okr.tenants.acme.clientcustomization.helpSiteUrl=https://en.wikipedia.org/wiki/Objectives_and_key_results
okr.tenants.acme.clientcustomization.customstyles.okr-topbar-background-color=#738290
okr.tenants.acme.clientcustomization.customstyles.okr-banner-background-color=#F2F2F2
15 changes: 2 additions & 13 deletions backend/src/main/resources/application-integration-test.properties
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@

# show actions from entity manager
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true

# debug options
logging.level.ch.puzzle.okr=DEBUG
logging.level.org.springframework.security=DEBUG
logging.level.org.flywaydb.core=DEBUG
# logging.level.org.springframework.boot.autoconfigure: DEBUG

# flyway fill database with data
spring.flyway.locations=classpath:db/h2-db/database-h2-schema,classpath:db/h2-db/data-test-h2

# TENANT Configuration
okr.tenant-ids=pitc,acme
okr.datasource.driver-class-name=org.h2.Driver

# security
connect.src=http://localhost:8544 http://localhost:8545

# hibernate
hibernate.connection.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;
hibernate.connection.username=user
hibernate.connection.password=sa
hibernate.multiTenancy=SCHEMA

# pitc
okr.tenants.pitc.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS okr_pitc
okr.tenants.pitc.datasource.username=user
Expand All @@ -34,7 +27,6 @@ [email protected],[email protected]
okr.tenants.pitc.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8544/realms/pitc/protocol/openid-connect/certs
okr.tenants.pitc.security.oauth2.frontend.issuer-url=http://localhost:8544/realms/pitc
okr.tenants.pitc.security.oauth2.frontend.client-id=pitc_okr_staging

# acme
okr.tenants.acme.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS okr_acme
okr.tenants.acme.datasource.username=user
Expand All @@ -44,22 +36,19 @@ [email protected],[email protected]
okr.tenants.acme.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:8544/realms/pitc/protocol/openid-connect/certs
okr.tenants.acme.security.oauth2.frontend.issuer-url=http://localhost:8544/realms/pitc
okr.tenants.acme.security.oauth2.frontend.client-id=acme_okr_staging

# pit client customization
okr.tenants.pitc.clientcustomization.logo=assets/images/okr-logo.svg
okr.tenants.pitc.clientcustomization.triangles=assets/images/triangles-okr-header.svg
okr.tenants.pitc.clientcustomization.background-logo=assets/images/puzzle-p.svg
okr.tenants.pitc.clientcustomization.favicon=assets/favicon.png
okr.tenants.pitc.clientcustomization.title=Puzzle OKR
okr.tenants.pitc.clientcustomization.supportSiteUrl=https://wiki.puzzle.ch/Puzzle/OKRs

okr.tenants.pitc.clientcustomization.helpSiteUrl=https://wiki.puzzle.ch/Puzzle/OKRs
okr.tenants.pitc.clientcustomization.customstyles.okr-topbar-background-color=#1e5a96

# acme client customization
okr.tenants.acme.clientcustomization.logo=assets/images/okr-logo-acme.svg
okr.tenants.acme.clientcustomization.triangles=assets/images/triangles-okr-acme-header.svg
okr.tenants.acme.clientcustomization.background-logo=assets/images/acme.svg
okr.tenants.acme.clientcustomization.favicon=assets/favicon-acme.png
okr.tenants.acme.clientcustomization.title=ACME OKR
okr.tenants.acme.clientcustomization.supportSiteUrl=https://google.com
okr.tenants.acme.clientcustomization.helpSiteUrl=https://en.wikipedia.org/wiki/Objectives_and_key_results
okr.tenants.acme.clientcustomization.customstyles.okr-topbar-background-color=#738290
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ void shouldGetClientConfig() throws Exception {
.andExpect(jsonPath("$.triangles", Matchers.is("Triangles")))
.andExpect(jsonPath("$.backgroundLogo", Matchers.is("Background_Logo")))
.andExpect(jsonPath("$.title", Matchers.is("Title")))
.andExpect(jsonPath("$.supportSiteUrl", Matchers.is("supportSiteUrl")))
.andExpect(jsonPath("$.helpSiteUrl", Matchers.is("helpSiteUrl")))
.andExpect(jsonPath("$.customStyles.font-family", Matchers.is("verdana")))
.andExpect(jsonPath("$.customStyles.font-size", Matchers.is("20px")));
}

private ClientConfigDto createClientConfigDto() {
Map<String, String> customStyles = Map.of("font-family", "verdana", "font-size", "20px");
return new ClientConfigDto("Active_Profile", "Issuer", "Client_Id", "Favicon", "Logo", "Triangles",
"Background_Logo", "Title", "supportSiteUrl", customStyles);
"Background_Logo", "Title", "helpSiteUrl", customStyles);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TenantClientCustomizationProviderTestIT {
private static final String BACKGROUND_LOGO = "background-logo";
private static final String FAVICON = "favicon";
private static final String TITLE = "title";
private static final String SUPPORT_SITE_URL = "supportSiteUrl";
private static final String HELP_SITE_URL = "helpSiteUrl";

private static final String CUSTOM_STYLE_NAME = "okr-topbar-background-color";
private static final String CUSTOM_STYLE_VALUE = "css-custom-value";
Expand All @@ -44,7 +44,7 @@ private void setupPropertiesForTenantWithId(String id) {
mockProperty("okr.tenants.{0}.clientcustomization.background-logo", BACKGROUND_LOGO, id);
mockProperty("okr.tenants.{0}.clientcustomization.favicon", FAVICON, id);
mockProperty("okr.tenants.{0}.clientcustomization.title", TITLE, id);
mockProperty("okr.tenants.{0}.clientcustomization.supportSiteUrl", SUPPORT_SITE_URL, id);
mockProperty("okr.tenants.{0}.clientcustomization.helpSiteUrl", HELP_SITE_URL, id);
mockProperty("okr.tenants.{0}.clientcustomization.customstyles.okr-topbar-background-color", CUSTOM_STYLE_VALUE,
id);
}
Expand Down Expand Up @@ -79,7 +79,7 @@ private void assertTenantClientCustomization(TenantClientCustomization customiza
assertEquals(prefix(tenantId) + TRIANGLES, customization.triangles());
assertEquals(prefix(tenantId) + BACKGROUND_LOGO, customization.backgroundLogo());
assertEquals(prefix(tenantId) + TITLE, customization.title());
assertEquals(prefix(tenantId) + SUPPORT_SITE_URL, customization.supportSiteUrl());
assertEquals(prefix(tenantId) + HELP_SITE_URL, customization.helpSiteUrl());
assertCustomStyles(customization, tenantId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private TenantClientCustomization getTenantClientCustomization(String tenantId)
prefix(tenantId) + "triangles", //
prefix(tenantId) + "backgroundLogo", //
prefix(tenantId) + "title", //
prefix(tenantId) + "supportSiteUrl", //
prefix(tenantId) + "helpSiteUrl", //
new HashMap<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
</button>

<button
*ngIf="this.supportSiteUrl$ | async as supportSiteUrl"
*ngIf="this.helpSiteUrl | async as helpSiteUrl"
id="hilfeButton"
class="topBarEntry btn"
(click)="window.open(supportSiteUrl, '_blank')"
(click)="window.open(helpSiteUrl, '_blank')"
>
<mat-icon aria-hidden="false" aria-label="Help icon" fontIcon="help_outline"></mat-icon>
<span class="d-none d-md-flex"> Hilfe </span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ApplicationTopBarComponent implements OnInit, OnDestroy {
userFullName: string = '';
menuIsOpen = false;
logoSrc$ = new BehaviorSubject<String>('assets/images/empty.svg');
supportSiteUrl$ = new BehaviorSubject<string>('https://en.wikipedia.org/wiki/Objectives_and_key_results');
helpSiteUrl = new BehaviorSubject<string>('https://en.wikipedia.org/wiki/Objectives_and_key_results');
private subscription?: Subscription;

constructor(
Expand All @@ -33,8 +33,8 @@ export class ApplicationTopBarComponent implements OnInit, OnDestroy {
if (config.logo) {
this.logoSrc$.next(config.logo);
}
if (config.supportSiteUrl) {
this.supportSiteUrl$.next(config.supportSiteUrl);
if (config.helpSiteUrl) {
this.helpSiteUrl.next(config.helpSiteUrl);
}
},
});
Expand Down
130 changes: 130 additions & 0 deletions frontend/src/app/services/customization.service.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var customization_service_1 = require("./customization.service");
var rxjs_1 = require("rxjs");
var CallRecorder = /** @class */ (function () {
function CallRecorder() {
this.calls = {};
}
CallRecorder.prototype.add = function (key, value) {
if (!this.calls[key]) {
this.calls[key] = [];
}
this.calls[key].push(value);
};
CallRecorder.prototype.getCallByIdx = function (key, index) {
if (index === void 0) { index = 0; }
return this.calls[key][index];
};
CallRecorder.prototype.getCallCount = function (key) {
var _a, _b;
return (_b = (_a = this.calls[key]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
};
CallRecorder.prototype.clear = function () {
this.calls = {};
};
return CallRecorder;
}());
describe('CustomizationService', function () {
var body = {
activeProfile: 'test',
issuer: 'some-issuer.com',
clientId: 'my-client-id',
title: 'title',
favicon: 'favicon',
logo: 'logo',
triangles: 'triangles',
backgroundLogo: 'backgroundLogo',
helpSiteUrl: 'https://wiki.puzzle.ch/Puzzle/OKRs',
customStyles: { cssVar1: 'foo' },
};
var service;
var configServiceMock;
var documentMock;
var callRecorder = new CallRecorder();
var configSubject;
beforeEach(function () {
configSubject = new rxjs_1.BehaviorSubject(body);
configServiceMock = { config$: configSubject.asObservable() };
callRecorder.clear();
documentMock = {
getElementById: function (id) {
return {
setAttribute: function () {
callRecorder.add("".concat(id, "-setAttribute"), arguments);
},
};
},
querySelector: function (selector) {
return {
set innerHTML(value) {
callRecorder.add("".concat(selector, ".innerHTML"), arguments);
},
get style() {
return {
setProperty: function () {
callRecorder.add("".concat(selector, ".style.setProperty"), arguments);
},
removeProperty: function () {
callRecorder.add("".concat(selector, ".style.removeProperty"), arguments);
},
};
},
};
},
};
service = new customization_service_1.CustomizationService(configServiceMock, documentMock);
});
it('should call correct apis when config is ready', function () {
var currentConfig = service.getCurrentConfig();
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.title).toBe(body.title);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.logo).toBe(body.logo);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.favicon).toBe(body.favicon);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.triangles).toBe(body.triangles);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.backgroundLogo).toBe(body.backgroundLogo);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.helpSiteUrl).toBe(body.helpSiteUrl);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.customStyles['cssVar1']).toBe(body.customStyles['cssVar1']);
expect(callRecorder.getCallCount('title.innerHTML')).toBe(1);
expect(callRecorder.getCallCount('favicon-setAttribute')).toBe(1);
expect(callRecorder.getCallCount('html.style.setProperty')).toBe(1);
expect(callRecorder.getCallCount('html.style.removeProperty')).toBe(0);
expect(callRecorder.getCallByIdx('title.innerHTML', 0)[0]).toBe('title');
expect(callRecorder.getCallByIdx('favicon-setAttribute', 0)[0]).toBe('href');
expect(callRecorder.getCallByIdx('favicon-setAttribute', 0)[1]).toBe('favicon');
expect(callRecorder.getCallByIdx('html.style.setProperty', 0)[0]).toBe('--cssVar1');
expect(callRecorder.getCallByIdx('html.style.setProperty', 0)[1]).toBe('foo');
});
it('should update if config changed afterwards', function () {
var bodySecond = {
activeProfile: 'test-second',
issuer: 'some-issuer.com-second',
clientId: 'my-client-id-second',
title: 'title-second',
favicon: 'favicon-second',
logo: 'logo-second',
triangles: 'triangles-second',
backgroundLogo: 'backgroundLogo-second',
helpSiteUrl: 'https://wiki.puzzle.ch/Puzzle/OKRs',
customStyles: { cssVarNew: 'bar' },
};
configSubject.next(bodySecond);
var currentConfig = service.getCurrentConfig();
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.title).toBe(bodySecond.title);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.logo).toBe(bodySecond.logo);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.favicon).toBe(bodySecond.favicon);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.triangles).toBe(bodySecond.triangles);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.backgroundLogo).toBe(bodySecond.backgroundLogo);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.helpSiteUrl).toBe(bodySecond.helpSiteUrl);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.customStyles['cssVarNew']).toBe(bodySecond.customStyles['cssVarNew']);
expect(currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.customStyles['cssVar1']).toBe(undefined);
expect(callRecorder.getCallCount('title.innerHTML')).toBe(2);
expect(callRecorder.getCallCount('favicon-setAttribute')).toBe(2);
expect(callRecorder.getCallCount('html.style.setProperty')).toBe(2);
expect(callRecorder.getCallCount('html.style.removeProperty')).toBe(1);
expect(callRecorder.getCallByIdx('title.innerHTML', 1)[0]).toBe('title-second');
expect(callRecorder.getCallByIdx('favicon-setAttribute', 1)[0]).toBe('href');
expect(callRecorder.getCallByIdx('favicon-setAttribute', 1)[1]).toBe('favicon-second');
expect(callRecorder.getCallByIdx('html.style.setProperty', 1)[0]).toBe('--cssVarNew');
expect(callRecorder.getCallByIdx('html.style.setProperty', 1)[1]).toBe('bar');
});
});
Loading

0 comments on commit b474c70

Please sign in to comment.