Skip to content

Commit

Permalink
Merge branch 'main' into multitenancy_main
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/src/main/resources/application-staging.properties
#	backend/src/main/resources/application.properties
#	frontend/src/app/app.module.ts
#	frontend/src/app/application-top-bar/application-top-bar.component.ts
#	frontend/src/app/components/action-plan/action-plan.component.ts
#	frontend/src/app/components/application-top-bar/application-top-bar.component.html
#	frontend/src/app/objective-filter/objective-filter.component.scss
#	frontend/src/app/services/customization.service.spec.ts
#	frontend/src/app/services/customization.service.ts
  • Loading branch information
Martin Käser committed Apr 23, 2024
2 parents df79f35 + 894da35 commit 53533b3
Show file tree
Hide file tree
Showing 44 changed files with 1,445 additions and 684 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/addIssueToProject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v0.5.0
- uses: actions/add-to-project@v0.6.1
with:
project-url: https://github.com/orgs/puzzle/projects/3
github-token: ${{ secrets.ADD_ISSUE_TO_PROJECT_CLASSIC }}
32 changes: 7 additions & 25 deletions .github/workflows/deploy-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,42 +97,24 @@ jobs:
- name: Push
run: docker push ${{ needs.extract-version.outputs.okr-docker-image}}

- name: Trigger Deployment Workflow with latest Version
uses: actions/checkout@v4
with:
repository: ${{ vars.TARGET_REPOSITORY }}
ref: ${{ vars.TARGET_REFERENCE }}
path: ccy-repo
token: ${{secrets.VERSION_TOKEN}}

- name: Change Yaml
- name: Install yq
shell: bash
env:
FILEPATH: ${{ vars.FILEPATH }}
YAMLPATH: ${{ vars.YAML_PATH }}
NEWVALUE: ${{ needs.extract-version.outputs.okr-docker-image}}
VERSION: v4.25.2
BINARY: yq_linux_amd64
run: |
wget -q https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/local/bin/yq
yq -i "${YAMLPATH} = \"${NEWVALUE}\"" ccy-repo/${FILEPATH}
- name: Commit and Push Changes
working-directory: ccy-repo
- name: Update YAML file
shell: bash
env:
COMMITPREFIX: '[CTS]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add ${{ vars.FILEPATH }} || {
echo "No files were changed, so we did not commit anything"
exit 1
} && \
git commit -m "$COMMITPREFIX Automated changes to ${{ vars.FILEPATH }}" && \
git push origin ${{ vars.TARGET_REFERENCE }}
- run: rm -rf ccy-repo
shell: bash
curl -s --header "PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}?ref=${{vars.TARGET_GITLAB_REFERENCE}}" -H "Accept: application/json" -H "Content-Type: application/json" | jq -r '.content' | base64 --decode > response.yaml
yq -i "${{vars.YAML_PATH}} = \"${{needs.extract-version.outputs.okr-docker-image}}\"" response.yaml
UPDATED_CONTENT=$(cat response.yaml)
curl --request PUT --header 'PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}' -F "branch=${{vars.TARGET_GITLAB_REFERENCE}}" -F "[email protected]" -F "author_name=GitLab Actions" -F "content=${UPDATED_CONTENT}" -F "commit_message=$COMMITPREFIX Automated changes to ${{vars.FILEPATH_COMMIT}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}"
generate-and-push-sbom:
runs-on: ubuntu-latest
Expand Down
32 changes: 6 additions & 26 deletions .github/workflows/staging-deploy-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,44 +179,24 @@ jobs:
- name: Push
run: docker push ${{ needs.update-version.outputs.okr-docker-image}}

- name: Trigger Deployment Workflow with latest Version
uses: actions/checkout@v4
with:
repository: ${{ vars.TARGET_REPOSITORY }}
ref: ${{ vars.TARGET_REFERENCE }}
path: ccy-repo
token: ${{secrets.VERSION_TOKEN}}

- name: Change Yaml
- name: Install yq
shell: bash
env:
FILEPATH: ${{ vars.FILEPATH }}
YAMLPATH: ${{ vars.YAML_PATH }}
NEWVALUE: ${{ needs.update-version.outputs.okr-docker-image}}
VERSION: v4.25.2
BINARY: yq_linux_amd64
run: |
wget -q https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/local/bin/yq
yq -i "${YAMLPATH} = \"${NEWVALUE}\"" ccy-repo/${FILEPATH}
- name: Commit and Push Changes
working-directory: ccy-repo
- name: Update YAML file
shell: bash
env:
COMMITPREFIX: '[CTS]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add ${{ vars.FILEPATH }} || {
echo "No files were changed, so we did not commit anything"
exit 1
} && \
git commit -m "$COMMITPREFIX Automated changes to ${{ vars.FILEPATH }}" && \
git push origin ${{ vars.TARGET_REFERENCE }}
- run: rm -rf ccy-repo
shell: bash
curl -s --header "PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}?ref=${{vars.TARGET_GITLAB_REFERENCE}}" -H "Accept: application/json" -H "Content-Type: application/json" | jq -r '.content' | base64 --decode > response.yaml
yq -i "${{vars.YAML_PATH}} = \"${{needs.update-version.outputs.okr-docker-image}}\"" response.yaml
UPDATED_CONTENT=$(cat response.yaml)
curl --request PUT --header 'PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}' -F "branch=${{vars.TARGET_GITLAB_REFERENCE}}" -F "[email protected]" -F "author_name=GitLab Actions" -F "content=${UPDATED_CONTENT}" -F "commit_message=$COMMITPREFIX Automated changes to ${{vars.FILEPATH_COMMIT}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}"
generate-and-push-sbom:
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<groupId>ch.puzzle.okr</groupId>
<artifactId>parent</artifactId>
<version>2.0.39-SNAPSHOT</version>
<version>2.0.95-SNAPSHOT</version>
</parent>

<artifactId>backend</artifactId>
<version>2.0.39-SNAPSHOT</version>
<version>2.0.95-SNAPSHOT</version>
<name>backend</name>
<description>Puzzle OKR Tool</description>

Expand Down Expand Up @@ -54,17 +54,17 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.6.0</version>
<version>10.10.0</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>10.6.0</version>
<version>10.10.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand All @@ -84,7 +84,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.1</version>
<version>3.25.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 3 additions & 0 deletions backend/src/main/java/ch/puzzle/okr/OkrApplication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package ch.puzzle.okr;

import ch.puzzle.okr.service.clientconfig.ClientCustomizationProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties(ClientCustomizationProperties.class)
public class OkrApplication {
public static void main(String[] args) {
SpringApplication.run(OkrApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ch.puzzle.okr.controller;

import ch.puzzle.okr.service.ClientConfigService;
import ch.puzzle.okr.dto.ClientConfigDto;
import ch.puzzle.okr.service.clientconfig.ClientConfigService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/config")
public class ClientConfigController {
Expand All @@ -20,7 +19,7 @@ public ClientConfigController(ClientConfigService configService) {
}

@GetMapping
public ResponseEntity<Map<String, String>> getConfig() {
public ResponseEntity<ClientConfigDto> getConfig() {
return ResponseEntity.status(HttpStatus.OK).body(configService.getConfigBasedOnActiveEnv());
}
}
7 changes: 7 additions & 0 deletions backend/src/main/java/ch/puzzle/okr/dto/ClientConfigDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ch.puzzle.okr.dto;

import java.util.HashMap;

public record ClientConfigDto(String activeProfile, String issuer, String clientId, String favicon, String logo,
String title, HashMap<String, String> customStyles) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ch.puzzle.okr.service.clientconfig;

import ch.puzzle.okr.dto.ClientConfigDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class ClientConfigService {

@Value("${spring.security.oauth2.resourceserver.jwt.issuer-uri}")
private String issuer;

@Value("${spring.profiles.active}")
private String activeProfile;

@Value("${spring.security.oauth2.resourceserver.opaquetoken.client-id}")
private String clientId;

private final ClientCustomizationProperties clientCustomizationProperties;

public ClientConfigService(ClientCustomizationProperties clientCustomizationProperties) {
this.clientCustomizationProperties = clientCustomizationProperties;
}

public ClientConfigDto getConfigBasedOnActiveEnv() {
return new ClientConfigDto(activeProfile, issuer, clientId, this.clientCustomizationProperties.getFavicon(),
this.clientCustomizationProperties.getLogo(), this.clientCustomizationProperties.getTitle(),
this.clientCustomizationProperties.getCustomStyles());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ch.puzzle.okr.service.clientconfig;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;

@ConfigurationProperties("okr.clientcustomization")
public class ClientCustomizationProperties {
private String favicon;
private String logo;
private String title;
private HashMap<String, String> customStyles = new HashMap<>();

public void setCustomStyles(HashMap<String, String> customStyles) {
this.customStyles = customStyles;
}

public String getFavicon() {
return favicon;
}

public void setFavicon(String favicon) {
this.favicon = favicon;
}

public String getLogo() {
return logo;
}

public void setLogo(String logo) {
this.logo = logo;
}

public HashMap<String, String> getCustomStyles() {
return customStyles;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
}
5 changes: 5 additions & 0 deletions backend/src/main/resources/application-staging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
logging.level.org.springframework=debug

okr.user.champion.emails=[email protected]

spring.security.oauth2.resourceserver.opaquetoken.client-id=pitc_okr_staging

okr.user.champion.usernames=peggimann
okr.clientcustomization.customstyles.okr-topbar-background-color=#ab31ad
6 changes: 5 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ okr.user.champion.emails=

okr.jwt.user.firstname=given_name
okr.jwt.user.lastname=family_name
okr.jwt.user.email=email
okr.jwt.user.email=email

okr.clientcustomization.favicon=assets/favicon.png
okr.clientcustomization.logo=assets/images/okr-logo.svg
okr.clientcustomization.title=Puzzle OKR
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ values (1, 'GJ 22/23-Q4', '2023-04-01', '2023-06-30'),
(6, 'GJ 21/22-Q4', '2022-04-01', '2022-06-30'),
(7, 'GJ 23/24-Q2', '2023-10-01', '2023-12-31'),
(8, 'GJ 23/24-Q3', '2024-01-01', '2024-03-31'),
(9, 'GJ 23/24-Q4', '2024-04-01', '2024-06-30'),
(199, 'Backlog', null, null);

insert into team (id, version, name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ch.puzzle.okr.controller;

import ch.puzzle.okr.service.ClientConfigService;
import ch.puzzle.okr.service.clientconfig.ClientConfigService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package ch.puzzle.okr.service;

import ch.puzzle.okr.dto.ClientConfigDto;
import ch.puzzle.okr.service.clientconfig.ClientConfigService;
import ch.puzzle.okr.test.SpringIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringIntegrationTest
@SpringBootTest(properties = { "okr.clientcustomization.customstyles.okr-topbar-background-color=#affe00",
"okr.clientcustomization.customstyles.okr-other-css-style=rgba(50,60,70,0.5)", })
class ClientConfigServiceIT {

@Autowired
private ClientConfigService clientConfigService;

@Test
void saveKeyResultShouldSaveNewKeyResult() {
Map<String, String> configMap = clientConfigService.getConfigBasedOnActiveEnv();

assertEquals("prod", configMap.get("activeProfile"));
assertEquals("http://localhost:8544/realms/pitc", configMap.get("issuer"));
ClientConfigDto clientConfig = clientConfigService.getConfigBasedOnActiveEnv();

assertEquals("prod", clientConfig.activeProfile());
assertEquals("http://localhost:8544/realms/pitc", clientConfig.issuer());
assertEquals("assets/favicon.png", clientConfig.favicon());
assertEquals("assets/images/okr-logo.svg", clientConfig.logo());
assertEquals("#affe00", clientConfig.customStyles().get("okr-topbar-background-color"));
assertEquals("rgba(50,60,70,0.5)", clientConfig.customStyles().get("okr-other-css-style"));
}

}
Loading

0 comments on commit 53533b3

Please sign in to comment.