Skip to content

Commit

Permalink
Merge pull request #245 from swisstopo/develop
Browse files Browse the repository at this point in the history
INT Release
  • Loading branch information
daniel-va authored Jul 25, 2024
2 parents c803d27 + 3e47f6c commit 95bd458
Show file tree
Hide file tree
Showing 220 changed files with 20,634 additions and 19,392 deletions.
197 changes: 147 additions & 50 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ on:
- "!main"

env:
NODE_VERSION: "20.x"
NODE_VERSION: "22.x"
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_DATABASE: postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?schema=public

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Review Dependencies
uses: actions/dependency-review-action@v4

install:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,40 +39,52 @@ jobs:
uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: "${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}"
key: "${{ runner.os }}-npm-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}"
restore-keys: |
${{ runner.os }}-npm-
- name: Cache node modules
uses: actions/cache@v4
with:
path: ./node_modules
key: "${{ runner.os }}-node_modules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
restore-keys: |
${{ runner.os }}-node_modules-
- name: Cache e2e node modules
uses: actions/cache@v4
with:
path: ./e2e/node_modules
key: "${{ runner.os }}-node_modules_e2e-${{ hashFiles('./e2e/package-lock.json') }}"
key: "${{ runner.os }}-node_modules_e2e-${{ env.NODE_VERSION }}-${{ hashFiles('./e2e/package-lock.json') }}"
restore-keys: |
${{ runner.os }}-node_modules_e2e-
- name: Install node dependencies
run: npm ci
run: npm install
- name: Generate prisma types
run: npm run prisma -- generate
- name: Install e2e node dependencies
run: cd e2e && npm ci

cypress:
test:
runs-on: ubuntu-latest
needs:
- install
strategy:
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
# Use 2 parallel instances
containers: [1, 2]
needs: install
services:
db:
image: postgis/postgis
ports:
- "5432:5432"
env:
POSTGRES_USER: ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
POSTGRES_DB: ${{ env.DB_DATABASE }}
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.1
ports:
- "9200:9200"
env:
ES_JAVA_OPTS: -Xms512m -Xmx512m
xpack.security.enabled: false
discovery.type: single-node
cluster.routing.allocation.disk.threshold_enabled: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -76,44 +96,121 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ./node_modules
key: "${{ runner.os }}-node_modules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
- name: Start services
env:
DB_USER: ${{ env.DB_USERNAME }}
DB_PASSWORD: ${{ env.DB_PASSWORD }}
run: |
cd development
chmod +x ./init/elasticsearch/init.sh
sed -i 's/- \.\/volumes\/elasticsearch\/data:\/usr\/share\/elasticsearch\/data//g' ./docker-compose.yaml
docker compose up -d db oidc elasticsearch
sleep 60
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
- name: Migrate database
run: npm run prisma -- migrate deploy
- name: Restore cached e2e node modules
- name: Run tests
run: npm run test

lint:
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Restore cached node modules
uses: actions/cache/restore@v4
with:
path: ./e2e/node_modules
key: "${{ runner.os }}-node_modules_e2e-${{ hashFiles('./e2e/package-lock.json') }}"
- name: Cypress run
uses: cypress-io/github-action@v6
path: ./node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
- name: Run lint
run: npm run lint
- name: Run prettier
run: npx prettier --check .

# It would be cleaner and probably more performant to replace this build step
# with either a non-emitting build or a simple type check.
# We only have `build` available for now,
# since the project is currently split across a multitude of small packages,
# all of which have to specify their own commands.
# (Daniel von Atzigen, 2024-04-12)
build:
runs-on: ubuntu-latest
needs:
- test
- lint
- dependency-review
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
command: |
npx cypress run \
--browser edge \
--record \
--parallel \
--key ${{ secrets.CYPRESS_RECORD_KEY }} \
--ci-build-id ${{ github.repository }}-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
build: npm run build
start: npm start
wait-on: "http://localhost:4200"
wait-on-timeout: 120
working-directory: ./e2e
env:
VITE_APP_VERSION: 0.0.99+dev
TZ: Europe/Zurich
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Stop services
run: |
cd development
docker compose down
node-version: ${{ env.NODE_VERSION }}
- name: Restore cached node modules
uses: actions/cache/restore@v4
with:
path: ./node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
- name: Reset nx
run: npx nx reset
- name: Run build
run: npm run build
# cypress:
# runs-on: ubuntu-latest
# needs:
# - test
# - lint
# - dependency-review
# strategy:
# # https://github.com/cypress-io/github-action/issues/48
# fail-fast: false
# matrix:
# # Use 2 parallel instances
# containers: [1, 2]
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Setup node
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# - name: Restore cached node modules
# uses: actions/cache/restore@v4
# with:
# path: ./node_modules
# key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('**/schema.prisma') }}"
# - name: Start services
# env:
# DB_USER: ${{ env.DB_USERNAME }}
# DB_PASSWORD: ${{ env.DB_PASSWORD }}
# run: |
# cd development
# chmod +x ./init/elasticsearch/init.sh
# sed -i 's/- \.\/volumes\/elasticsearch\/data:\/usr\/share\/elasticsearch\/data//g' ./docker-compose.yaml
# docker compose up -d db oidc elasticsearch
# sleep 60
# - name: Migrate database
# run: npm run prisma -- migrate deploy
# - name: Restore cached e2e node modules
# uses: actions/cache/restore@v4
# with:
# path: ./e2e/node_modules
# key: "${{ runner.os }}-node_modules_e2e-${{ env.NODE_VERSION }}-${{ hashFiles('./e2e/package-lock.json') }}"
# - name: Cypress run
# uses: cypress-io/github-action@v6
# with:
# command: |
# npx cypress run \
# --browser edge \
# --record \
# --parallel \
# --key ${{ secrets.CYPRESS_RECORD_KEY }} \
# --ci-build-id ${{ github.repository }}-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
# build: npm run build
# start: npm start
# wait-on: "http://localhost:4200"
# wait-on-timeout: 120
# working-directory: ./e2e
# env:
# VITE_APP_VERSION: 0.0.99+dev
# TZ: Europe/Zurich
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Stop services
# run: |
# cd development
# docker compose down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/node_modules
/tmp
/.idea
/development/volumes
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog

## [Unreleased]

### Added

- Suchfilter zeigen Anzahl Ergebnisse und sind inital verfügbar
- Mehrsprachigkeit von Assets
- Versionsnummer der Applikation wird angezeigt
- Direktauswahl von Assets ohne Suche
- Testing
- Regeneriere Elasticsearch Index via Admin Panel
- Einteilung von Assets in Arbeitsgruppen

### Changed

- UI Refactoring: Neuanordnung der Container
- UI Refactoring: Suchergebnisse als Tabelle
- Update Dependencies
- Bearbeitungsrechte werden auf Basis der Arbeitsgruppen vergeben anstatt global

### Fixed

- Error Handling
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ npm run prisma -- migrate deploy

# Import example data:
cd development
docker compose exec db sh -c 'psql --dbname=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB} -f /dump.sql'
docker compose exec db sh -c 'psql --dbname=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB} -v ON_ERROR_STOP=1 -f /dump.sql'
```

> You will need to manually sync the data to Elasticsearch via the admin panel in the web UI.
Expand Down
2 changes: 1 addition & 1 deletion apps/client-asset-sg/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine as app-builder
FROM node:22-alpine as app-builder

ARG APP_VERSION
ENV APP_VERSION=${APP_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion apps/client-asset-sg/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"assets": ["apps/client-asset-sg/src/favicon.ico", "apps/client-asset-sg/src/assets"],
"styles": ["apps/client-asset-sg/src/styles.scss"],
"scripts": [],
"allowedCommonJsDependencies": ["tsafe", "validator", "xml-utils", "pbf", "rbush", "earcut"]
"allowedCommonJsDependencies": ["tsafe", "validator", "xml-utils", "pbf", "rbush", "earcut", "@prisma/client"]
},
"configurations": {
"production": {
Expand Down
25 changes: 6 additions & 19 deletions apps/client-asset-sg/src/app/app-guards.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import { inject } from '@angular/core';
import { CanActivateFn } from '@angular/router';
import { fromAppShared } from '@asset-sg/client-shared';
import { ORD } from '@asset-sg/core';
import { User, isAdmin, isEditor } from '@asset-sg/shared';
import { isNotNull } from '@asset-sg/core';
import { User } from '@asset-sg/shared/v2';
import { Store } from '@ngrx/store';
import * as E from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';
import { map } from 'rxjs';
import { filter, map } from 'rxjs';

import { AppState } from './state/app-state';

export const roleGuard = (rolePredicate: (u: User) => boolean) => {
export const roleGuard = (testUser: (u: User) => boolean) => {
const store = inject(Store<AppState>);
return store.select(fromAppShared.selectRDUserProfile).pipe(
ORD.filterIsCompleteEither,
map((user) =>
E.isRight(
pipe(
user,
E.filterOrElseW(rolePredicate, () => undefined)
)
)
)
);
return store.select(fromAppShared.selectUser).pipe(filter(isNotNull), map(testUser));
};

export const adminGuard: CanActivateFn = () => roleGuard(isAdmin);
export const editorGuard: CanActivateFn = () => roleGuard(isEditor);
export const adminGuard: CanActivateFn = () => roleGuard((user) => user.isAdmin);
40 changes: 23 additions & 17 deletions apps/client-asset-sg/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
<ng-container *ngIf="errorService.onMessage | async as error; else splashScreen">
<ng-container *ngIf="errorService.onMessage | async as error; else content">
<asset-sg-app-bar />
<div class="error">
<span>{{ error }}</span>
<button asset-sg-warn (click)="authService.logOut()">Logout</button>
</div>
</ng-container>

<ng-template #splashScreen>
<ng-container *ngIf="(authService.state$ | async) !== AuthState.Success; else content">
<ng-template #content>
<ng-container *ngIf="authService.state$ | async as authState">
@if (authState === AuthState.Success || authState === AuthState.ForbiddenResource) {
<asset-sg-app-bar>
<ng-template [cdkPortalOutlet]="(appPortalService.appBarPortalContent$ | push) ?? ''"></ng-template>
</asset-sg-app-bar>
<asset-sg-menu-bar />
<div class="router-outlet">
@if (authState === AuthState.Success) {
<router-outlet />
} @else {
<div class="forbidden">
<h1 translate>resourceForbidden</h1>
<p>403 - Forbidden</p>
</div>
}
</div>
<div class="drawer-portal">
<ng-template [cdkPortalOutlet]="(appPortalService.drawerPortalContent$ | push) ?? ''"></ng-template>
</div>
} @else {
<app-splash-screen />
}
</ng-container>
</ng-template>

<ng-template #content>
<asset-sg-app-bar>
<ng-template [cdkPortalOutlet]="appPortalService.appBarPortalContent$ | push"></ng-template>
</asset-sg-app-bar>
<asset-sg-menu-bar />
<div class="router-outlet">
<router-outlet></router-outlet>
</div>
<div class="drawer-portal">
<ng-template [cdkPortalOutlet]="appPortalService.drawerPortalContent$ | push"></ng-template>
</div>
</ng-template>

<div class="alerts">
<ul app-alert-list></ul>
</div>
Loading

0 comments on commit 95bd458

Please sign in to comment.