diff --git a/alfa-client/apps/admin/project.json b/alfa-client/apps/admin/project.json index 9c6af90763bf5aec332dd62f254377b6de58f77a..e113da51b11ba0f7afa5d2a0e194ba9aea7a1e82 100644 --- a/alfa-client/apps/admin/project.json +++ b/alfa-client/apps/admin/project.json @@ -41,8 +41,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "2mb", + "maximumError": "3mb" }, { "type": "anyComponentStyle", diff --git a/alfa-client/apps/admin/src/app/app.component.html b/alfa-client/apps/admin/src/app/app.component.html index 66f83dc085317b14d81ad4a3b54fec85b9f88890..aec8d53fbb5c0848c05817014a197e6fbec5ccdf 100644 --- a/alfa-client/apps/admin/src/app/app.component.html +++ b/alfa-client/apps/admin/src/app/app.component.html @@ -18,9 +18,9 @@ <div class="flex h-screen w-full justify-center overflow-y-auto"> <ods-navbar data-test-id="navigation"> <ng-container *ngIf="apiRoot | hasLink: ApiRootLinkRel.CONFIGURATION"> - <ods-nav-item caption="Organisationseinheiten" to="/organisationseinheiten"> - <ods-orga-unit-icon icon /> - </ods-nav-item> + <!-- <ods-nav-item caption="Organisationseinheiten" to="/organisationseinheiten">--> + <!-- <ods-orga-unit-icon icon />--> + <!-- </ods-nav-item>--> <ods-nav-item caption="Postfach" to="/postfach"> <ods-mailbox-icon icon /> </ods-nav-item> diff --git a/alfa-client/apps/admin/src/app/app.component.spec.ts b/alfa-client/apps/admin/src/app/app.component.spec.ts index 9dc1460ef48786b4278b89bc2fef350c0e5d45f1..d10cfd74e6f7e55e727bf6779c494f0f5311f8b7 100644 --- a/alfa-client/apps/admin/src/app/app.component.spec.ts +++ b/alfa-client/apps/admin/src/app/app.component.spec.ts @@ -22,7 +22,7 @@ import { OrgaUnitIconComponent, } from '@ods/system'; import { AuthenticationService } from 'authentication'; -import { NavigationComponent } from 'libs/admin-settings/src/lib/navigation/navigation.component'; +import { NavigationComponent } from 'libs/admin/settings/src/lib/navigation/navigation.component'; import { createApiRootResource } from 'libs/api-root-shared/test/api-root'; import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent, MockDirective } from 'ng-mocks'; diff --git a/alfa-client/apps/admin/src/app/app.routes.ts b/alfa-client/apps/admin/src/app/app.routes.ts index 80dafdcc1dfdf77729e2041e3ca263ac9a0cd2fe..fdff512b76c4e15d4026c8c250cce90357cf98be 100644 --- a/alfa-client/apps/admin/src/app/app.routes.ts +++ b/alfa-client/apps/admin/src/app/app.routes.ts @@ -1,5 +1,4 @@ import { Route } from '@angular/router'; -import { OrganisationseinheitPageComponent } from '../pages/organisationseinheit/organisationseinheit-page/organisationseinheit-page.component'; import { PostfachPageComponent } from '../pages/postfach/postfach-page/postfach-page.component'; export const appRoutes: Route[] = [ @@ -13,9 +12,9 @@ export const appRoutes: Route[] = [ component: PostfachPageComponent, title: 'Admin | Postfach', }, - { - path: 'organisationseinheiten', - component: OrganisationseinheitPageComponent, - title: 'Admin | Organisationseinheiten', - }, + // { + // path: 'organisationseinheiten', + // component: OrganisationseinheitPageComponent, + // title: 'Admin | Organisationseinheiten', + // }, ]; diff --git a/alfa-client/apps/admin/src/styles.scss b/alfa-client/apps/admin/src/styles.scss index d4e151f329f1cefda33709ace138cd39fb383a7a..9a4448d0f9c72e50e1aac1b190f36cf3118d060a 100644 --- a/alfa-client/apps/admin/src/styles.scss +++ b/alfa-client/apps/admin/src/styles.scss @@ -1,8 +1,14 @@ +@use '@angular/material' as mat; + @tailwind base; @tailwind components; @tailwind utilities; @import 'libs/design-system/src/lib/tailwind-preset/root.css'; +@import 'libs/ui/src/lib/font/font_material'; + +@include mat.all-component-typographies(); +@include mat.core(); .heading-1 { @apply text-3xl font-medium text-text; diff --git a/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.html b/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.html deleted file mode 100644 index 73fdc05b075776a3751e4f04ef7f6ebf08eb0e78..0000000000000000000000000000000000000000 --- a/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.html +++ /dev/null @@ -1,2 +0,0 @@ -<admin-organisationseinheit-navigation-item></admin-organisationseinheit-navigation-item> -<admin-postfach-navigation-item></admin-postfach-navigation-item> diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts deleted file mode 100644 index 24eb2f3b5b2ad34101a7ba4cfe920a709949e88c..0000000000000000000000000000000000000000 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { HttpError, StateResource } from '@alfa-client/tech-shared'; -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { SettingName } from '../admin-settings.model'; -import { PostfachResourceService } from './postfach-resource.service'; -import { Postfach, PostfachResource, PostfachSettingsItem } from './postfach.model'; - -@Injectable() -export class PostfachService { - constructor(private postfachResourceService: PostfachResourceService) {} - - public get(): Observable<StateResource<PostfachResource>> { - return this.postfachResourceService.get(); - } - - public save(postfach: Postfach): Observable<StateResource<PostfachResource | HttpError>> { - return this.postfachResourceService.save(this.buildPostfachSettingItem(postfach)); - } - - private buildPostfachSettingItem(postfach: Postfach): PostfachSettingsItem { - return { - name: SettingName.POSTFACH, - settingBody: postfach, - }; - } -} diff --git a/alfa-client/libs/admin-settings/.eslintrc.json b/alfa-client/libs/admin/settings/.eslintrc.json similarity index 90% rename from alfa-client/libs/admin-settings/.eslintrc.json rename to alfa-client/libs/admin/settings/.eslintrc.json index adbe7ae2dfabd4a42804f00846baec80877f4c5c..3230caf3d2f01580c97f01513e96c9c4727c91c9 100644 --- a/alfa-client/libs/admin-settings/.eslintrc.json +++ b/alfa-client/libs/admin/settings/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["../../.eslintrc.json"], + "extends": ["../../../.eslintrc.json"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/alfa-client/libs/admin-settings/README.md b/alfa-client/libs/admin/settings/README.md similarity index 100% rename from alfa-client/libs/admin-settings/README.md rename to alfa-client/libs/admin/settings/README.md diff --git a/alfa-client/libs/admin-settings/jest.config.ts b/alfa-client/libs/admin/settings/jest.config.ts similarity index 88% rename from alfa-client/libs/admin-settings/jest.config.ts rename to alfa-client/libs/admin/settings/jest.config.ts index 6a725dafe3e164fd3e957164738b3e29170811d2..26fb88d9012f3d3b3a4c62e37d28fe0849337433 100644 --- a/alfa-client/libs/admin-settings/jest.config.ts +++ b/alfa-client/libs/admin/settings/jest.config.ts @@ -3,10 +3,10 @@ const esModules = ['@keycloak/keycloak-admin-client', 'url-join', 'url-template', 'camelize-ts']; export default { displayName: 'admin-settings', - preset: '../../jest.preset.js', + preset: '../../../jest.preset.js', setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], globals: {}, - coverageDirectory: '../../coverage/libs/admin-settings', + coverageDirectory: '../../coverage/libs/admin/settings', transform: { '^.+\\.(ts|mjs|js|html)$': [ 'jest-preset-angular', diff --git a/alfa-client/libs/admin-settings/project.json b/alfa-client/libs/admin/settings/project.json similarity index 60% rename from alfa-client/libs/admin-settings/project.json rename to alfa-client/libs/admin/settings/project.json index 2d85134f707e7aed82bbe30a08be2b01fea3a8c4..2749cb93e4ed471d107b091fece1a677debe2edc 100644 --- a/alfa-client/libs/admin-settings/project.json +++ b/alfa-client/libs/admin/settings/project.json @@ -1,7 +1,7 @@ { "name": "admin-settings", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/admin-settings/src", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/admin/settings/src", "projectType": "library", "prefix": "admin", "tags": [], @@ -14,8 +14,8 @@ "executor": "@nx/jest:jest", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "options": { - "tsConfig": "libs/admin-settings/tsconfig.spec.json", - "jestConfig": "libs/admin-settings/jest.config.ts" + "tsConfig": "libs/admin/settings/tsconfig.spec.json", + "jestConfig": "libs/admin/settings/jest.config.ts" } } } diff --git a/alfa-client/libs/admin-settings/src/index.ts b/alfa-client/libs/admin/settings/src/index.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/index.ts rename to alfa-client/libs/admin/settings/src/index.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings-resource.service.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings-resource.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings-resource.service.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings-resource.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.linkrel.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.linkrel.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.linkrel.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.linkrel.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.model.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.model.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.model.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.model.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.module.spec.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.module.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.module.spec.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.module.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.module.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.module.ts similarity index 89% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.module.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.module.ts index 99b04e136805e4fec867cfe801aa82ab6ded3936..a6865423b56b2537999ce25764a3357a883fe0da 100644 --- a/alfa-client/libs/admin-settings/src/lib/admin-settings.module.ts +++ b/alfa-client/libs/admin/settings/src/lib/admin-settings.module.ts @@ -6,6 +6,8 @@ import { NgModule } from '@angular/core'; import { ReactiveFormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import KcAdminClient from '@keycloak/keycloak-admin-client'; +import { ButtonWithSpinnerComponent, TextareaEditorComponent } from '@ods/component'; +import { TextInputComponent } from '@ods/system'; import { createSettingListResourceService, SettingListResourceService, @@ -23,6 +25,7 @@ import { OrganisationseinheitListComponent } from './organisationseinheit/organi import { OrganisationseinheitNavigationItemComponent } from './organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component'; import { PostfachContainerComponent } from './postfach/postfach-container/postfach-container.component'; import { PostfachFormComponent } from './postfach/postfach-container/postfach-form/postfach-form.component'; +import { PostfachSignaturComponent } from './postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component'; import { PostfachNavigationItemComponent } from './postfach/postfach-navigation-item/postfach-navigation-item.component'; import { createPostfachResourceService, @@ -41,6 +44,7 @@ import { TextFieldComponent } from './shared/text-field/text-field.component'; declarations: [ PostfachContainerComponent, PostfachFormComponent, + PostfachSignaturComponent, NavigationItemComponent, TextFieldComponent, PostfachNavigationItemComponent, @@ -55,7 +59,15 @@ import { TextFieldComponent } from './shared/text-field/text-field.component'; MoreItemButtonComponent, SpinnerComponent, ], - imports: [CommonModule, TechSharedModule, RouterModule, ReactiveFormsModule], + imports: [ + CommonModule, + TechSharedModule, + RouterModule, + ReactiveFormsModule, + TextInputComponent, + ButtonWithSpinnerComponent, + TextareaEditorComponent, + ], exports: [ PostfachContainerComponent, OrganisationseinheitContainerComponent, diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.service.spec.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.service.spec.ts similarity index 97% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.service.spec.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.service.spec.ts index 0dae05ec7a255b758dc57b5041376fafc1894b7f..b46edf6f96f8a3f74808786111071d045dbf5329 100644 --- a/alfa-client/libs/admin-settings/src/lib/admin-settings.service.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/admin-settings.service.spec.ts @@ -4,8 +4,8 @@ import { createStateResource, } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { singleCold } from 'libs/tech-shared/test/marbles'; import { Observable, of } from 'rxjs'; -import { singleCold } from '../../../tech-shared/test/marbles'; import { createSettingsListResource } from '../../test/admin-settings'; import { createPostfachResource, createSettingItemResource } from '../../test/postfach/postfach'; import { SettingListResourceService } from './admin-settings-resource.service'; diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.service.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.service.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.util.spec.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.util.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.util.spec.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.util.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/admin-settings.util.ts b/alfa-client/libs/admin/settings/src/lib/admin-settings.util.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/admin-settings.util.ts rename to alfa-client/libs/admin/settings/src/lib/admin-settings.util.ts diff --git a/alfa-client/libs/admin-settings/src/lib/configuration/configuration-resource.service.ts b/alfa-client/libs/admin/settings/src/lib/configuration/configuration-resource.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/configuration/configuration-resource.service.ts rename to alfa-client/libs/admin/settings/src/lib/configuration/configuration-resource.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/configuration/configuration.linkrel.ts b/alfa-client/libs/admin/settings/src/lib/configuration/configuration.linkrel.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/configuration/configuration.linkrel.ts rename to alfa-client/libs/admin/settings/src/lib/configuration/configuration.linkrel.ts diff --git a/alfa-client/libs/admin-settings/src/lib/configuration/configuration.model.ts b/alfa-client/libs/admin/settings/src/lib/configuration/configuration.model.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/configuration/configuration.model.ts rename to alfa-client/libs/admin/settings/src/lib/configuration/configuration.model.ts diff --git a/alfa-client/libs/admin-settings/src/lib/configuration/configuration.service.spec.ts b/alfa-client/libs/admin/settings/src/lib/configuration/configuration.service.spec.ts similarity index 95% rename from alfa-client/libs/admin-settings/src/lib/configuration/configuration.service.spec.ts rename to alfa-client/libs/admin/settings/src/lib/configuration/configuration.service.spec.ts index df7a4250f9fdd077594d0743e2c82cef23c5b059..5a581ac9ad22f23d01d328450b2d7d3e079bde8d 100644 --- a/alfa-client/libs/admin-settings/src/lib/configuration/configuration.service.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/configuration/configuration.service.spec.ts @@ -1,7 +1,7 @@ import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { singleCold, singleHot } from 'libs/tech-shared/test/marbles'; import { Observable } from 'rxjs'; -import { singleCold, singleHot } from '../../../../tech-shared/test/marbles'; import { createConfigurationResource } from '../../../test/configuration/configuration'; import { ConfigurationResourceService } from './configuration-resource.service'; import { ConfigurationResource } from './configuration.model'; diff --git a/alfa-client/libs/admin-settings/src/lib/configuration/configuration.service.ts b/alfa-client/libs/admin/settings/src/lib/configuration/configuration.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/configuration/configuration.service.ts rename to alfa-client/libs/admin/settings/src/lib/configuration/configuration.service.ts diff --git a/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.html b/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.html new file mode 100644 index 0000000000000000000000000000000000000000..aa69f82b45426328c850c413c0653d4a074c7ac5 --- /dev/null +++ b/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.html @@ -0,0 +1,2 @@ +<!--<admin-organisationseinheit-navigation-item></admin-organisationseinheit-navigation-item>--> +<admin-postfach-navigation-item></admin-postfach-navigation-item> diff --git a/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.scss b/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.scss similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.scss rename to alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.scss diff --git a/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.ts b/alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/navigation/navigation.component.ts rename to alfa-client/libs/admin/settings/src/lib/navigation/navigation.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts similarity index 98% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts index 417eec4616318c4c8b39eb639906e3433eaa78fe..50aed3b14f080f41d6dd560101a3c1a358bc5b8f 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.spec.ts @@ -8,9 +8,9 @@ import { } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; +import { singleCold } from 'libs/tech-shared/test/marbles'; import { MockComponent } from 'ng-mocks'; import { of } from 'rxjs'; -import { singleCold } from '../../../../../tech-shared/test/marbles'; import { createOrganisationseinheit, createOrganisationseinheitState, diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-container.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts similarity index 99% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts index 03bef4912b7d8a510ee06cfaa2ec438ae318b278..c43144f6a8730dd6c81ed73aaef73aa4f0b4b5ef 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.spec.ts @@ -2,8 +2,8 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { fakeAsync, tick } from '@angular/core/testing'; import { AbstractControl, FormBuilder } from '@angular/forms'; import { hot } from 'jest-marbles'; +import { singleCold, singleHot } from 'libs/tech-shared/test/marbles'; import { Observable, lastValueFrom, throwError } from 'rxjs'; -import { singleCold, singleHot } from '../../../../../../tech-shared/test/marbles'; import { createOrganisationseinheit, createOrganisationseinheitError, diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit.formservice.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.html b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.html rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-list/organisationseinheit-list.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.html b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.html rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.ts rename to alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-navigation-item/organisationseinheit-navigation-item.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.html b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.html similarity index 71% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.html rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.html index 8a68a1e11400f2ece06013fc60f1d2a13f1d1b50..8c406667e45b4bba2c8a1aeb31599df687338c45 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.html +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.html @@ -1 +1,2 @@ +<h1 class="heading-1">Postfach</h1> <postfach-form [postfachStateResource]="postfachStateResource$ | async"></postfach-form> diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts similarity index 92% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts index 49de353525058623dc206167d4e3344437ffc439..d00f5aa44d6e99755de7e5464a289aed6ea22a79 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.spec.ts @@ -1,9 +1,9 @@ import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; +import { singleCold, singleHot } from 'libs/tech-shared/test/marbles'; +import { Mock, mock } from 'libs/test-utils/src/lib/mocking'; import { MockComponent } from 'ng-mocks'; -import { singleCold, singleHot } from '../../../../../tech-shared/test/marbles'; -import { Mock, mock } from '../../../../../test-utils/src/lib/mocking'; import { createPostfachResource } from '../../../../test/postfach/postfach'; import { PostfachResource } from '../postfach.model'; import { PostfachService } from '../postfach.service'; diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-container.component.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-container.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html similarity index 69% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html index cf06ca1af3045314ba30e32d03ac45b8aa5c7203..a5aace656e46f148670b719e35a52d23df73ec4b 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html @@ -1,6 +1,6 @@ <form class="form flex-col" [formGroup]="formService.form"> - <h1 class="heading-1">Postfach</h1> - <h2 class="heading-2">Absender</h2> + <!-- + <h2 class="heading-2">Absender</h1> <p id="absender-desc" class="p-1">Hinterlegen Sie Absenderinformationen zu Ihrem Postfach.</p> <div [formGroupName]="PostfachFormService.ASBSENDER_GROUP" @@ -34,26 +34,21 @@ ></text-field> </div> <div class="h-20"></div> - <h2 class="heading-2">Signatur</h2> - <p id="signatur-desc">Erstellen oder ändern Sie die Signatur für Nachrichten.</p> - <textarea - data-test-id="signatur-text" - aria-describedby="signatur-desc" - [formControlName]="PostfachFormService.SIGNATUR_FIELD" - class="mb-2 mt-2 block h-40 w-96 p-1" - ></textarea> +--> + <postfach-signatur class="mb-6 block" /> - <admin-primary-button - (clickEmitter)="submit()" - [submitInProgress]="this.submitInProgress$ | async" + <ods-button-with-spinner data-test-id="save-button" - label="Speichern" - ></admin-primary-button> + text="Speichern" + [stateResource]="submitInProgress$ | async" + (clickEmitter)="submit()" + ></ods-button-with-spinner> <span *ngIf="formService.invalidEmpty" data-test-id="invalid-empty-message-span" class="m-2 text-red-500" - >*Es müssen alle Felder ausgefüllt sein.</span > + *Es müssen alle Felder ausgefüllt sein. + </span> </form> diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts similarity index 56% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts index f3e6c68f3f15f51d766224ea4add00605a4e05be..3470d76a49844b39ea90737b2474d95c76ff5a2c 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts @@ -1,26 +1,29 @@ -import { ProblemDetail, createStateResource } from '@alfa-client/tech-shared'; import { - Mock, + createEmptyStateResource, + createStateResource, + ProblemDetail, +} from '@alfa-client/tech-shared'; +import { dispatchEventFromFixture, existsAsHtmlElement, - getDebugElementFromFixtureByCss, - getElementFromFixture, + Mock, mock, notExistsAsHtmlElement, } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { ButtonWithSpinnerComponent } from '@ods/component'; import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; -import { MockComponent, ngMocks } from 'ng-mocks'; -import { EMPTY, of } from 'rxjs'; -import { createInvalidParam, createProblemDetail } from '../../../../../../tech-shared/test/error'; -import { singleCold } from '../../../../../../tech-shared/test/marbles'; +import { createInvalidParam, createProblemDetail } from 'libs/tech-shared/test/error'; +import { singleCold } from 'libs/tech-shared/test/marbles'; +import { MockComponent } from 'ng-mocks'; +import { EMPTY } from 'rxjs'; import { createPostfachResource } from '../../../../../test/postfach/postfach'; -import { PrimaryButtonComponent } from '../../../shared/primary-button/primary-button.component'; import { TextFieldComponent } from '../../../shared/text-field/text-field.component'; import { PostfachResource } from '../../postfach.model'; import { PostfachService } from '../../postfach.service'; import { PostfachFormComponent } from './postfach-form.component'; +import { PostfachSignaturComponent } from './postfach-signatur/postfach-signatur.component'; import { PostfachFormService } from './postfach.formservice'; describe('PostfachFormComponent', () => { @@ -37,8 +40,9 @@ describe('PostfachFormComponent', () => { await TestBed.configureTestingModule({ declarations: [ PostfachFormComponent, - MockComponent(PrimaryButtonComponent), MockComponent(TextFieldComponent), + MockComponent(PostfachSignaturComponent), + MockComponent(ButtonWithSpinnerComponent), ], imports: [ReactiveFormsModule, FormsModule], providers: [ @@ -86,59 +90,43 @@ describe('PostfachFormComponent', () => { }); }); - describe('Absender section', () => { - const fields: string[][] = [ - [PostfachFormService.NAME_FIELD, 'Name', 'absender-name'], - [PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift', 'absender-anschrift'], - [PostfachFormService.DIENST_FIELD, 'Dienst', 'absender-dienst'], - [PostfachFormService.MANDANT_FIELD, 'Mandant', 'absender-mandant'], - [ - PostfachFormService.GEMEINDESCHLUESSEL_FIELD, - 'Gemeindeschlüssel', - 'absender-gemeindeschluessel', - ], - ]; - - test.each(fields)( - 'should bind form for text-field "%s"', - async (fieldName, text, dataTestId) => { - const fieldValue = `some text-field ${text}`; - const absenderGroup = formService.form.get(PostfachFormService.ASBSENDER_GROUP); - const formControl = absenderGroup.get(fieldName); - - const textFieldComponent = getDebugElementFromFixtureByCss( - fixture, - getDataTestIdOf(dataTestId), - ); - ngMocks.change(textFieldComponent, fieldValue); - expect(formControl.value).toBe(fieldValue); - }, - ); - - test.each(fields)( - 'should have label for field "%s" with name "%s"', - (fieldName, text, dataTestId) => { - const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(dataTestId)); - expect(textFieldElement.getAttribute('ng-reflect-label')).toBe(text); - }, - ); - }); - - describe('Signatur section', () => { - const signaturTextarea = getDataTestIdOf('signatur-text'); - - it('should have signatur-text', () => { - existsAsHtmlElement(fixture, signaturTextarea); - }); - - it('should set form-control-name', () => { - const text = 'some signature text'; - formService.form.get(PostfachFormService.SIGNATUR_FIELD).setValue(text); - - const textareaElement = getElementFromFixture(fixture, signaturTextarea); - expect(textareaElement.value).toBe(text); - }); - }); + // describe('Absender section', () => { + // const fields: string[][] = [ + // [PostfachFormService.NAME_FIELD, 'Name', 'absender-name'], + // [PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift', 'absender-anschrift'], + // [PostfachFormService.DIENST_FIELD, 'Dienst', 'absender-dienst'], + // [PostfachFormService.MANDANT_FIELD, 'Mandant', 'absender-mandant'], + // [ + // PostfachFormService.GEMEINDESCHLUESSEL_FIELD, + // 'Gemeindeschlüssel', + // 'absender-gemeindeschluessel', + // ], + // ]; + // + // test.each(fields)( + // 'should bind form for text-field "%s"', + // async (fieldName, text, dataTestId) => { + // const fieldValue = `some text-field ${text}`; + // const absenderGroup = formService.form.get(PostfachFormService.ASBSENDER_GROUP); + // const formControl = absenderGroup.get(fieldName); + // + // const textFieldComponent = getDebugElementFromFixtureByCss( + // fixture, + // getDataTestIdOf(dataTestId), + // ); + // ngMocks.change(textFieldComponent, fieldValue); + // expect(formControl.value).toBe(fieldValue); + // }, + // ); + // + // test.each(fields)( + // 'should have label for field "%s" with name "%s"', + // (fieldName, text, dataTestId) => { + // const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(dataTestId)); + // expect(textFieldElement.getAttribute('ng-reflect-label')).toBe(text); + // }, + // ); + // }); describe('save button', () => { it('should call submit on click', () => { @@ -150,17 +138,17 @@ describe('PostfachFormComponent', () => { expect(submitFn).toHaveBeenCalled(); }); - it.each([true, false])('should use submit progress "%s"', (progress) => { - component.submitInProgress$ = of(progress); - - fixture.detectChanges(); - - const saveButtonComponent: PrimaryButtonComponent = getDebugElementFromFixtureByCss( - fixture, - saveButtonSelector, - ).componentInstance; - expect(saveButtonComponent.submitInProgress).toBe(progress); - }); + // it.each([true, false])('should use submit progress "%s"', (progress) => { + // component.submitInProgress$ = of(progress); + // + // fixture.detectChanges(); + // + // const saveButtonComponent: ButtonWithSpinnerComponent = getDebugElementFromFixtureByCss( + // fixture, + // saveButtonSelector, + // ).componentInstance; + // expect(saveButtonComponent.loading).toBe(progress); + // }); }); describe('invalid message', () => { @@ -190,11 +178,12 @@ describe('PostfachFormComponent', () => { describe('submit', () => { it('should assign submit in progress', () => { - formService.submitWithProgress = jest.fn().mockReturnValue(singleCold(true)); + const stateResource = createEmptyStateResource(); + formService.submit = jest.fn().mockReturnValue(singleCold(stateResource)); component.submit(); - expect(component.submitInProgress$).toBeObservable(singleCold(true)); + expect(component.submitInProgress$).toBeObservable(singleCold(stateResource)); }); }); }); diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts similarity index 74% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts index be240d7c1e9f5439bb24fe222501ab20c9c2fc72..ca965ac3fa5ff09806a8a95a9ea22ccb2764ae19 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.ts @@ -1,5 +1,6 @@ -import { StateResource, isNotNil } from '@alfa-client/tech-shared'; +import { createEmptyStateResource, isNotNil, StateResource } from '@alfa-client/tech-shared'; import { Component, Input } from '@angular/core'; +import { Resource } from '@ngxp/rest'; import { Observable, of } from 'rxjs'; import { PostfachResource } from '../../postfach.model'; import { PostfachFormService } from './postfach.formservice'; @@ -10,7 +11,7 @@ import { PostfachFormService } from './postfach.formservice'; providers: [PostfachFormService], }) export class PostfachFormComponent { - submitInProgress$: Observable<boolean> = of(false); + submitInProgress$: Observable<StateResource<Resource>> = of(createEmptyStateResource<Resource>()); @Input() set postfachStateResource(stateResource: StateResource<PostfachResource>) { this.updatePostfachResource(stateResource.resource); @@ -27,6 +28,6 @@ export class PostfachFormComponent { constructor(public formService: PostfachFormService) {} public submit(): void { - this.submitInProgress$ = this.formService.submitWithProgress(); + this.submitInProgress$ = this.formService.submit(); } } diff --git a/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.html b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.html new file mode 100644 index 0000000000000000000000000000000000000000..91f5982d6a2e93f317b7a301d4177ec9c59482df --- /dev/null +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.html @@ -0,0 +1,16 @@ +<form [formGroup]="formService.form" class="max-w-[960px]"> + <h2 class="heading-2">Signatur</h2> + <p id="signatur-desc"> + Diese Signatur wird bei allen Nachrichten an den Antragsteller angezeigt. + </p> + <ods-textarea-editor + [formControlName]="formServiceClass.SIGNATUR_FIELD" + [isResizable]="false" + [showLabel]="false" + data-test-id="signatur-text" + label="signature" + rows="6" + class="w-full" + aria-describedby="signatur-desc" + /> +</form> diff --git a/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7ac55113ec028463983d6e823f2e7842fbf9e53a --- /dev/null +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.spec.ts @@ -0,0 +1,54 @@ +import { getElementFromFixture, mock, useFromMock } from '@alfa-client/test-utils'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { TextareaEditorComponent } from '@ods/component'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; +import { MockComponent } from 'ng-mocks'; +import { PostfachService } from '../../../postfach.service'; +import { PostfachFormComponent } from '../postfach-form.component'; +import { PostfachFormService } from '../postfach.formservice'; +import { PostfachSignaturComponent } from './postfach-signatur.component'; + +describe('PostfachSignaturComponent', () => { + let component: PostfachSignaturComponent; + let fixture: ComponentFixture<PostfachSignaturComponent>; + + const formService: PostfachFormService = new PostfachFormService( + new FormBuilder(), + useFromMock(mock(PostfachService)), + ); + + const signaturTextarea = getDataTestIdOf('signatur-text'); + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ReactiveFormsModule], + declarations: [PostfachFormComponent, MockComponent(TextareaEditorComponent)], + providers: [ + { + provide: PostfachFormService, + useValue: formService, + }, + ], + }).compileComponents(); + fixture = TestBed.createComponent(PostfachSignaturComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + describe('template', () => { + it('should create', () => { + expect(component).toBeTruthy(); + }); + + describe('ods-textarea-editor', () => { + describe('input', () => { + it('should set formControlName to Signatur Field', () => { + const textAreaEditor = getElementFromFixture(fixture, signaturTextarea); + + expect(textAreaEditor.getAttribute('rows')).toEqual('6'); + }); + }); + }); + }); +}); diff --git a/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..5d6a6f695879e1989dabe1192e0aaa7f0d97a48d --- /dev/null +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach-signatur/postfach-signatur.component.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; +import { PostfachFormService } from '../postfach.formservice'; + +@Component({ + selector: 'postfach-signatur', + templateUrl: './postfach-signatur.component.html', +}) +export class PostfachSignaturComponent { + protected readonly formServiceClass = PostfachFormService; + + constructor(public formService: PostfachFormService) {} +} diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts similarity index 82% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts index d5a884c0f1379fcf3172de5de2743f8a30d691bd..bbc93c26a6744ea5ae695e9c4400bdeccfdb1f72 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.spec.ts @@ -1,12 +1,7 @@ -import { - createEmptyStateResource, - createStateResource, - StateResource, -} from '@alfa-client/tech-shared'; +import { createStateResource, StateResource } from '@alfa-client/tech-shared'; import { mock, Mock, useFromMock } from '@alfa-client/test-utils'; import { FormBuilder } from '@angular/forms'; -import { cold } from 'jest-marbles'; -import { Observable, of } from 'rxjs'; +import { of } from 'rxjs'; import { createPostfach, createPostfachResource } from '../../../../../test/postfach/postfach'; import { Postfach, PostfachResource } from '../../postfach.model'; import { PostfachService } from '../../postfach.service'; @@ -19,7 +14,6 @@ describe('PostfachFormService', () => { beforeEach(() => { postfachService = mock(PostfachService); - formService = new PostfachFormService(formBuilder, useFromMock(postfachService)); }); @@ -93,19 +87,4 @@ describe('PostfachFormService', () => { }); }); }); - - describe('submit with progress', () => { - it('should assign submit in progress to state resource loading', () => { - formService.submit = jest.fn().mockReturnValue( - cold('ab', { - a: createEmptyStateResource(true), - b: createEmptyStateResource(false), - }), - ); - - const progressObservable: Observable<boolean> = formService.submitWithProgress(); - - expect(progressObservable).toBeObservable(cold('ab', { a: true, b: false })); - }); - }); }); diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts similarity index 84% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts index c6d801bdd90f6f27101dd9d621c497083c57f6ac..ed81ff5fd52cfc3ef92312fd3f2d0cbbcb8d4d89 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-container/postfach-form/postfach.formservice.ts @@ -1,14 +1,8 @@ -import { - AbstractFormService, - EMPTY_STRING, - HttpError, - ProblemDetail, - StateResource, -} from '@alfa-client/tech-shared'; +import { AbstractFormService, EMPTY_STRING, StateResource } from '@alfa-client/tech-shared'; import { Injectable } from '@angular/core'; import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { isNil } from 'lodash-es'; -import { Observable, map } from 'rxjs'; +import { Observable } from 'rxjs'; import { Postfach, PostfachResource } from '../../postfach.model'; import { PostfachService } from '../../postfach.service'; @@ -43,7 +37,7 @@ export class PostfachFormService extends AbstractFormService { }); } - protected doSubmit(): Observable<StateResource<PostfachResource | HttpError>> { + protected doSubmit(): Observable<StateResource<PostfachResource>> { const value: Postfach = this.getFormValue(); if (this.shouldSkipAbsender(value)) { delete value.absender; @@ -65,12 +59,4 @@ export class PostfachFormService extends AbstractFormService { public get invalidEmpty(): boolean { return this.form.invalid; } - - public submitWithProgress(): Observable<boolean> { - return this.submit().pipe( - map( - (stateResource: StateResource<PostfachResource | ProblemDetail>) => stateResource.loading, - ), - ); - } } diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.html b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.html rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.scss b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.scss similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.scss rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.scss diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-navigation-item/postfach-navigation-item.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-resource.service.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach-resource.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach-resource.service.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach-resource.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.linkrel.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.linkrel.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach.linkrel.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach.linkrel.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.model.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.model.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach.model.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach.model.ts diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.spec.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.spec.ts similarity index 56% rename from alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.spec.ts rename to alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.spec.ts index ca41b7c408ecec8a94ed38459aae668038c8f0ee..d787449be4be3621a443ff9cd4a9824613fbc167 100644 --- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach.service.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.spec.ts @@ -1,8 +1,15 @@ -import { HttpError, StateResource, createStateResource } from '@alfa-client/tech-shared'; +import { + StateResource, + createEmptyStateResource, + createStateResource, +} from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { SnackBarService } from '@alfa-client/ui'; import { Type } from '@angular/core'; -import { Observable } from 'rxjs'; -import { singleCold, singleHot } from '../../../../tech-shared/test/marbles'; +import { fakeAsync, tick } from '@angular/core/testing'; +import { cold } from 'jest-marbles'; +import { singleCold, singleHot } from 'libs/tech-shared/test/marbles'; +import { Observable, of } from 'rxjs'; import { createPostfachResource, createPostfachSettingItem } from '../../../test/postfach/postfach'; import { PostfachResourceService } from './postfach-resource.service'; import { PostfachResource, PostfachSettingsItem } from './postfach.model'; @@ -11,11 +18,12 @@ import { PostfachService } from './postfach.service'; describe('PostfachService', () => { let service: PostfachService; let resourceService: Mock<PostfachResourceService>; + const snackbarService: Mock<SnackBarService> = mock(SnackBarService); beforeEach(() => { resourceService = mockResourceService(PostfachResourceService); - service = new PostfachService(useFromMock(resourceService)); + service = new PostfachService(useFromMock(resourceService), useFromMock(snackbarService)); }); it('should create', () => { @@ -36,8 +44,7 @@ describe('PostfachService', () => { it('should reurn value', () => { resourceService.get.mockReturnValue(singleCold(postfachStateResource)); - const returnedPostfachResource: Observable<StateResource<PostfachResource | HttpError>> = - service.get(); + const returnedPostfachResource: Observable<StateResource<PostfachResource>> = service.get(); expect(returnedPostfachResource).toBeObservable(singleHot(postfachStateResource)); }); @@ -45,25 +52,48 @@ describe('PostfachService', () => { describe('save', () => { const postfachSettingsItem: PostfachSettingsItem = createPostfachSettingItem(); + const postfachResource: PostfachResource = createPostfachResource(); + const postfachStateResource: StateResource<PostfachResource> = + createStateResource(postfachResource); + + beforeEach(() => {}); it('should call resourceService', () => { + resourceService.save.mockReturnValue(of(postfachStateResource)); + service.save(postfachSettingsItem.settingBody); expect(resourceService.save).toHaveBeenCalledWith(postfachSettingsItem); }); it('should return saved value', () => { - const postfachResource: PostfachResource = createPostfachResource(); - const postfachStateResource: StateResource<PostfachResource> = - createStateResource(postfachResource); - resourceService.save.mockReturnValue(singleCold(postfachStateResource)); + resourceService.save.mockReturnValue(singleCold(postfachStateResource, '-a')); - const savedPostfach: Observable<StateResource<PostfachResource | HttpError>> = service.save( + const savedPostfach: Observable<StateResource<PostfachResource>> = service.save( postfachResource.settingBody, ); - expect(savedPostfach).toBeObservable(singleHot(postfachStateResource)); + expect(savedPostfach).toBeObservable( + cold('ab', { + a: createEmptyStateResource<PostfachResource>(true), + b: postfachStateResource, + }), + ); }); + + it('should show message in snackbar', fakeAsync(() => { + resourceService.save.mockReturnValue(of(postfachStateResource)); + const savedPostfach: Observable<StateResource<PostfachResource>> = service.save( + postfachResource.settingBody, + ); + + savedPostfach.subscribe(); + tick(); + + expect(snackbarService.showInfo).toHaveBeenCalledWith( + 'Die Signatur wurde erfolgreich gespeichert.', + ); + })); }); }); diff --git a/alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.ts b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ff867073051235829114ca5cba89d9c227128ad --- /dev/null +++ b/alfa-client/libs/admin/settings/src/lib/postfach/postfach.service.ts @@ -0,0 +1,41 @@ +import { createEmptyStateResource, StateResource } from '@alfa-client/tech-shared'; +import { SnackBarService } from '@alfa-client/ui'; +import { Injectable } from '@angular/core'; +import { Observable, startWith, tap } from 'rxjs'; +import { SettingName } from '../admin-settings.model'; +import { PostfachResourceService } from './postfach-resource.service'; +import { Postfach, PostfachResource, PostfachSettingsItem } from './postfach.model'; + +@Injectable() +export class PostfachService { + constructor( + private postfachResourceService: PostfachResourceService, + private snackbarService: SnackBarService, + ) {} + + public get(): Observable<StateResource<PostfachResource>> { + return this.postfachResourceService.get(); + } + + public save(postfach: Postfach): Observable<StateResource<PostfachResource>> { + return this.postfachResourceService.save(this.buildPostfachSettingItem(postfach)).pipe( + tap((stateResource: StateResource<PostfachResource>) => + this.showInfoAfterSave(stateResource), + ), + startWith(createEmptyStateResource<PostfachResource>(true)), + ); + } + + private showInfoAfterSave(stateResource: StateResource<PostfachResource>) { + if (!stateResource.loading) { + this.snackbarService.showInfo('Die Signatur wurde erfolgreich gespeichert.'); + } + } + + private buildPostfachSettingItem(postfach: Postfach): PostfachSettingsItem { + return { + name: SettingName.POSTFACH, + settingBody: postfach, + }; + } +} diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.html b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-item-button/more-item-button.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.html b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/more-menu/more-menu.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/more-menu/more-menu.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.html b/alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.scss b/alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.scss similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.scss rename to alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.scss diff --git a/alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/navigation-item/navigation-item.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/navigation-item/navigation-item.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.html b/alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/primary-button/primary-button.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/primary-button/primary-button.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.html b/alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/secondary-button/secondary-button.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/secondary-button/secondary-button.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.html b/alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/spinner/spinner.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/spinner/spinner.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.html b/alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.html similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.html rename to alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.html diff --git a/alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.spec.ts rename to alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.ts b/alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/shared/text-field/text-field.component.ts rename to alfa-client/libs/admin/settings/src/lib/shared/text-field/text-field.component.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.model.ts b/alfa-client/libs/admin/settings/src/lib/user/user.model.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.model.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.model.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.repository.service.ts b/alfa-client/libs/admin/settings/src/lib/user/user.repository.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.repository.service.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.repository.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts b/alfa-client/libs/admin/settings/src/lib/user/user.repository.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.repository.spec.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.repository.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts b/alfa-client/libs/admin/settings/src/lib/user/user.service.spec.ts similarity index 99% rename from alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.service.spec.ts index f15073e7d7fc75be636949747d6189d6650b6c6f..56ac9d24a8cf68804dce861d61b7a3cf551aeb54 100644 --- a/alfa-client/libs/admin-settings/src/lib/user/user.service.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/user/user.service.spec.ts @@ -1,8 +1,8 @@ import { mock, Mock, useFromMock } from '@alfa-client/test-utils'; import { fakeAsync, tick } from '@angular/core/testing'; import { cold } from 'jest-marbles'; +import { singleCold } from 'libs/tech-shared/test/marbles'; import { firstValueFrom, lastValueFrom, Observable, of } from 'rxjs'; -import { singleCold } from '../../../../tech-shared/test/marbles'; import { createOrganisationseinheit, createOrganisationseinheitState, diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.service.ts b/alfa-client/libs/admin/settings/src/lib/user/user.service.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.service.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.service.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts b/alfa-client/libs/admin/settings/src/lib/user/user.util.spec.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.util.spec.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.util.spec.ts diff --git a/alfa-client/libs/admin-settings/src/lib/user/user.util.ts b/alfa-client/libs/admin/settings/src/lib/user/user.util.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/lib/user/user.util.ts rename to alfa-client/libs/admin/settings/src/lib/user/user.util.ts diff --git a/alfa-client/libs/admin-settings/src/test-setup.ts b/alfa-client/libs/admin/settings/src/test-setup.ts similarity index 100% rename from alfa-client/libs/admin-settings/src/test-setup.ts rename to alfa-client/libs/admin/settings/src/test-setup.ts diff --git a/alfa-client/libs/admin-settings/test/admin-settings.ts b/alfa-client/libs/admin/settings/test/admin-settings.ts similarity index 90% rename from alfa-client/libs/admin-settings/test/admin-settings.ts rename to alfa-client/libs/admin/settings/test/admin-settings.ts index d81dbd8109f79ac5eff68526de2aced072605d05..56cc3ea62b8ac65078f16e7d4494ab4371a54e59 100644 --- a/alfa-client/libs/admin-settings/test/admin-settings.ts +++ b/alfa-client/libs/admin/settings/test/admin-settings.ts @@ -1,5 +1,5 @@ import { Resource } from '@ngxp/rest'; -import { toResource } from '../../tech-shared/test/resource'; +import { toResource } from '../../../tech-shared/test/resource'; import { SettingListLinkRel } from '../src/lib/admin-settings.linkrel'; import { SettingItemResource, SettingListResource } from '../src/lib/admin-settings.model'; diff --git a/alfa-client/libs/admin-settings/test/configuration/configuration.ts b/alfa-client/libs/admin/settings/test/configuration/configuration.ts similarity index 82% rename from alfa-client/libs/admin-settings/test/configuration/configuration.ts rename to alfa-client/libs/admin/settings/test/configuration/configuration.ts index 32e4ed5cac791a9c3c9ea0c6520f9df6decfe905..c12683311837ef4ded9e34d0fbf8797111c004f0 100644 --- a/alfa-client/libs/admin-settings/test/configuration/configuration.ts +++ b/alfa-client/libs/admin/settings/test/configuration/configuration.ts @@ -1,4 +1,4 @@ -import { toResource } from '../../../tech-shared/test/resource'; +import { toResource } from 'libs/tech-shared/test/resource'; import { ConfigurationLinkRel } from '../../src/lib/configuration/configuration.linkrel'; import { ConfigurationResource } from '../../src/lib/configuration/configuration.model'; diff --git a/alfa-client/libs/admin-settings/test/postfach/postfach.ts b/alfa-client/libs/admin/settings/test/postfach/postfach.ts similarity index 93% rename from alfa-client/libs/admin-settings/test/postfach/postfach.ts rename to alfa-client/libs/admin/settings/test/postfach/postfach.ts index 65dc1159f333f5aa897ff759b2a9de5a1c307398..16dd988db914e892938d5b93ae63ede3055beead 100644 --- a/alfa-client/libs/admin-settings/test/postfach/postfach.ts +++ b/alfa-client/libs/admin/settings/test/postfach/postfach.ts @@ -1,5 +1,5 @@ import faker from '@faker-js/faker'; -import { toResource } from '../../../tech-shared/test/resource'; +import { toResource } from 'libs/tech-shared/test/resource'; import { SettingItemResource, SettingName } from '../../src/lib/admin-settings.model'; import { Postfach, diff --git a/alfa-client/libs/admin-settings/test/user/user.ts b/alfa-client/libs/admin/settings/test/user/user.ts similarity index 100% rename from alfa-client/libs/admin-settings/test/user/user.ts rename to alfa-client/libs/admin/settings/test/user/user.ts diff --git a/alfa-client/libs/admin-settings/tsconfig.json b/alfa-client/libs/admin/settings/tsconfig.json similarity index 82% rename from alfa-client/libs/admin-settings/tsconfig.json rename to alfa-client/libs/admin/settings/tsconfig.json index 7cc6baf2f58ed5ccfba098131996f579979e9f18..8ca9ad312c2bd4dc364383853ddd91a2ed8f86fd 100644 --- a/alfa-client/libs/admin-settings/tsconfig.json +++ b/alfa-client/libs/admin/settings/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../../tsconfig.base.json", "files": [], "include": [], "references": [ diff --git a/alfa-client/libs/admin-settings/tsconfig.lib.json b/alfa-client/libs/admin/settings/tsconfig.lib.json similarity index 87% rename from alfa-client/libs/admin-settings/tsconfig.lib.json rename to alfa-client/libs/admin/settings/tsconfig.lib.json index dcc35a71ee8a26bc9394b9cf96b02996be26ec16..17469f1e4af3ea771aaa29b1d48f9bb5bf62a020 100644 --- a/alfa-client/libs/admin-settings/tsconfig.lib.json +++ b/alfa-client/libs/admin/settings/tsconfig.lib.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "declaration": true, "declarationMap": true, "inlineSources": true, diff --git a/alfa-client/libs/admin-settings/tsconfig.spec.json b/alfa-client/libs/admin/settings/tsconfig.spec.json similarity index 88% rename from alfa-client/libs/admin-settings/tsconfig.spec.json rename to alfa-client/libs/admin/settings/tsconfig.spec.json index c3cb17f784fa2f7b9a4b0e7c9b03663500f4ee3d..723782fbd367969806c5992aea882773ab65af8b 100644 --- a/alfa-client/libs/admin-settings/tsconfig.spec.json +++ b/alfa-client/libs/admin/settings/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"], "target": "ES2022", diff --git a/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration-request-form.component.ts b/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration-request-form.component.ts index ccaf4fd89ec7f6af5d2afe69d3ff397669cd841c..d78bb1da55f8ffcb8d3364ce11ef6aff6573aad4 100644 --- a/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration-request-form.component.ts +++ b/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration-request-form.component.ts @@ -1,6 +1,6 @@ import { Collaboration, CollaborationListResource } from '@alfa-client/collaboration-shared'; import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared'; -import { HttpError, StateResource, createEmptyStateResource } from '@alfa-client/tech-shared'; +import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared'; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Observable, of } from 'rxjs'; import { CollaborationRequestFormService } from './collaboration.request.formservice'; @@ -20,7 +20,7 @@ export class CollaborationRequestFormComponent { this.formService.setListResource(collaborationListResource); } - public submitInProgress$: Observable<StateResource<CommandResource | HttpError>> = of( + public submitInProgress$: Observable<StateResource<CommandResource>> = of( createEmptyStateResource<CommandResource>(), ); diff --git a/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration.request.formservice.spec.ts b/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration.request.formservice.spec.ts index a9f135fc6a49e51d32f30ee11708d49189343178..8333c24f140f2ad55fc22d3da7011806b90dccdf 100644 --- a/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration.request.formservice.spec.ts +++ b/alfa-client/libs/collaboration/src/lib/collaboration-in-vorgang-container/collaboration-request-form/collaboration.request.formservice.spec.ts @@ -1,6 +1,6 @@ import { CollaborationListResource } from '@alfa-client/collaboration-shared'; import { CommandResource } from '@alfa-client/command-shared'; -import { HttpError, StateResource, createStateResource } from '@alfa-client/tech-shared'; +import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { UntypedFormBuilder } from '@angular/forms'; import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service'; @@ -48,8 +48,7 @@ describe('CollaborationRequestFormService', () => { }); it('should return stateCommandResource', () => { - const response$: Observable<StateResource<CommandResource | HttpError>> = - formService.submit(); + const response$: Observable<StateResource<CommandResource>> = formService.submit(); expect(response$).toBeObservable(singleColdCompleted(stateCommandResource)); }); diff --git a/alfa-client/libs/design-component/src/lib/button-with-spinner/button-with-spinner.component.ts b/alfa-client/libs/design-component/src/lib/button-with-spinner/button-with-spinner.component.ts index 05700cac1ad64ec9d60ef775fa70c0b1340140b8..2489bb3d94ad7f490abf17231a075dc0050700c2 100644 --- a/alfa-client/libs/design-component/src/lib/button-with-spinner/button-with-spinner.component.ts +++ b/alfa-client/libs/design-component/src/lib/button-with-spinner/button-with-spinner.component.ts @@ -1,8 +1,9 @@ import { CommandResource, hasCommandError } from '@alfa-client/command-shared'; -import { createEmptyStateResource, isLoaded, StateResource } from '@alfa-client/tech-shared'; +import { StateResource, createEmptyStateResource, isLoaded } from '@alfa-client/tech-shared'; import { CommonModule } from '@angular/common'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { ButtonComponent, buttonVariants, ErrorMessageComponent } from '@ods/system'; +import { Resource } from '@ngxp/rest'; +import { ButtonComponent, ErrorMessageComponent, buttonVariants } from '@ods/system'; import { VariantProps } from 'class-variance-authority'; import { isNil } from 'lodash-es'; @@ -16,7 +17,7 @@ type ButtonVariants = VariantProps<typeof buttonVariants>; template: ` <ods-error-message *ngIf="isError" text="Ein Fehler ist aufgetreten." - subText="Versuchen Sie es nocheinmal." + subText="Versuchen Sie es noch einmal." > </ods-error-message> <ods-button @@ -32,7 +33,7 @@ type ButtonVariants = VariantProps<typeof buttonVariants>; export class ButtonWithSpinnerComponent implements OnInit { @Input() text: string = ''; @Input() dataTestId: string = ''; - @Input() stateResource: StateResource<CommandResource>; + @Input() stateResource: StateResource<Resource>; @Input() variant: ButtonVariants['variant'] = 'primary'; @Input() size: ButtonVariants['size'] = 'medium'; @@ -42,10 +43,8 @@ export class ButtonWithSpinnerComponent implements OnInit { this.stateResource = this.getStateResource(); } - getStateResource(): StateResource<CommandResource> { - return isNil(this.stateResource) ? - createEmptyStateResource<CommandResource>() - : this.stateResource; + getStateResource(): StateResource<Resource> { + return isNil(this.stateResource) ? createEmptyStateResource<Resource>() : this.stateResource; } get isLoading(): boolean { @@ -53,6 +52,8 @@ export class ButtonWithSpinnerComponent implements OnInit { } get isError(): boolean { - return isLoaded(this.stateResource) && hasCommandError(this.stateResource.resource); + return ( + isLoaded(this.stateResource) && hasCommandError(<CommandResource>this.stateResource.resource) + ); } } diff --git a/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.html b/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.html index 9252326a5bdcc9d9c25ec164981bd0e24915bafa..f8858992626b2be8a4dc43e07f7947e3b0a84735 100644 --- a/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.html +++ b/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.html @@ -7,6 +7,7 @@ [attr.data-test-id]="(label | convertForDataTest) + '-text-editor'" [required]="isRequired" [focus]="focus" + [showLabel]="showLabel" > <ods-validation-error error diff --git a/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.ts b/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.ts index c40849cf31e2279a3727527898213567bab07c4c..d6a19c8b70cac1f11b73038b321b1fc79fa2af58 100644 --- a/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.ts +++ b/alfa-client/libs/design-component/src/lib/form/text-editor/text-editor.component.ts @@ -24,6 +24,7 @@ export class TextEditorComponent extends FormControlEditorAbstractComponent { @Input() placeholder: string = ''; @Input() isRequired: boolean = false; @Input() focus: boolean = false; + @Input() showLabel: boolean = true; get variant(): string { return this.invalidParams.length > 0 ? 'error' : 'default'; diff --git a/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.html b/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.html index c27f425a3f9ca703f85b9961a8c87175a50a0a9f..22a5c192844d111ff69b4ed90f1be4b7108fcee8 100644 --- a/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.html +++ b/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.html @@ -7,6 +7,8 @@ [attr.data-test-id]="(label | convertForDataTest) + '-textarea-editor'" [required]="isRequired" [focus]="focus" + [isResizable]="isResizable" + [showLabel]="showLabel" > <ods-validation-error error diff --git a/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.ts b/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.ts index a47b955192b12c4a9ce1379062cd16543e455e2a..ef615ae42c6b31689a63ce85d22613537190588e 100644 --- a/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.ts +++ b/alfa-client/libs/design-component/src/lib/form/textarea-editor/textarea-editor.component.ts @@ -24,6 +24,8 @@ export class TextareaEditorComponent extends FormControlEditorAbstractComponent @Input() rows: number = 10; @Input() isRequired: boolean = false; @Input() focus: boolean = false; + @Input() isResizable: boolean = true; + @Input() showLabel: boolean = true; get variant(): string { return this.invalidParams.length > 0 ? 'error' : 'default'; diff --git a/alfa-client/libs/design-system/src/lib/form/textarea/textarea.component.ts b/alfa-client/libs/design-system/src/lib/form/textarea/textarea.component.ts index 2c4340b9f30232e900ef8a4ac8c845adf4765d41..cc91e16b2345a9f1a578001c60b7b20655ed5598 100644 --- a/alfa-client/libs/design-system/src/lib/form/textarea/textarea.component.ts +++ b/alfa-client/libs/design-system/src/lib/form/textarea/textarea.component.ts @@ -31,14 +31,14 @@ type TextareaVariants = VariantProps<typeof textareaVariants>; imports: [CommonModule, ReactiveFormsModule, TechSharedModule], template: ` <div class="mt-2"> - <label [for]="id" class="text-md mb-2 block font-medium text-text"> + <label *ngIf="showLabel" [for]="id" class="text-md mb-2 block font-medium text-text"> {{ inputLabel }}<ng-container *ngIf="required"><i aria-hidden="true">*</i></ng-container> </label> <textarea [id]="id" [formControl]="fieldControl" [rows]="rows" - [ngClass]="textareaVariants({ variant })" + [ngClass]="[textareaVariants({ variant }), isResizable ? 'resize' : 'resize-none']" [placeholder]="placeholder" [autocomplete]="autocomplete" [attr.aria-required]="required" @@ -64,6 +64,8 @@ export class TextareaComponent { @Input() variant: TextareaVariants['variant']; @Input() fieldControl: FormControl = new FormControl(EMPTY_STRING); @Input() required: boolean = false; + @Input() isResizable: boolean = true; + @Input() showLabel: boolean = true; @Input() set focus(value: boolean) { if (value && this.textAreaElement) { diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts index e0da72cebbd87689172262fba7a0393652b18302..2a984d4ddbdc07d828802be92d46d770002a6fdf 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts @@ -62,7 +62,8 @@ export interface CreatePostfachMailCommand extends CreateCommand { export interface PostfachMailResource extends Resource, PostfachMail {} export interface PostfachMailListResource extends ListResource { - features: Features; + features: PostfachFeatures; + settings: PostfachSettings; } export enum PostfachNachrichtenCount { @@ -80,7 +81,10 @@ export interface PostfachMailFormDialogData extends FixedDialogData { postfachNachricht?: PostfachMailResource; } -export interface Features { - //TODO Rename to PostfachFeatures +export interface PostfachFeatures { reply: boolean; } + +export interface PostfachSettings { + signatur: string; +} diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts index 1d00b7d41af9f9851a34f07c3035251d140eeb2c..3d23e1126c898d3b4d1df1ce5da9edad93b8d477 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts @@ -21,7 +21,6 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { MatDialog } from '@angular/material/dialog'; import { BinaryFileListResource, BinaryFileResource, @@ -37,6 +36,7 @@ import { import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { SnackBarService } from '@alfa-client/ui'; import { VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; +import { MatDialog } from '@angular/material/dialog'; import { createBinaryFileListResource, createBinaryFileResource, @@ -49,9 +49,11 @@ import { import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { BehaviorSubject, of } from 'rxjs'; import { + createPostfachFeatures, createPostfachMail, createPostfachMailListResource, createPostfachMailResource, + createPostfachSettings, } from '../../test/postfach'; import { PostfachFacade } from './+state/postfach.facade'; import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel'; @@ -630,7 +632,20 @@ describe('PostfachService', () => { ); service.getFeatures().subscribe((features) => { - expect(features).toEqual({ reply: true }); + expect(features).toEqual(createPostfachFeatures()); + done(); + }); + }); + }); + + describe('getSettings', () => { + it('should return settings by list stateResource', (done) => { + service.postfachMailList$ = new BehaviorSubject( + createStateResource(createPostfachMailListResource()), + ); + + service.getSettings().subscribe((settings) => { + expect(settings).toEqual(createPostfachSettings()); done(); }); }); diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts index f4bc26e4687c2ce05b1cc7b3d36560b76a5a21df..4fda384295d5f2cf511064bccd84941fd78d3a8c 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -58,10 +58,11 @@ import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel import { PostfachMessages } from './postfach.message'; import { CreatePostfachMailCommand, - Features, + PostfachFeatures, PostfachMail, PostfachMailListResource, PostfachMailResource, + PostfachSettings, } from './postfach.model'; import { PostfachRepository } from './postfach.repository'; import { createResendPostfachMailCommand, createSendPostfachMailCommand } from './postfach.util'; @@ -372,7 +373,7 @@ export class PostfachService { this.postfachFacade.clearAttachmentList(); } - public getFeatures(): Observable<Features> { + public getFeatures(): Observable<PostfachFeatures> { return this.getPostfachMailListByVorgang().pipe( map( (listStateResource: StateResource<PostfachMailListResource>) => @@ -380,4 +381,13 @@ export class PostfachService { ), ); } + + public getSettings(): Observable<PostfachSettings> { + return this.getPostfachMailListByVorgang().pipe( + map( + (listStateResource: StateResource<PostfachMailListResource>) => + listStateResource.resource.settings, + ), + ); + } } diff --git a/alfa-client/libs/postfach-shared/test/postfach.ts b/alfa-client/libs/postfach-shared/test/postfach.ts index fb0fa71451c5d4409d18ba8c879e592eae198030..0ca6f2c9f377754a92d123e1692ae567597fa410 100644 --- a/alfa-client/libs/postfach-shared/test/postfach.ts +++ b/alfa-client/libs/postfach-shared/test/postfach.ts @@ -21,8 +21,8 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { faker } from '@faker-js/faker'; import { EMPTY_ARRAY, createStateResource } from '@alfa-client/tech-shared'; +import { faker } from '@faker-js/faker'; import { Resource } from '@ngxp/rest'; import { toResource } from 'libs/tech-shared/test/resource'; import { times } from 'lodash-es'; @@ -30,10 +30,12 @@ import { PostfachMailListLinkRel } from '../src/lib/postfach.linkrel'; import { PostfachNachrichtMessageCode } from '../src/lib/postfach.message-code'; import { Direction, + PostfachFeatures, PostfachMail, PostfachMailFormDialogData, PostfachMailListResource, PostfachMailResource, + PostfachSettings, ReplyOption, } from '../src/lib/postfach.model'; @@ -62,13 +64,27 @@ export function createPostfachMailResources(linkRelations: string[] = []): Postf export function createPostfachMailListResource( linkRelations: string[] = [], ): PostfachMailListResource { - return toResource(createPostfachMailListWithAllowedReplyFeature(), [...linkRelations], { + return toResource(createPostfachMailList(), [...linkRelations], { [PostfachMailListLinkRel.POSTFACH_MAIL_LIST]: createPostfachMailResources(), }); } -function createPostfachMailListWithAllowedReplyFeature(): Resource { - return toResource({ features: { reply: true } }, ['sendPostfachMail']); +function createPostfachMailList(): Resource { + return toResource({ features: createPostfachFeatures(), settings: createPostfachSettings() }, [ + 'sendPostfachMail', + ]); +} + +export function createPostfachFeatures(): PostfachFeatures { + return { reply: true }; +} + +export function createPostfachSettings(): PostfachSettings { + return { signatur: 'Best regards' }; +} + +export function createEmptyPostfachSettings(): PostfachSettings { + return { signatur: '' }; } export class PostfachTestFactory { diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts index 40d4bc90cda99e87336563376dd405d63298d575..3f25e40be126c663b985d8591d829789743a0b99 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts @@ -21,12 +21,6 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; -import { MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { PostfachService } from '@alfa-client/postfach-shared'; import { createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; @@ -39,8 +33,14 @@ import { TextAreaEditorComponent, TextEditorComponent, } from '@alfa-client/ui'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { createCommandResource } from 'libs/command-shared/test/command'; -import { PostfachTestFactory } from 'libs/postfach-shared/test/postfach'; +import { PostfachTestFactory, createPostfachSettings } from 'libs/postfach-shared/test/postfach'; import { MockComponent } from 'ng-mocks'; import { of } from 'rxjs'; import { PostfachMailFormComponent } from './postfach-mail-form.component'; @@ -54,7 +54,10 @@ describe('PostfachMailFormComponent', () => { let component: PostfachMailFormComponent; let fixture: ComponentFixture<PostfachMailFormComponent>; - const postfachService: Mock<PostfachService> = mock(PostfachService); + const postfachService: Mock<PostfachService> = { + ...mock(PostfachService), + getSettings: jest.fn().mockReturnValue(of(createPostfachSettings())), + }; const formService: PostfachMailFormservice = new PostfachMailFormservice( new FormBuilder(), useFromMock(postfachService), diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts index 0825838a83338418ca10cc5a43bbbd001c23987a..fbf54ddd0d162ea4c311122f05077b078e05165d 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts @@ -21,25 +21,29 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { UntypedFormBuilder } from '@angular/forms'; import { CommandResource } from '@alfa-client/command-shared'; -import { PostfachService } from '@alfa-client/postfach-shared'; +import { PostfachService, PostfachSettings } from '@alfa-client/postfach-shared'; import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { UntypedFormBuilder } from '@angular/forms'; import { createCommandResource } from 'libs/command-shared/test/command'; -import { createPostfachMailResource } from 'libs/postfach-shared/test/postfach'; +import { + createEmptyPostfachSettings, + createPostfachMailResource, + createPostfachSettings, +} from 'libs/postfach-shared/test/postfach'; import { of } from 'rxjs'; import { PostfachMailFormservice } from './postfach-mail.formservice'; describe('PostfachMailFormservice', () => { let formService: PostfachMailFormservice; - let service: Mock<any>; + let service: Mock<any> = mock(PostfachService); const formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); + const postfachSettings: PostfachSettings = createPostfachSettings(); beforeEach(() => { - service = mock(PostfachService); - + service.getSettings.mockReturnValue(of(postfachSettings)); formService = new PostfachMailFormservice(formBuilder, useFromMock(service)); }); @@ -84,4 +88,29 @@ describe('PostfachMailFormservice', () => { }); }); }); + + describe('initMailBody', () => { + it('should call service', () => { + formService.initMailBody(); + + expect(service.getSettings).toHaveBeenCalled(); + }); + + it('should set field mail body with signatur and newline if signatur is not empty', () => { + formService.initMailBody(); + + const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value; + expect(mailBodyValue).toBe(`\n${postfachSettings.signatur}`); + }); + + it('should not set field mail body if signatur is empty', () => { + service.getSettings.mockReturnValue(of(createEmptyPostfachSettings())); + formService = new PostfachMailFormservice(formBuilder, useFromMock(service)); + + formService.initMailBody(); + + const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value; + expect(mailBodyValue).toBe(null); + }); + }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts index 3e7de900cdaa45e7ebfbbdc66994fb9b874ae594..20b16bb775a0abc4bd57866ec93170756dcf4aa8 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts @@ -21,6 +21,9 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ +import { CommandResource } from '@alfa-client/command-shared'; +import { PostfachService, PostfachSettings } from '@alfa-client/postfach-shared'; +import { AbstractFormService, StateResource } from '@alfa-client/tech-shared'; import { Injectable } from '@angular/core'; import { UntypedFormArray, @@ -28,11 +31,8 @@ import { UntypedFormControl, UntypedFormGroup, } from '@angular/forms'; -import { CommandResource } from '@alfa-client/command-shared'; -import { PostfachService } from '@alfa-client/postfach-shared'; -import { AbstractFormService, StateResource } from '@alfa-client/tech-shared'; import { ReplyOption } from 'libs/postfach-shared/src/lib/postfach.model'; -import { Observable } from 'rxjs'; +import { Observable, first } from 'rxjs'; @Injectable() export class PostfachMailFormservice extends AbstractFormService { @@ -48,6 +48,7 @@ export class PostfachMailFormservice extends AbstractFormService { private postfachService: PostfachService, ) { super(formBuilder); + this.initMailBody(); } protected initForm(): UntypedFormGroup { @@ -59,6 +60,25 @@ export class PostfachMailFormservice extends AbstractFormService { }); } + public initMailBody(): void { + this.postfachService + .getSettings() + .pipe(first((settings) => Boolean(settings.signatur))) + .subscribe((settings: PostfachSettings) => { + this.patchMailBodyWithSignaturAndNewline(settings.signatur); + }); + } + + private patchMailBodyWithSignaturAndNewline(signatur: string) { + this.form + .get(PostfachMailFormservice.FIELD_MAIL_BODY) + .setValue(this.addNewlineAtBeginning(signatur)); + } + + private addNewlineAtBeginning(value: string): string { + return `\n${value}`; + } + protected getPathPrefix(): string { return PostfachMailFormservice.FIELD_PATH_PREFIX; } diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts index 1e6ae6bea4559a733a50f29c4411aedc738c8e1c..71a0fc57deeb55ffbadac5d10f4a9cf49ddecd71 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts @@ -1,12 +1,12 @@ -import { Component, OnInit } from '@angular/core'; import { - Features, FORBIDDEN_REPLY_OPTION_ITEM, POSSIBLE_REPLY_OPTION_ITEM, + PostfachFeatures, PostfachService, } from '@alfa-client/postfach-shared'; import { FormProvider } from '@alfa-client/tech-shared'; import { CheckboxEnumEditorItem } from '@alfa-client/ui'; +import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { PostfachMailFormservice } from '../postfach-mail.formservice'; @@ -19,7 +19,7 @@ import { PostfachMailFormservice } from '../postfach-mail.formservice'; export class PostfachNachrichtReplyEditorContainerComponent implements OnInit { public readonly formServiceClass = PostfachMailFormservice; - public postfachFeatures$: Observable<Features>; + public postfachFeatures$: Observable<PostfachFeatures>; public checkedItem: CheckboxEnumEditorItem = POSSIBLE_REPLY_OPTION_ITEM; public uncheckedItem: CheckboxEnumEditorItem = FORBIDDEN_REPLY_OPTION_ITEM; diff --git a/alfa-client/libs/tech-shared/src/lib/resource/api-resource.service.spec.ts b/alfa-client/libs/tech-shared/src/lib/resource/api-resource.service.spec.ts index 8b559b8b81e03d6f4f1a56f56ac6e1e67e14cf64..977db3428026e075b535d45b53e6cdd9865579fb 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/api-resource.service.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/api-resource.service.spec.ts @@ -5,7 +5,7 @@ import { Observable, of, throwError } from 'rxjs'; import { singleCold, singleHot } from '../../../test//marbles'; import { createProblemDetail } from '../../../test/error'; import { createDummyResource } from '../../../test/resource'; -import { HttpError, ProblemDetail } from '../tech.model'; +import { ProblemDetail } from '../tech.model'; import { ApiResourceService } from './api-resource.service'; import { LinkRelationName, ResourceServiceConfig, SaveResourceData } from './resource.model'; import { ResourceRepository } from './resource.repository'; @@ -65,7 +65,7 @@ describe('ApiResourceService', () => { service.stateResource.next(createStateResource(resourceWithEditLinkRel)); repository.save.mockReturnValue(singleHot(loadedResource)); - const saved: Observable<StateResource<Resource | HttpError>> = service.save(dummyToSave); + const saved: Observable<StateResource<Resource>> = service.save(dummyToSave); expect(saved).toBeObservable(singleCold(createStateResource(loadedResource))); }); diff --git a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts index 1a15c29a582000a5be2378c1163f3a487cfd6d1c..61f1ae622b0c4621da50136718665d0c5a94756e 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.spec.ts @@ -8,7 +8,7 @@ import { Observable, lastValueFrom, of, throwError } from 'rxjs'; import { createProblemDetail } from '../../../test//error'; import { singleCold, singleHot } from '../../../test/marbles'; import { createDummyResource } from '../../../test/resource'; -import { HttpError, ProblemDetail } from '../tech.model'; +import { ProblemDetail } from '../tech.model'; import { LinkRelationName, ResourceServiceConfig } from './resource.model'; import { ResourceRepository } from './resource.repository'; import { ResourceService } from './resource.service'; @@ -408,7 +408,7 @@ describe('ResourceService', () => { service.stateResource.next(createStateResource(resourceWithEditLinkRel)); service.doSave = jest.fn().mockReturnValue(singleHot(loadedResource)); - const saved: Observable<StateResource<Resource | HttpError>> = service.save(dummyToSave); + const saved: Observable<StateResource<Resource>> = service.save(dummyToSave); expect(saved).toBeObservable(singleCold(createStateResource(loadedResource))); }); @@ -441,7 +441,7 @@ describe('ResourceService', () => { service .handleError(<HttpErrorResponse>(<any>error)) - .subscribe((responseError: StateResource<HttpError>) => { + .subscribe((responseError: StateResource<unknown>) => { expect(responseError).toEqual(createErrorStateResource(error)); done(); }); @@ -453,7 +453,7 @@ describe('ResourceService', () => { statusText: 'Internal Server Error', }; - const thrownError$: Observable<StateResource<HttpError>> = service.handleError(error); + const thrownError$: Observable<StateResource<unknown>> = service.handleError(error); expect.assertions(1); expect(lastValueFrom(thrownError$)).rejects.toThrowError('Internal Server Error'); diff --git a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts index a69b290c8037e6c4797ae4afc19a695568f9d1c9..6c9eb0a56f13fb81555b915c436119b742b2ec45 100644 --- a/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts +++ b/alfa-client/libs/tech-shared/src/lib/resource/resource.service.ts @@ -143,7 +143,7 @@ export abstract class ResourceService<B extends Resource, T extends Resource> { this.stateResource.next(createStateResource(resource)); } - public save(toSave: unknown): Observable<StateResource<T | HttpError>> { + public save(toSave: unknown): Observable<StateResource<T>> { const previousResource: T = this.stateResource.value.resource; return this.doSave(previousResource, toSave).pipe( tap((loadedResource: T) => this.stateResource.next(createStateResource(loadedResource))), @@ -152,7 +152,7 @@ export abstract class ResourceService<B extends Resource, T extends Resource> { ); } - handleError(errorResponse: HttpErrorResponse): Observable<StateResource<HttpError>> { + handleError(errorResponse: HttpErrorResponse): Observable<StateResource<T>> { if (isUnprocessableEntity(errorResponse.status)) { return of(createErrorStateResource((<any>errorResponse) as HttpError)); } diff --git a/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.spec.ts b/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.spec.ts index ee4a624cb890cbf0da636f80ae01f1aeb7fdc616..35fd33e57c839f74868240d50a5af8d47773fe79 100644 --- a/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.spec.ts +++ b/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.spec.ts @@ -29,8 +29,13 @@ import { createInvalidParam, createProblemDetail } from 'libs/tech-shared/test/e import { Observable, of } from 'rxjs'; import { AbstractFormService } from './formservice.abstract'; -import { createEmptyStateResource, createErrorStateResource, createStateResource, StateResource } from '../resource/resource.util'; -import { HttpError, InvalidParam, ProblemDetail } from '../tech.model'; +import { + createEmptyStateResource, + createErrorStateResource, + createStateResource, + StateResource, +} from '../resource/resource.util'; +import { InvalidParam, ProblemDetail } from '../tech.model'; import { createCommandResource } from '../../../../command-shared/test/command'; import * as ValidationUtil from '../validation/tech.validation.util'; @@ -64,8 +69,7 @@ describe('AbstractFormService', () => { }); it('should return state resource observable', () => { - const submitObservable: Observable<StateResource<Resource | HttpError>> = - formService.submit(); + const submitObservable: Observable<StateResource<Resource>> = formService.submit(); expect(submitObservable).toBeObservable(cold('(a|)', { a: stateResourceWithError })); }); @@ -113,8 +117,7 @@ describe('AbstractFormService', () => { it('should return stateresource while loading', () => { const commandStateResource: StateResource<CommandResource> = createEmptyStateResource(true); - const result: StateResource<Resource | HttpError> = - formService.handleResponse(commandStateResource); + const result: StateResource<Resource> = formService.handleResponse(commandStateResource); expect(result).toBe(commandStateResource); }); diff --git a/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.ts b/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.ts index 956266f7c268dc575e7e29307b0530a31555f43f..4f225d54b0b1d97d031eb854263bee095aeed03f 100644 --- a/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.ts +++ b/alfa-client/libs/tech-shared/src/lib/service/formservice.abstract.ts @@ -47,16 +47,16 @@ export abstract class AbstractFormService<T extends Resource = Resource> { public submit( afterSubmit: OperatorFunction<StateResource<T>, StateResource<T>> = identity, - ): Observable<StateResource<T | HttpError>> { + ): Observable<StateResource<T>> { return this.doSubmit().pipe( afterSubmit, map((result) => this.handleResponse(result)), ); } - protected abstract doSubmit(): Observable<StateResource<T | HttpError>>; + protected abstract doSubmit(): Observable<StateResource<T>>; - handleResponse(result: StateResource<T | HttpError>): StateResource<T | HttpError> { + handleResponse(result: StateResource<T>): StateResource<T> { if (result.loading) return result; if (hasStateResourceError(result)) { this.handleError(result.error); diff --git a/alfa-client/libs/tech-shared/src/lib/tech.util.ts b/alfa-client/libs/tech-shared/src/lib/tech.util.ts index 55e881a99ac582741b7bea58ddde81b00c5c11b0..805f0501f440c90c2ca425309e05b33a94ae3314 100644 --- a/alfa-client/libs/tech-shared/src/lib/tech.util.ts +++ b/alfa-client/libs/tech-shared/src/lib/tech.util.ts @@ -26,6 +26,7 @@ import { Base64 } from 'js-base64'; import { isEmpty, isNil, isNull, isUndefined } from 'lodash-es'; import { sanitize } from 'sanitize-filename-ts'; import { LinkRelationName } from './resource/resource.model'; + import { ApiError } from './tech.model'; export const EMPTY_STRING: string = ''; diff --git a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/bescheiden.formservice.ts b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/bescheiden.formservice.ts index b079362062868d5fd121503655948db80538f466..cebc1954c540d054f03d4e9e03d2719d9c3c8963 100644 --- a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/bescheiden.formservice.ts +++ b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/bescheiden.formservice.ts @@ -11,7 +11,6 @@ import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/comm import { AbstractFormService, EMPTY_STRING, - HttpError, StateResource, convertToBoolean, formatForDatabase, @@ -161,7 +160,7 @@ export class BescheidenFormService extends AbstractFormService implements OnDest return BescheidenFormService.FIELD_PATH_PREFIX; } - protected doSubmit(): Observable<StateResource<Resource | HttpError>> { + protected doSubmit(): Observable<StateResource<Resource>> { if (this.isPatch() || this.bescheidService.existsBescheidDraft()) { return this.bescheidService.updateBescheid(this.getValue()); } else { @@ -185,7 +184,7 @@ export class BescheidenFormService extends AbstractFormService implements OnDest }); } - public submitDraft(): Observable<StateResource<Resource | HttpError>> { + public submitDraft(): Observable<StateResource<Resource>> { return this.submit().pipe( tapOnCommandSuccessfullyDone(() => this.bescheidService.reloadCurrentVorgang()), ); diff --git a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-steps-content/vorgang-detail-bescheiden-steps-content.component.ts b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-steps-content/vorgang-detail-bescheiden-steps-content.component.ts index ce42b5dcd7153c3e1e12b0eef65028a1586778ff..e7c2bfebe926455e262f0f96fb23bf3ea6e4eedf 100644 --- a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-steps-content/vorgang-detail-bescheiden-steps-content.component.ts +++ b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-steps-content/vorgang-detail-bescheiden-steps-content.component.ts @@ -1,5 +1,4 @@ import { - HttpError, StateResource, createEmptyStateResource, hasStateResourceError, @@ -30,7 +29,7 @@ export class VorgangDetailBescheidenStepsContentComponent implements OnInit { showBescheidErstellungUeberspringen$: Observable<boolean>; - submitResource: StateResource<Resource | HttpError> = createEmptyStateResource(); + submitResource: StateResource<Resource> = createEmptyStateResource(); constructor( private readonly vorgangService: VorgangService, @@ -54,7 +53,7 @@ export class VorgangDetailBescheidenStepsContentComponent implements OnInit { this.formService .submit() .pipe( - tap((resource: StateResource<Resource | HttpError>) => (this.submitResource = resource)), + tap((resource: StateResource<Resource>) => (this.submitResource = resource)), filter(this.noError), first(), ) @@ -72,7 +71,7 @@ export class VorgangDetailBescheidenStepsContentComponent implements OnInit { return this.formService.validateBescheidDocumentExists(); } - noError(stateResource: StateResource<Resource | HttpError>): boolean { + noError(stateResource: StateResource<Resource>): boolean { return isLoaded(stateResource) && !hasStateResourceError(stateResource); } } diff --git a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-weiter-button/vorgang-detail-bescheiden-weiter-button.component.ts b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-weiter-button/vorgang-detail-bescheiden-weiter-button.component.ts index 5e89e7dd34f564986e2d2b48f78919d18c091041..47b2204616e49678ecc4fe4f6df379109f7916f3 100644 --- a/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-weiter-button/vorgang-detail-bescheiden-weiter-button.component.ts +++ b/alfa-client/libs/vorgang-detail/src/lib/vorgang-detail-page/vorgang-detail-bescheiden/vorgang-detail-bescheiden-steps/vorgang-detail-bescheiden-weiter-button/vorgang-detail-bescheiden-weiter-button.component.ts @@ -1,10 +1,5 @@ import { BescheidLinkRel, BescheidService } from '@alfa-client/bescheid-shared'; -import { - HttpError, - StateResource, - createEmptyStateResource, - isLoaded, -} from '@alfa-client/tech-shared'; +import { StateResource, createEmptyStateResource, isLoaded } from '@alfa-client/tech-shared'; import { VorgangService, VorgangWithEingangLinkRel } from '@alfa-client/vorgang-shared'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Resource, hasLink } from '@ngxp/rest'; @@ -16,7 +11,7 @@ import { BescheidenFormService } from '../../bescheiden.formservice'; templateUrl: './vorgang-detail-bescheiden-weiter-button.component.html', }) export class VorgangDetailBescheidenWeiterButtonComponent implements OnInit { - @Input() submitResource: StateResource<Resource | HttpError> = createEmptyStateResource(); + @Input() submitResource: StateResource<Resource> = createEmptyStateResource(); @Output() clickEmitter: EventEmitter<MouseEvent> = new EventEmitter<MouseEvent>(); showButton$: Observable<boolean>; diff --git a/alfa-client/nx.json b/alfa-client/nx.json index da024e6acd9e3b33a78b07915bd508b2f9b12a7a..ef541a7eb5a1b147ff131218b9f498e2d295f344 100644 --- a/alfa-client/nx.json +++ b/alfa-client/nx.json @@ -12,13 +12,13 @@ "@nx/angular:library": { "linter": "eslint", "unitTestRunner": "jest", - "styleext": "scss" + "style": "scss" }, "@nrwl/schematics:component": { - "styleext": "scss" + "style": "scss" }, "@schematics/angular:component": { - "styleext": "scss" + "style": "scss" }, "@nx/angular:component": { "style": "scss" diff --git a/alfa-client/tsconfig.base.json b/alfa-client/tsconfig.base.json index 15284c9f0e8bc51994ae4e9b965a16c8b17d0bb6..718027c42393e9c9066bb1b65c2287c66654a873 100644 --- a/alfa-client/tsconfig.base.json +++ b/alfa-client/tsconfig.base.json @@ -16,7 +16,7 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { - "@admin-client/admin-settings": ["libs/admin-settings/src/index.ts"], + "@admin-client/admin-settings": ["libs/admin/settings/src/index.ts"], "@alfa-client/api-root-shared": ["libs/api-root-shared/src/index.ts"], "@alfa-client/app-shared": ["libs/app-shared/src/index.ts"], "@alfa-client/bescheid": ["libs/bescheid/src/index.ts"], @@ -57,8 +57,7 @@ "@alfa-client/wiedervorlage-shared": ["libs/wiedervorlage-shared/src/index.ts"], "@ods/component": ["libs/design-component/src/index.ts"], "@ods/system": ["libs/design-system/src/index.ts"], - "authentication": ["libs/authentication/src/index.ts"], - "test": ["libs/test/src/index.ts"] + "authentication": ["libs/authentication/src/index.ts"] } }, "exclude": ["node_modules", "tmp"] diff --git a/alfa-server/pom.xml b/alfa-server/pom.xml index 352336b4ac3074f81a411207f393d1b590933cbf..8310c3d2875b5bd9052d1a8704a958ecb3957786 100644 --- a/alfa-server/pom.xml +++ b/alfa-server/pom.xml @@ -24,18 +24,19 @@ <artifactId>alfa-service</artifactId> <version>${project.version}</version> </dependency> - <dependency> <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa-xdomea</artifactId> <version>${project.version}</version> </dependency> - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> - + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-config</artifactId> + </dependency> <!-- aspectJ --> <dependency> <groupId>org.aspectj</groupId> @@ -130,4 +131,4 @@ </plugins> </build> -</project> +</project> \ No newline at end of file diff --git a/alfa-server/src/main/resources/application.yml b/alfa-server/src/main/resources/application.yml index 0f0c8e24b2ea7023c57f11e22b8f3d7c997864e3..f5642fefecceda5c3f88a333ad14c835c5394bc1 100644 --- a/alfa-server/src/main/resources/application.yml +++ b/alfa-server/src/main/resources/application.yml @@ -23,6 +23,8 @@ spring: jwt: issuer-uri: ${ozgcloud.oauth2.issuer-uri} jwk-set-uri: ${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs + config: + import: optional:configserver:${ozgcloud_administration_address:http://localhost:8888}/configserver/ server: http2: @@ -51,7 +53,7 @@ management: endpoints: web: exposure: - include: health,prometheus + include: health,prometheus,refresh grpc: client: diff --git a/alfa-service/pom.xml b/alfa-service/pom.xml index 24d69e9a5b0678baaea9c632062d636ba513d436..86daeeea0530386f5a9b708e593c5b46362e622d 100644 --- a/alfa-service/pom.xml +++ b/alfa-service/pom.xml @@ -84,6 +84,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-config</artifactId> + </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailController.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailController.java index 42bc7f1da0053aaabad81228c24faf6e82ecf20a..8f985cf34a9f199baf42d7d7f0761b6d5d30a2c3 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailController.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailController.java @@ -66,7 +66,8 @@ public class PostfachMailController { static final String PDF_NAME_TEMPLATE = "%s_%s_Nachrichten.pdf"; static final DateTimeFormatter PDF_NAME_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); - private final PostfachMailService service; + private final PostfachMailService postfachMailService; + private final PostfachSettingsService postfachSettingsService; private final PostfachMailModelAssembler assembler; @@ -74,18 +75,10 @@ public class PostfachMailController { private final BinaryFileController binaryFileController; @GetMapping(params = PARAM_VORGANG_ID) - public RepresentationModel<EntityModel<Postfach>> getAll(@RequestParam String vorgangId) { + public RepresentationModel<EntityModel<PostfachSettings>> getAll(@RequestParam String vorgangId) { var vorgang = getVorgang(vorgangId); - - return assembler.toCollectionModel(sort(service.getAll(vorgangId)), buildPostfach(vorgang), vorgang); - } - - Postfach buildPostfach(VorgangWithEingang vorgang) { - return Postfach.builder() - .features(Features.builder() - .reply(service.isReplyToMessageAllowed(vorgang)) - .build()) - .build(); + var postfachSetting = postfachSettingsService.getPostfachSettings(vorgang); + return assembler.toCollectionModel(sort(postfachMailService.getAll(vorgangId)), vorgang, postfachSetting); } Stream<PostfachMail> sort(Stream<PostfachMail> nachrichten) { @@ -104,7 +97,7 @@ public class PostfachMailController { } StreamingResponseBody createDownloadStreamingBody(VorgangWithEingang vorgang) { - return out -> service.getAllAsPdf(vorgang, out); + return out -> postfachMailService.getAllAsPdf(vorgang, out); } ResponseEntity<StreamingResponseBody> buildResponseEntity(VorgangWithEingang vorgang, StreamingResponseBody responseBody) { @@ -119,12 +112,12 @@ public class PostfachMailController { } public boolean isPostfachConfigured() { - return service.isPostfachConfigured(); + return postfachSettingsService.isPostfachConfigured(); } @GetMapping("{nachrichtId}/attachments") public CollectionModel<EntityModel<OzgFile>> findAttachments(@PathVariable PostfachNachrichtId nachrichtId) { - var postfachNachricht = service.findById(nachrichtId); + var postfachNachricht = postfachMailService.findById(nachrichtId); return binaryFileController.getFiles(postfachNachricht.getAttachments()); } diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java index 52c0ba965c916de9bbcf463f4fc6a411c5be7c08..e82e85c2618727e310645ac8cf573ceef5d981de 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssembler.java @@ -32,7 +32,6 @@ import java.util.stream.Stream; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.Link; import org.springframework.hateoas.RepresentationModel; @@ -50,8 +49,10 @@ import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; import de.ozgcloud.alfa.vorgang.VorgangController; import de.ozgcloud.alfa.vorgang.VorgangHead; import de.ozgcloud.alfa.vorgang.VorgangWithEingang; +import lombok.RequiredArgsConstructor; @Component +@RequiredArgsConstructor class PostfachMailModelAssembler implements RepresentationModelAssembler<PostfachMail, EntityModel<PostfachMail>> { public static final String REL_SEND_POSTFACH_MAIL = "sendPostfachMail"; @@ -77,17 +78,12 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> Optional.ofNullable(postfachNachricht.getCreatedBy()) .map(createdBy -> !createdBy.toString().startsWith(SYSTEM_USER_IDENTIFIER)).orElse(false); - @Autowired - private UserManagerUrlProvider userManagerUrlProvider; + private final UserManagerUrlProvider userManagerUrlProvider; - public RepresentationModel<EntityModel<Postfach>> toCollectionModel( - Stream<PostfachMail> postfachMails, Postfach postfach, VorgangWithEingang vorgang) { + public RepresentationModel<EntityModel<PostfachSettings>> toCollectionModel(Stream<PostfachMail> postfachMails, VorgangWithEingang vorgang, + PostfachSettings postfachSettings) { - RepresentationModel<EntityModel<Postfach>> model = HalModelBuilder - .halModelOf(postfach) - .link(linkTo(methodOn(PostfachMailController.class).getAll(vorgang.getId())).withSelfRel()) - .embed(postfachMails.map(this::toModel)) - .build(); + var model = buildHalRepresentationModel(postfachMails, vorgang, postfachSettings); if (hasServiceKonto(vorgang)) { addPostfachNachrichtLinks(model, vorgang); @@ -95,10 +91,35 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac return model; } + RepresentationModel<EntityModel<PostfachSettings>> buildHalRepresentationModel(Stream<PostfachMail> postfachMails, VorgangWithEingang vorgang, + PostfachSettings postfachSettings) { + return HalModelBuilder + .halModelOf(postfachSettings) + .link(linkTo(methodOn(PostfachMailController.class).getAll(vorgang.getId())).withSelfRel()) + .embed(postfachMails.map(this::toModel)) + .build(); + } + boolean hasServiceKonto(VorgangWithEingang vorgang) { return Optional.ofNullable(vorgang.getHeader()).map(VorgangHead::getServiceKonto).isPresent(); } + void addPostfachNachrichtLinks(RepresentationModel<EntityModel<PostfachSettings>> model, VorgangWithEingang vorgang) { + var vorgangId = vorgang.getId(); + + if (vorgang.getStatus() != VorgangStatus.ZU_LOESCHEN) { + model.add(linkTo(methodOn(PostfachMailCommandByVorgangController.class).sendPostfachMail(vorgangId, null)) + .withRel(REL_SEND_POSTFACH_MAIL)); + } + + model.add(linkTo(BinaryFileController.class).slash(vorgangId).slash(POSTFACH_NACHRICHT_ATTACHMENT_FIELD).slash(FILE_PATH) + .withRel(REL_UPLOAD_ATTACHMENT)); + + if (vorgang.isHasNewPostfachNachricht()) { + model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD).withRel(REL_RESET_NEW_POSTFACH_MAIL)); + } + } + @Override public EntityModel<PostfachMail> toModel(PostfachMail postfachMail) { var selfLink = linkTo(PostfachMailController.class).slash(postfachMail.getId()); @@ -120,20 +141,4 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac .buildModel(); } - private void addPostfachNachrichtLinks(RepresentationModel<EntityModel<Postfach>> model, VorgangWithEingang vorgang) { - var vorgangId = vorgang.getId(); - - if (vorgang.getStatus() != VorgangStatus.ZU_LOESCHEN) { - model.add(linkTo(methodOn(PostfachMailCommandByVorgangController.class).sendPostfachMail(vorgangId, null)) - .withRel(REL_SEND_POSTFACH_MAIL)); - } - - model.add(linkTo(BinaryFileController.class).slash(vorgangId).slash(POSTFACH_NACHRICHT_ATTACHMENT_FIELD).slash(FILE_PATH) - .withRel(REL_UPLOAD_ATTACHMENT)); - - if (vorgang.isHasNewPostfachNachricht()) { - model.add(linkTo(VorgangController.class).slash(vorgangId).slash(HAS_NEW_POSTFACH_NACHRICHT_FIELD).withRel(REL_RESET_NEW_POSTFACH_MAIL)); - } - } - } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailService.java index 17c5a69936b94b265c1eaf802fcc4f49802aca91..b46e278275cb133aca63f025afa69c75633a4a05 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachMailService.java @@ -28,14 +28,12 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import org.springframework.stereotype.Service; -import de.ozgcloud.alfa.common.FeatureToggleProperties; import de.ozgcloud.alfa.common.binaryfile.BinaryFileService; import de.ozgcloud.alfa.common.binaryfile.FileId; import de.ozgcloud.alfa.common.command.Command; @@ -46,7 +44,6 @@ import de.ozgcloud.alfa.common.file.OzgFile; import de.ozgcloud.alfa.common.user.UserManagerUrlProvider; import de.ozgcloud.alfa.common.user.UserProfile; import de.ozgcloud.alfa.common.user.UserService; -import de.ozgcloud.alfa.vorgang.ServiceKonto; import de.ozgcloud.alfa.vorgang.VorgangWithEingang; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; @@ -56,16 +53,12 @@ import lombok.extern.log4j.Log4j2; @Service class PostfachMailService { - private PostfachConfigGroup postfachConfigGroup; - private final PostfachMailRemoteService remoteService; private final PostfachNachrichtPdfService pdfService; private final BinaryFileService fileService; private final UserService userService; private final CommandService commandService; - private final FeatureToggleProperties featureToggleProperties; - public PostfachMail findById(PostfachNachrichtId nachrichtId) { return remoteService.findById(nachrichtId) .orElseThrow(() -> new ResourceNotFoundException(PostfachMail.class, nachrichtId)); @@ -85,13 +78,6 @@ class PostfachMailService { } } - public boolean isPostfachConfigured() { - if (Objects.isNull(postfachConfigGroup)) { - postfachConfigGroup = remoteService.getPostfachConfig(); - } - return postfachConfigGroup.isConfigured(); - } - public OutputStream getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) { var postfachNachrichtPdfDataList = buildPostfachNachrichtPdfDataList(vorgang.getId()); @@ -143,27 +129,4 @@ class PostfachMailService { .map(created -> UserProfile.builder().id(created).build()) .orElseGet(() -> null); } - - public boolean isReplyToMessageAllowed(VorgangWithEingang vorgang) { - return Optional.ofNullable(vorgang.getHeader().getServiceKonto()) - .map(ServiceKonto::getType) - .map(this::isReplyAllowed) - .orElse(false); - } - - boolean isReplyAllowed(String serviceKontoType) { - if (featureToggleProperties.isReplyAlwaysAllowed()) { - return true; - } - - if (!isPostfachConfigured()) { - return false; - } - - return postfachConfigGroup.getPostfachConfigs().stream() - .filter(postfachConfig -> postfachConfig.getType().equalsIgnoreCase(serviceKontoType)) - .map(PostfachConfig::isReplyAllowed) - .findFirst() - .orElse(false); - } } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachProperties.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..e6d7b0dea5e3fd6e4951c8df5447ab43a45d2a97 --- /dev/null +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachProperties.java @@ -0,0 +1,24 @@ +package de.ozgcloud.alfa.postfach; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Configuration; + +import lombok.Getter; +import lombok.Setter; + +@Configuration +@ConfigurationProperties(prefix = PostfachProperties.PREFIX) +@RefreshScope +@Getter +@Setter +public class PostfachProperties { + + static final String PREFIX = "ozgcloud.postfach"; + + /** + * Signature appended to messages. Configured by administration config server. + */ + private String signatur = ""; + +} diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Postfach.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettings.java similarity index 80% rename from alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Postfach.java rename to alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettings.java index 804b5396f6dd1312d65f5be8c4758d0782b753c7..bae33daefcdda7f03967c0d8d36d3cee8e9750e9 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Postfach.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettings.java @@ -9,8 +9,9 @@ import lombok.Setter; @Setter @AllArgsConstructor @Builder -class Postfach { +class PostfachSettings { private Features features; + private Settings settings; } diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettingsService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettingsService.java new file mode 100644 index 0000000000000000000000000000000000000000..e42fc707246eba12df26de9cb20c31a6f6598262 --- /dev/null +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/PostfachSettingsService.java @@ -0,0 +1,74 @@ +package de.ozgcloud.alfa.postfach; + +import java.util.Objects; +import java.util.Optional; + +import org.springframework.cloud.endpoint.RefreshEndpoint; +import org.springframework.stereotype.Service; + +import de.ozgcloud.alfa.common.FeatureToggleProperties; +import de.ozgcloud.alfa.vorgang.ServiceKonto; +import de.ozgcloud.alfa.vorgang.VorgangWithEingang; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +class PostfachSettingsService { + + private PostfachConfigGroup postfachConfigGroup; + + private final PostfachMailRemoteService remoteService; + private final RefreshEndpoint refreshEndpoint; + private final PostfachProperties postfachProperties; + private final FeatureToggleProperties featureToggleProperties; + + public boolean isPostfachConfigured() { + if (Objects.isNull(postfachConfigGroup)) { + postfachConfigGroup = remoteService.getPostfachConfig(); + } + return postfachConfigGroup.isConfigured(); + } + + public PostfachSettings getPostfachSettings(VorgangWithEingang vorgang) { + return PostfachSettings.builder() + .features(Features.builder() + .reply(isReplyToMessageAllowed(vorgang)) + .build()) + .settings(Settings.builder() + .signatur(getSignatur()) + .build()) + .build(); + } + + String getSignatur() { + refreshPostfachProperties(); + return postfachProperties.getSignatur(); + } + + void refreshPostfachProperties() { + refreshEndpoint.refresh(); + } + + boolean isReplyToMessageAllowed(VorgangWithEingang vorgang) { + return Optional.ofNullable(vorgang.getHeader().getServiceKonto()) + .map(ServiceKonto::getType) + .map(this::isReplyAllowed) + .orElse(false); + } + + boolean isReplyAllowed(String serviceKontoType) { + if (featureToggleProperties.isReplyAlwaysAllowed()) { + return true; + } + + if (!isPostfachConfigured()) { + return false; + } + + return postfachConfigGroup.getPostfachConfigs().stream() + .filter(postfachConfig -> postfachConfig.getType().equalsIgnoreCase(serviceKontoType)) + .map(PostfachConfig::isReplyAllowed) + .findFirst() + .orElse(false); + } +} diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Settings.java b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Settings.java new file mode 100644 index 0000000000000000000000000000000000000000..8f28f2aea75d803f8c95e0851b384833087f343f --- /dev/null +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/postfach/Settings.java @@ -0,0 +1,12 @@ +package de.ozgcloud.alfa.postfach; + +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +class Settings { + + private String signatur; + +} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailControllerTest.java index 17f732923cf5995bae45c8521461e328b84b490c..d33010bf633ca9ecff42b8816dc23f4ea38bf980 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailControllerTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailControllerTest.java @@ -23,7 +23,6 @@ */ package de.ozgcloud.alfa.postfach; -import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -63,7 +62,10 @@ class PostfachMailControllerTest { private PostfachMailController controller; @Mock - private PostfachMailService service; + private PostfachMailService postfachMailService; + + @Mock + private PostfachSettingsService postfachSettingsService; @Mock private PostfachMailModelAssembler assembler; @@ -85,23 +87,23 @@ class PostfachMailControllerTest { class TestGetAll { private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); - private final Postfach postfach = PostfachTestFactory.create(); private final Stream<PostfachMail> postfachMails = Stream.of(PostfachMailTestFactory.create()); private final Stream<PostfachMail> sortedPostfachMails = Stream.of(PostfachMailTestFactory.create()); + private final PostfachSettings postfachSettings = PostfachSettingsTestFactory.create(); @BeforeEach void mockVorgangController() { when(vorgangController.getVorgang(anyString())).thenReturn(vorgang); - when(service.getAll(VorgangHeaderTestFactory.ID)).thenReturn(postfachMails); - doReturn(postfach).when(controller).buildPostfach(vorgang); + when(postfachMailService.getAll(VorgangHeaderTestFactory.ID)).thenReturn(postfachMails); doReturn(sortedPostfachMails).when(controller).sort(postfachMails); + when(postfachSettingsService.getPostfachSettings(vorgang)).thenReturn(postfachSettings); } @Test void shouldCallService() { doRequest(); - verify(service).getAll(VorgangHeaderTestFactory.ID); + verify(postfachMailService).getAll(VorgangHeaderTestFactory.ID); } @Test @@ -112,24 +114,24 @@ class PostfachMailControllerTest { } @Test - void shouldCallModelAssembler() { + void shouldGetPostfachSettings() { doRequest(); - verify(assembler).toCollectionModel(sortedPostfachMails, postfach, vorgang); + verify(postfachSettingsService).getPostfachSettings(vorgang); } @Test - void shouldSortPostfachMails() { + void shouldCallModelAssembler() { doRequest(); - verify(controller).sort(postfachMails); + verify(assembler).toCollectionModel(sortedPostfachMails, vorgang, postfachSettings); } @Test - void shouldBuildPostfach() { + void shouldSortPostfachMails() { doRequest(); - verify(controller).buildPostfach(vorgang); + verify(controller).sort(postfachMails); } @SneakyThrows @@ -139,32 +141,6 @@ class PostfachMailControllerTest { } } - @Nested - class TestBuildPostfach { - - private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); - - @Test - void shouldCheckIsReplyAllowed() { - callController(); - - verify(service).isReplyToMessageAllowed(any(VorgangWithEingang.class)); - } - - @Test - void shouldSetIsReplyAllowedFeature() { - when(service.isReplyToMessageAllowed(vorgang)).thenReturn(true); - - var postfach = callController(); - - assertThat(postfach.getFeatures().isReply()).isTrue(); - } - - private Postfach callController() { - return controller.buildPostfach(vorgang); - } - } - @DisplayName("Get all as pdf") @Nested class TestGetAllAsPdf { @@ -191,7 +167,7 @@ class PostfachMailControllerTest { void shouldCallService() { doRequest(); - verify(service).getAllAsPdf(eq(vorgang), any(OutputStream.class)); + verify(postfachMailService).getAllAsPdf(eq(vorgang), any(OutputStream.class)); } @Test @@ -258,7 +234,7 @@ class PostfachMailControllerTest { void shouldCallServiceGetAllAsPdf() throws IOException { controller.createDownloadStreamingBody(vorgang).writeTo(out); - verify(service).getAllAsPdf(eq(vorgang), any()); + verify(postfachMailService).getAllAsPdf(eq(vorgang), any()); } } @@ -269,7 +245,7 @@ class PostfachMailControllerTest { @BeforeEach void init() { - when(service.findById(any())).thenReturn(PostfachMailTestFactory.create()); + when(postfachMailService.findById(any())).thenReturn(PostfachMailTestFactory.create()); } @Test @@ -281,7 +257,7 @@ class PostfachMailControllerTest { void shouldCallService() throws Exception { doRequest(); - verify(service).findById(PostfachNachrichtId.from(PostfachMailTestFactory.ID)); + verify(postfachMailService).findById(PostfachNachrichtId.from(PostfachMailTestFactory.ID)); } @Test @@ -305,7 +281,7 @@ class PostfachMailControllerTest { void shouldCallService() { controller.isPostfachConfigured(); - verify(service).isPostfachConfigured(); + verify(postfachSettingsService).isPostfachConfigured(); } } diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java index c69adafddb5363490bd3e172e9be3edc81732bf6..1338bf82ddf79b9680a48e3dd866eb6d93f46f90 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailModelAssemblerTest.java @@ -24,9 +24,9 @@ package de.ozgcloud.alfa.postfach; import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import java.util.List; import java.util.UUID; import java.util.stream.Stream; @@ -36,35 +36,44 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; import org.springframework.hateoas.RepresentationModel; +import org.springframework.hateoas.mediatype.hal.HalModelBuilder; +import org.springframework.web.util.UriComponentsBuilder; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import de.ozgcloud.alfa.common.user.UserId; import de.ozgcloud.alfa.common.user.UserManagerUrlProvider; import de.ozgcloud.alfa.postfach.PostfachMail.Direction; import de.ozgcloud.alfa.postfach.PostfachMailController.PostfachMailCommandByVorgangController; +import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory; import de.ozgcloud.alfa.vorgang.Vorgang.VorgangStatus; import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory; import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory; import de.ozgcloud.alfa.vorgang.VorgangWithEingang; import de.ozgcloud.alfa.vorgang.VorgangWithEingangTestFactory; +import lombok.SneakyThrows; class PostfachMailModelAssemblerTest { @InjectMocks + @Spy private PostfachMailModelAssembler modelAssembler; @Mock private UserManagerUrlProvider userManagerUrlProvider; - @BeforeEach - void mock() { - when(userManagerUrlProvider.isConfiguredForUserProfile()).thenReturn(false); - } - @Nested - class TestLinksOnModel { + class TestToModel { + + @BeforeEach + void mock() { + when(userManagerUrlProvider.isConfiguredForUserProfile()).thenReturn(false); + } @Test void shouldHaveSelfLink() { @@ -78,7 +87,7 @@ class PostfachMailModelAssemblerTest { @DisplayName("if 'sentSuccessful' is false, add link") @Test - void shouldHaveResendLink() { + void shouldBePresent() { var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().sentSuccessful(false).build()) .getLink(PostfachMailModelAssembler.REL_RESEND_POSTFACH_MAIL); @@ -86,78 +95,51 @@ class PostfachMailModelAssemblerTest { .isEqualTo("/api/postfachMails/" + PostfachMailTestFactory.ID + "/commands"); } - @Nested - class ShouldNOTHaveResendLink { - - @DisplayName("if 'sentSuccessful' is true, hide link") - @Test - void ifSuccessfulSent() { - var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().sentSuccessful(true).build()) - .getLink(PostfachMailModelAssembler.REL_RESEND_POSTFACH_MAIL); - - assertThat(link).isNotPresent(); - } - - @Test - void ifNotJetTriedToSend() { - var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(false).sentAt(null).build(); - - var link = modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_RESEND_POSTFACH_MAIL); + @DisplayName("if 'sentSuccessful' is true, hide link") + @Test + void shouldNotBePresentIfSuccessfulSent() { + var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().sentSuccessful(true).build()) + .getLink(PostfachMailModelAssembler.REL_RESEND_POSTFACH_MAIL); - assertThat(link).isNotPresent(); - } + assertThat(link).isNotPresent(); } - @Nested - class SendLink { - @DisplayName("should be present if nachricht not jet tried to send") - @Test - void shouldBePresent() { - var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(false).sentAt(null).build(); - - var link = modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_SEND); - - assertThat(link).isPresent().get().extracting(Link::getHref) - .isEqualTo("/api/postfachMails/" + PostfachMailTestFactory.ID + "/commands"); - } + @Test + void shouldNotBePresentIfNotYetTriedToSend() { + var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(false).sentAt(null).build(); - @Nested - class ShouldNOTBePresent { - @Test - void ifNachrichtSent() { - var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(true).build(); + var link = modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_RESEND_POSTFACH_MAIL); - assertThat(modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_SEND)).isNotPresent(); - } - } + assertThat(link).isNotPresent(); } + } @Nested - class ResetHasNewPostfachNachricht { - Stream<PostfachMail> mails = List.of(PostfachMailTestFactory.create()).stream(); + class SendLink { + @DisplayName("should be present if nachricht not jet tried to send") @Test - void shouldHaveLink() { - var link = modelAssembler.toCollectionModel(mails, PostfachTestFactory.create(), VorgangWithEingangTestFactory.create()) - .getLink(PostfachMailModelAssembler.REL_RESET_NEW_POSTFACH_MAIL); + void shouldBePresent() { + var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(false).sentAt(null).build(); - assertThat(link).isPresent(); + var link = modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_SEND); + + assertThat(link).isPresent().get().extracting(Link::getHref) + .isEqualTo("/api/postfachMails/" + PostfachMailTestFactory.ID + "/commands"); } @Test - void shouldNotNaveLink() { - var link = modelAssembler - .toCollectionModel(mails, PostfachTestFactory.create(), - VorgangWithEingangTestFactory.createBuilder().hasNewPostfachNachricht(false).build()) - .getLink(PostfachMailModelAssembler.REL_RESET_NEW_POSTFACH_MAIL); + void shouldNotBePresentIfNachrichtSent() { + var nachricht = PostfachMailTestFactory.createBuilder().sentSuccessful(true).build(); - assertThat(link).isNotPresent(); + assertThat(modelAssembler.toModel(nachricht).getLink(PostfachMailModelAssembler.REL_SEND)).isNotPresent(); } + } @Nested - class ToAttachments { + class AttachmentsLink { @Test @DisplayName("should be present if attachments present") @@ -170,7 +152,7 @@ class PostfachMailModelAssemblerTest { @Test @DisplayName("should NOT be present if there are no attachments") - void shouldNOTBePresent() { + void shouldNotBePresentOnNoAttachments() { var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().clearAttachments().build()) .getLink(PostfachMailModelAssembler.REL_ATTACHMENTS); @@ -204,7 +186,7 @@ class PostfachMailModelAssemblerTest { @DisplayName("should not be present if the value of createdBy starts with 'system'") @Test - void shouldNOTBePresentOnSystemUser() { + void shouldNotBePresentOnSystemUser() { var link = modelAssembler .toModel(PostfachMailTestFactory.createBuilder() .createdBy(UserId.from(PostfachMailModelAssembler.SYSTEM_USER_IDENTIFIER + UUID.randomUUID().toString())).build()) @@ -300,108 +282,214 @@ class PostfachMailModelAssemblerTest { } } - @DisplayName("On collection model link") @Nested - class TestLinksOnCollectionModel { + class TestToCollectionModel { + + private final Stream<PostfachMail> mails = Stream.of(PostfachMailTestFactory.create()); + private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); + private final PostfachSettings postfachSettings = PostfachSettingsTestFactory.create(); + + @Mock + private RepresentationModel<EntityModel<PostfachSettings>> model; + + @BeforeEach + void setUpMocks() { + doReturn(model).when(modelAssembler).buildHalRepresentationModel(mails, vorgang, postfachSettings); + } @Test - void shouldHaveSelfLink() { - var model = modelAssembler - .toCollectionModel(Stream.of(PostfachMailTestFactory.create()), PostfachTestFactory.create(), - VorgangWithEingangTestFactory.create()); - var selfLink = model.getLink(IanaLinkRelations.SELF_VALUE); + void shouldBuildHalRepresentationModel() { + callModelAssembler(); - assertThat(selfLink).isPresent(); - assertThat(selfLink.get().getHref()).isEqualTo( - String.format("%s?%s=%s", PostfachMailController.PATH, PostfachMailController.PARAM_VORGANG_ID, VorgangHeaderTestFactory.ID)); + verify(modelAssembler).buildHalRepresentationModel(mails, vorgang, postfachSettings); } - @DisplayName("send postfach mail") @Nested - class SendPostfachMailLink { - - private final String sendPostfachMailLinkRel = PostfachMailModelAssembler.REL_SEND_POSTFACH_MAIL; + class OnHasServiceKonto { @Test - void shouldExistsOnExistingServiceKonto() { - var link = toCollectionModel(VorgangWithEingangTestFactory.create()).getLink(sendPostfachMailLinkRel); + void shouldAddPostfachNachrichtLinks() { + doReturn(true).when(modelAssembler).hasServiceKonto(vorgang); + + callModelAssembler(); - assertThat(link).isPresent(); - assertThat(link.get().getHref()) - .isEqualTo(PostfachMailCommandByVorgangController.PATH.replace("{vorgangId}", - VorgangHeaderTestFactory.ID)); + verify(modelAssembler).addPostfachNachrichtLinks(model, vorgang); } + } + + @Nested + class OnHasNotServiceKonto { @Test - void shouldNotExist() { - var link = toCollectionModel(VorgangWithEingangTestFactory.createBuilder().status(VorgangStatus.ZU_LOESCHEN).build()).getLink( - sendPostfachMailLinkRel); + void shouldAddPostfachNachrichtLinks() { + doReturn(false).when(modelAssembler).hasServiceKonto(vorgang); - assertThat(link).isEmpty(); + callModelAssembler(); + + verify(modelAssembler, never()).addPostfachNachrichtLinks(any(), any()); } + } - @DisplayName("should NOT exists") - @Nested - class TestNotExists { + @Test + void shouldReturnModel() { + var returnedModel = callModelAssembler(); - @Test - void onMissingVorgangHeader() { - var vorgangWithoutHeader = VorgangWithEingangTestFactory.createBuilder().header(null).build(); + assertThat(returnedModel).isEqualTo(model); + } - var link = toCollectionModel(vorgangWithoutHeader).getLink(sendPostfachMailLinkRel); + private RepresentationModel<EntityModel<PostfachSettings>> callModelAssembler() { + return modelAssembler.toCollectionModel(mails, vorgang, postfachSettings); + } + } - assertThat(link).isNotPresent(); - } + @Nested + class TestBuildHalRepresentationModel { - @Test - void onMissingServiceKonto() { - var vorgangWithoutServiceKonto = VorgangWithEingangTestFactory.createBuilder().header( - VorgangHeadTestFactory.createBuilder().serviceKonto(null).build()).build(); + private final PostfachMail postfachMail = PostfachMailTestFactory.create(); + private final Stream<PostfachMail> mails = Stream.of(postfachMail); + private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); + private final PostfachSettings postfachSettings = PostfachSettingsTestFactory.create(); - var link = toCollectionModel(vorgangWithoutServiceKonto).getLink(sendPostfachMailLinkRel); + @Test + void shouldHavePostfachAsContent() { + var model = (EntityModel<PostfachSettings>) callModelAssembler(); - assertThat(link).isNotPresent(); - } + assertThat(model.getContent()).isEqualTo(postfachSettings); + } + + @Test + void shouldAddSelfLink() { + var model = callModelAssembler(); + var selfLink = model.getLink(IanaLinkRelations.SELF_VALUE); + + assertThat(selfLink).get().extracting(Link::getHref).isEqualTo( + String.format("%s?%s=%s", PostfachMailController.PATH, PostfachMailController.PARAM_VORGANG_ID, VorgangHeaderTestFactory.ID)); + } + + @Test + void shouldCallToModel() { + callModelAssembler(); + + verify(modelAssembler).toModel(postfachMail); + } + + @Test + @SneakyThrows + void shouldContainPostfachMails() { + var objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); + doReturn(EntityModel.of(postfachMail)).when(modelAssembler).toModel(postfachMail); + + var model = callModelAssembler(); + + assertThat(objectMapper.writeValueAsString(model)).contains(objectMapper.writeValueAsString(EntityModel.of(postfachMail))); + } + + private RepresentationModel<EntityModel<PostfachSettings>> callModelAssembler() { + return modelAssembler.buildHalRepresentationModel(mails, vorgang, postfachSettings); + } + + } + + @Nested + class TestHasServiceKonto { + + @Test + void shouldReturnTrueIfServicekontoIsPresent() { + var hasServiceKonto = modelAssembler.hasServiceKonto(VorgangWithEingangTestFactory.createBuilder() + .header(VorgangHeadTestFactory.createBuilder().serviceKonto(ServiceKontoTestFactory.create()).build()).build()); + + assertThat(hasServiceKonto).isTrue(); + } + + @Test + void shouldReturnFalseIfServicekontoIsNotPresent() { + var hasServiceKonto = modelAssembler.hasServiceKonto(VorgangWithEingangTestFactory.createBuilder() + .header(VorgangHeadTestFactory.createBuilder().serviceKonto(null).build()).build()); + + assertThat(hasServiceKonto).isFalse(); + } + + @Test + void shouldReturnFalseOnMissingVorgangHeader() { + var hasServiceKonto = modelAssembler.hasServiceKonto(VorgangWithEingangTestFactory.createBuilder() + .header(null).build()); + + assertThat(hasServiceKonto).isFalse(); + } + } + + @Nested + class TestAddPostfachNachrichtLinks { + + private final PostfachSettings postfach = PostfachSettingsTestFactory.create(); + + private RepresentationModel<EntityModel<PostfachSettings>> model = HalModelBuilder + .halModelOf(postfach) + .build(); + + @Nested + class ResetNewPostfachNachrichtLink { + @Test + void shouldBePresent() { + callModelAssembler(VorgangWithEingangTestFactory.create()); + + var link = model.getLink(PostfachMailModelAssembler.REL_RESET_NEW_POSTFACH_MAIL); + assertThat(link).isPresent().get().extracting(Link::getHref) + .isEqualTo(UriComponentsBuilder.fromUriString("/api/vorgangs") + .pathSegment(VorgangHeaderTestFactory.ID, "hasNewPostfachNachricht") + .build().toString()); + } + + @Test + void shouldNotBePresent() { + callModelAssembler(VorgangWithEingangTestFactory.createBuilder().hasNewPostfachNachricht(false).build()); + + var link = model.getLink(PostfachMailModelAssembler.REL_RESET_NEW_POSTFACH_MAIL); + assertThat(link).isNotPresent(); } } + @DisplayName("send postfach mail") @Nested - class UploadAttachmentLink { + class SendPostfachMailLink { - private final String uploadAttachmentLinkRel = PostfachMailModelAssembler.REL_UPLOAD_ATTACHMENT; + private final String sendPostfachMailLinkRel = PostfachMailModelAssembler.REL_SEND_POSTFACH_MAIL; @Test - void shouldHaveLink() { - var link = toCollectionModel(VorgangWithEingangTestFactory.create()).getLink(uploadAttachmentLinkRel); + void shouldExist() { + callModelAssembler(VorgangWithEingangTestFactory.create()); - assertThat(link).isPresent(); - assertThat(link.get().getHref()) - .isEqualTo(String.format("/api/binaryFiles/%s/postfachNachrichtAttachment/file", VorgangHeaderTestFactory.ID)); + var link = model.getLink(sendPostfachMailLinkRel); + assertThat(link).get().extracting(Link::getHref) + .isEqualTo(PostfachMailCommandByVorgangController.PATH.replace("{vorgangId}", VorgangHeaderTestFactory.ID)); } @Test - void shouldNotHaveLink() { - var vorgangWithoutServiceKonto = VorgangWithEingangTestFactory.createBuilder().header( - VorgangHeadTestFactory.createBuilder().serviceKonto(null).build()).build(); - var link = toCollectionModel(vorgangWithoutServiceKonto).getLink(uploadAttachmentLinkRel); + void shouldNotExistOnStatusZuLoeschen() { + callModelAssembler(VorgangWithEingangTestFactory.createBuilder().status(VorgangStatus.ZU_LOESCHEN).build()); - assertThat(link).isNotPresent(); + var link = model.getLink(sendPostfachMailLinkRel); + assertThat(link).isEmpty(); } } - private RepresentationModel<EntityModel<Postfach>> toCollectionModel(VorgangWithEingang vorgang) { - return modelAssembler.toCollectionModel( - Stream.of(PostfachMailTestFactory.create()), - buildPostfach(), - vorgang); + @Nested + class UploadAttachmentLink { + + private final String uploadAttachmentLinkRel = PostfachMailModelAssembler.REL_UPLOAD_ATTACHMENT; + + @Test + void shouldBePresent() { + callModelAssembler(VorgangWithEingangTestFactory.create()); + + var link = model.getLink(uploadAttachmentLinkRel); + assertThat(link).get().extracting(Link::getHref) + .isEqualTo(String.format("/api/binaryFiles/%s/postfachNachrichtAttachment/file", VorgangHeaderTestFactory.ID)); + } } - private Postfach buildPostfach() { - return PostfachTestFactory.createBuilder() - .features(FeaturesTestFactory.createBuilder() - .reply(FeaturesTestFactory.REPLY_FORBIDDEN) - .build()) - .build(); + private void callModelAssembler(VorgangWithEingang vorgang) { + modelAssembler.addPostfachNachrichtLinks(model, vorgang); } } -} \ No newline at end of file +} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailServiceTest.java index f31e143f6a0b1723b19a82771fced255d102340f..33d902c17f9c72aaa03d6cd36e7e7145f9328a59 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachMailServiceTest.java @@ -38,17 +38,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentMatcher; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.springframework.test.util.ReflectionTestUtils; -import com.thedeanda.lorem.LoremIpsum; - -import de.ozgcloud.alfa.common.FeatureToggleProperties; import de.ozgcloud.alfa.common.binaryfile.BinaryFileService; import de.ozgcloud.alfa.common.binaryfile.BinaryFileTestFactory; import de.ozgcloud.alfa.common.binaryfile.FileId; @@ -62,8 +56,6 @@ import de.ozgcloud.alfa.common.user.UserId; import de.ozgcloud.alfa.common.user.UserProfile; import de.ozgcloud.alfa.common.user.UserProfileTestFactory; import de.ozgcloud.alfa.common.user.UserService; -import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory; -import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory; import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory; import de.ozgcloud.alfa.vorgang.VorgangWithEingang; import de.ozgcloud.alfa.vorgang.VorgangWithEingangTestFactory; @@ -84,9 +76,6 @@ class PostfachMailServiceTest { @Mock private CommandService commandService; - @Mock - private FeatureToggleProperties featureToggleProperties; - @DisplayName("Get all") @Nested class TestGetAll { @@ -158,60 +147,6 @@ class PostfachMailServiceTest { } } - @DisplayName("Is postfach configured") - @Nested - class TestIsPostfachConfigured { - - @Test - void shouldCallRemoteServiceOnMissingProperty() { - when(remoteService.getPostfachConfig()).thenReturn(PostfachConfigGroupTestFactory.create()); - - service.isPostfachConfigured(); - - verify(remoteService).getPostfachConfig(); - } - - @Test - void shouldNotCallRemoteServiceOnExistingProperty() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); - - service.isPostfachConfigured(); - - verifyNoInteractions(remoteService); - } - - @Test - void shoulCallRemoteServiceOnlyOnce() { - when(remoteService.getPostfachConfig()).thenReturn(PostfachConfigGroupTestFactory.create()); - - service.isPostfachConfigured(); - service.isPostfachConfigured(); - - verify(remoteService, times(1)).getPostfachConfig(); - } - - @ParameterizedTest - @ValueSource(booleans = { false, true }) - void shouldReturnValueFromRemoteService(boolean expectedConfigured) { - var serviceResponse = PostfachConfigGroupTestFactory.createBuilder().configured(expectedConfigured).build(); - when(remoteService.getPostfachConfig()).thenReturn(serviceResponse); - - var configured = service.isPostfachConfigured(); - - assertThat(configured).isEqualTo(expectedConfigured); - } - - @ParameterizedTest - @ValueSource(booleans = { false, true }) - void shouldReturnCachedValue(boolean expectedConfigured) { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().configured(expectedConfigured).build()); - - var configured = service.isPostfachConfigured(); - - assertThat(configured).isEqualTo(expectedConfigured); - } - } - @DisplayName("Get all as pdf") @Nested class TestGetAllAsPdf { @@ -507,133 +442,4 @@ class PostfachMailServiceTest { } } } - - @Nested - @DisplayName("Is reply to a message allowed for given Vorgang") - class TestIsReplyToMessageAllowed { - - @Test - void shouldCallIsReplyAllowed() { - doReturn(true).when(service).isReplyAllowed(any()); - - service.isReplyToMessageAllowed(VorgangWithEingangTestFactory.create()); - - verify(service).isReplyAllowed(ServiceKontoTestFactory.TYPE); - } - - @ParameterizedTest - @ValueSource(booleans = { false, true }) - void shouldReturnResultOfIsReplyAllowed(boolean expectedReplyAllowed) { - doReturn(expectedReplyAllowed).when(service).isReplyAllowed(any()); - - var replyAllowed = service.isReplyToMessageAllowed(VorgangWithEingangTestFactory.create()); - - assertThat(replyAllowed).isEqualTo(expectedReplyAllowed); - } - - @Test - void shouldReturnFalseForNotExistingServiceKonto() { - var vorgangWithEingang = VorgangWithEingangTestFactory.createBuilder() - .header(VorgangHeadTestFactory.createBuilder() - .serviceKonto(null) - .build()) - .build(); - - var replyToMessageAllowed = service.isReplyToMessageAllowed(vorgangWithEingang); - - assertThat(replyToMessageAllowed).isFalse(); - } - } - - @Nested - class TestIsReplyAllowed { - - private static final String DUMMY_SERVICE_KONTO_TYPE = LoremIpsum.getInstance().getWords(1); - - @BeforeEach - void setUp() { - when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(false); - } - - @Test - @DisplayName("reply not allowed if postfach not configured") - void shouldReturnFalseIfPostfachNotConfigured() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().postfachConfigs(List.of()).build()); - doReturn(false).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); - - assertThat(replyAllowed).isFalse(); - } - - @Test - @DisplayName("given ServiceKonto-type is not configured") - void shouldReturnFalseForNotConfiguredType() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().postfachConfigs(List.of()).build()); - doReturn(true).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(DUMMY_SERVICE_KONTO_TYPE); - - assertThat(replyAllowed).isFalse(); - } - - @Test - @DisplayName("given ServiceKonto-type is null") - void shouldReturnFalseForUnknownType() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); - doReturn(true).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(null); - - assertThat(replyAllowed).isFalse(); - } - - @Test - @DisplayName("reply not allowed for given ServiceKonto-type") - void shouldReturnFalseIfReplyNotAllowed() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder() - .postfachConfigs(List.of(PostfachConfigTestFactory.createBuilder().replyAllowed(false).build())) - .build()); - doReturn(true).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); - - assertThat(replyAllowed).isFalse(); - } - - @Test - @DisplayName("reply allowed for given ServiceKonto-type") - void shouldReturnTrueIfReplyIsAllowed() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); - doReturn(true).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); - - assertThat(replyAllowed).isTrue(); - } - - @Test - @DisplayName("reply allowed for given lower case ServiceKonto-type") - void shouldReturnTrueIfReplyIsAllowedForLowerCaseServiceKontoType() { - setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); - doReturn(true).when(service).isPostfachConfigured(); - - var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE.toLowerCase()); - - assertThat(replyAllowed).isTrue(); - } - - @Test - void shouldReturnTrueIfAlwaysAllowed() { - when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(true); - - var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); - - assertThat(replyAllowed).isTrue(); - } - } - - private void setPostfachConfigGroup(PostfachConfigGroup postfachConfigGroup) { - ReflectionTestUtils.setField(service, "postfachConfigGroup", postfachConfigGroup); - } } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2898c5ecf7fde5ead5dab2eb396bbeeae8f3861d --- /dev/null +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsServiceTest.java @@ -0,0 +1,320 @@ +package de.ozgcloud.alfa.postfach; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.springframework.cloud.endpoint.RefreshEndpoint; +import org.springframework.test.util.ReflectionTestUtils; + +import com.thedeanda.lorem.LoremIpsum; + +import de.ozgcloud.alfa.common.FeatureToggleProperties; +import de.ozgcloud.alfa.vorgang.ServiceKontoTestFactory; +import de.ozgcloud.alfa.vorgang.VorgangHeadTestFactory; +import de.ozgcloud.alfa.vorgang.VorgangWithEingang; +import de.ozgcloud.alfa.vorgang.VorgangWithEingangTestFactory; + +class PostfachSettingsServiceTest { + + @Spy + @InjectMocks + private PostfachSettingsService service; + @Mock + private PostfachMailRemoteService remoteService; + @Mock + private RefreshEndpoint refreshEndpoint; + @Mock + private PostfachProperties postfachProperties; + @Mock + private FeatureToggleProperties featureToggleProperties; + + @DisplayName("Is postfach configured") + @Nested + class TestIsPostfachConfigured { + + @Test + void shouldCallRemoteServiceOnMissingProperty() { + when(remoteService.getPostfachConfig()).thenReturn(PostfachConfigGroupTestFactory.create()); + + callService(); + + verify(remoteService).getPostfachConfig(); + } + + @Test + void shouldNotCallRemoteServiceOnExistingProperty() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); + + callService(); + + verifyNoInteractions(remoteService); + } + + @Test + void shoulCallRemoteServiceOnlyOnce() { + when(remoteService.getPostfachConfig()).thenReturn(PostfachConfigGroupTestFactory.create()); + + callService(); + callService(); + + verify(remoteService, times(1)).getPostfachConfig(); + } + + @ParameterizedTest + @ValueSource(booleans = { false, true }) + void shouldReturnValueFromRemoteService(boolean expectedConfigured) { + var serviceResponse = PostfachConfigGroupTestFactory.createBuilder().configured(expectedConfigured).build(); + when(remoteService.getPostfachConfig()).thenReturn(serviceResponse); + + var configured = callService(); + + assertThat(configured).isEqualTo(expectedConfigured); + } + + @ParameterizedTest + @ValueSource(booleans = { false, true }) + void shouldReturnCachedValue(boolean expectedConfigured) { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().configured(expectedConfigured).build()); + + var configured = callService(); + + assertThat(configured).isEqualTo(expectedConfigured); + } + + private boolean callService() { + return service.isPostfachConfigured(); + } + } + + @Nested + class TestGetPostfachSettings { + private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); + + @BeforeEach + void mockService() { + doReturn(true).when(service).isReplyToMessageAllowed(vorgang); + + } + + @Test + void shouldCheckIsReplyAllowed() { + callService(); + + verify(service).isReplyToMessageAllowed(vorgang); + } + + @ParameterizedTest + @ValueSource(booleans = { true, false }) + void shouldSetIsReplyAllowedFeature(boolean replyAllowed) { + when(service.isReplyToMessageAllowed(vorgang)).thenReturn(replyAllowed); + + var postfach = callService(); + + assertThat(postfach.getFeatures().isReply()).isEqualTo(replyAllowed); + } + + @Test + void shouldGetSignatur() { + callService(); + + verify(service).getSignatur(); + } + + @Test + void shouldSetSignatur() { + doReturn(SettingsTestFactory.SIGNATUR).when(service).getSignatur(); + + var postfach = callService(); + + assertThat(postfach.getSettings().getSignatur()).isEqualTo(SettingsTestFactory.SIGNATUR); + } + + private PostfachSettings callService() { + return service.getPostfachSettings(vorgang); + } + } + + @Nested + class TestGetSignatur { + + @Test + void shouldRefreshCloudProperties() { + callService(); + + verify(service).refreshPostfachProperties(); + } + + @Test + void shouldGetSignatur() { + callService(); + + verify(postfachProperties).getSignatur(); + + } + + @Test + void shouldReturnSignatur() { + when(postfachProperties.getSignatur()).thenReturn(SettingsTestFactory.SIGNATUR); + + var signatur = callService(); + + assertThat(signatur).isEqualTo(SettingsTestFactory.SIGNATUR); + } + + private String callService() { + return service.getSignatur(); + } + } + + @Nested + class TestRefreshPostfachProperties { + + @Test + void shouldCallRefreshEndpoint() { + service.refreshPostfachProperties(); + + verify(refreshEndpoint).refresh(); + } + } + + @Nested + @DisplayName("Is reply to a message allowed for given Vorgang") + class TestIsReplyToMessageAllowed { + + @Test + void shouldCallIsReplyAllowed() { + doReturn(true).when(service).isReplyAllowed(ServiceKontoTestFactory.TYPE); + + service.isReplyToMessageAllowed(VorgangWithEingangTestFactory.create()); + + verify(service).isReplyAllowed(ServiceKontoTestFactory.TYPE); + } + + @ParameterizedTest + @ValueSource(booleans = { false, true }) + void shouldReturnResultOfIsReplyAllowed(boolean expectedReplyAllowed) { + doReturn(expectedReplyAllowed).when(service).isReplyAllowed(ServiceKontoTestFactory.TYPE); + + var replyAllowed = service.isReplyToMessageAllowed(VorgangWithEingangTestFactory.create()); + + assertThat(replyAllowed).isEqualTo(expectedReplyAllowed); + } + + @Test + void shouldReturnFalseForNotExistingServiceKonto() { + var vorgangWithEingang = VorgangWithEingangTestFactory.createBuilder() + .header(VorgangHeadTestFactory.createBuilder() + .serviceKonto(null) + .build()) + .build(); + + var replyToMessageAllowed = service.isReplyToMessageAllowed(vorgangWithEingang); + + assertThat(replyToMessageAllowed).isFalse(); + } + } + + @Nested + class TestIsReplyAllowed { + + private static final String DUMMY_SERVICE_KONTO_TYPE = LoremIpsum.getInstance().getWords(1); + + @BeforeEach + void setUp() { + when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(false); + } + + @Test + @DisplayName("reply not allowed if postfach not configured") + void shouldReturnFalseIfPostfachNotConfigured() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().postfachConfigs(List.of()).build()); + doReturn(false).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); + + assertThat(replyAllowed).isFalse(); + } + + @Test + @DisplayName("given ServiceKonto-type is not configured") + void shouldReturnFalseForNotConfiguredType() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder().postfachConfigs(List.of()).build()); + doReturn(true).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(DUMMY_SERVICE_KONTO_TYPE); + + assertThat(replyAllowed).isFalse(); + } + + @Test + @DisplayName("given ServiceKonto-type is null") + void shouldReturnFalseForUnknownType() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); + doReturn(true).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(null); + + assertThat(replyAllowed).isFalse(); + } + + @Test + @DisplayName("reply not allowed for given ServiceKonto-type") + void shouldReturnFalseIfReplyNotAllowed() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.createBuilder() + .postfachConfigs(List.of(PostfachConfigTestFactory.createBuilder().replyAllowed(false).build())) + .build()); + doReturn(true).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); + + assertThat(replyAllowed).isFalse(); + } + + @Test + @DisplayName("reply allowed for given ServiceKonto-type") + void shouldReturnTrueIfReplyIsAllowed() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); + doReturn(true).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); + + assertThat(replyAllowed).isTrue(); + } + + @Test + @DisplayName("reply allowed for given lower case ServiceKonto-type") + void shouldReturnTrueIfReplyIsAllowedForLowerCaseServiceKontoType() { + setPostfachConfigGroup(PostfachConfigGroupTestFactory.create()); + doReturn(true).when(service).isPostfachConfigured(); + + var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE.toLowerCase()); + + assertThat(replyAllowed).isTrue(); + } + + @Test + void shouldReturnTrueIfAlwaysAllowed() { + when(featureToggleProperties.isReplyAlwaysAllowed()).thenReturn(true); + + var replyAllowed = service.isReplyAllowed(PostfachConfigTestFactory.TYPE); + + assertThat(replyAllowed).isTrue(); + } + } + + private void setPostfachConfigGroup(PostfachConfigGroup postfachConfigGroup) { + ReflectionTestUtils.setField(service, "postfachConfigGroup", postfachConfigGroup); + } + +} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..6db1a82014fdc494a7fa8ce083214dd624fdb10c --- /dev/null +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachSettingsTestFactory.java @@ -0,0 +1,17 @@ +package de.ozgcloud.alfa.postfach; + +public class PostfachSettingsTestFactory { + + public static final Features FEATURES = FeaturesTestFactory.create(); + public static final Settings SETTINGS = SettingsTestFactory.create(); + + public static PostfachSettings create() { + return createBuilder().build(); + } + + public static PostfachSettings.PostfachSettingsBuilder createBuilder() { + return PostfachSettings.builder() + .features(FEATURES) + .settings(SETTINGS); + } +} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachTestFactory.java deleted file mode 100644 index 2fafe4b9cd22e28321b5abb0210e77308dd5d476..0000000000000000000000000000000000000000 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/PostfachTestFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.ozgcloud.alfa.postfach; - -public class PostfachTestFactory { - - public static final Features FEATURES = FeaturesTestFactory.create(); - - public static Postfach create() { - return createBuilder().build(); - } - - public static Postfach.PostfachBuilder createBuilder() { - return Postfach.builder().features(FEATURES); - } -} diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/SettingsTestFactory.java b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/SettingsTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..03fa58cccc956240f7bade5eceb693477618aa50 --- /dev/null +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/postfach/SettingsTestFactory.java @@ -0,0 +1,17 @@ +package de.ozgcloud.alfa.postfach; + +import com.thedeanda.lorem.LoremIpsum; + +public class SettingsTestFactory { + + public static final String SIGNATUR = LoremIpsum.getInstance().getParagraphs(2, 2); + + public static Settings create() { + return createBuilder().build(); + } + + public static Settings.SettingsBuilder createBuilder() { + return Settings.builder() + .signatur(SIGNATUR); + } +} diff --git a/alfa-service/src/test/resources/application.yml b/alfa-service/src/test/resources/application.yml index d2f9d0715b8ff905923e8bb5387f518ff77213af..ea81cad0839dc0d94a6ee477c178dd42c66b44fe 100644 --- a/alfa-service/src/test/resources/application.yml +++ b/alfa-service/src/test/resources/application.yml @@ -22,12 +22,12 @@ ozgcloud: url: https://localhost profile-template: /api/userProfiles/%s search-template: /api/userProfiles/?searchBy={searchBy} - + jwt: auth: converter: resource-id: alfa - principle-attribute: preferred_username + principle-attribute: preferred_username spring: mvc: @@ -42,13 +42,15 @@ spring: multipart: max-file-size: 2GB max-request-size: 2GB + config: + import: optional:configserver:http://localhost:8888/ security: oauth2: resourceserver: jwt: issuer-uri: ${ozgcloud.keycloak.auth-server-url}/realms/${ozgcloud.keycloak.realm} jwk-set-uri: ${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs - + server: http2: enabled: true @@ -76,8 +78,8 @@ management: endpoints: web: exposure: - include: health,prometheus - + include: health,prometheus,refresh + grpc: client: vorgang-manager: diff --git a/pom.xml b/pom.xml index 1989d2bfc0f915073d913b26e94eadfed20299bc..5c3018e62bf6370472aba1576215d06d0e43067d 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,7 @@ <ozgcloud-common-pdf.version>3.0.1</ozgcloud-common-pdf.version> <user-manager.version>2.2.0</user-manager.version> <zufi-manager.version>1.2.0</zufi-manager.version> + <spring-cloud-config-client.version>4.1.3</spring-cloud-config-client.version> <!-- TODO: die Version über ozgcloud-common ziehen --> <jjwt.version>0.11.5</jjwt.version> @@ -158,6 +159,11 @@ <version>${jjwt.version}</version> <scope>runtime</scope> </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-config</artifactId> + <version>${spring-cloud-config-client.version}</version> + </dependency> </dependencies> </dependencyManagement> diff --git a/src/main/helm/templates/_helpers.tpl b/src/main/helm/templates/_helpers.tpl index 2277556ced3553ea475b105264fc156bada77eb6..fde4a4e14938c745ee8972e5a8c9781a7f5c0669 100644 --- a/src/main/helm/templates/_helpers.tpl +++ b/src/main/helm/templates/_helpers.tpl @@ -50,13 +50,17 @@ app.kubernetes.io/namespace: {{ include "app.namespace" . }} {{- end -}} {{- define "app.grpc_client_vorgang_manager_address" -}} -{{ printf "%s.%s:9090" ( coalesce .Values.vorgangManagerName "vorgang-manager" ) .Release.Namespace | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{ printf "dns:///%s.%s:9090" ( coalesce .Values.vorgangManagerName "vorgang-manager" ) .Release.Namespace | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end -}} {{- define "app.grpc_client_user-manager_address" -}} {{ printf "%s.%s:9000" ( coalesce .Values.usermanagerName "user-manager" ) .Release.Namespace }} {{- end -}} +{{- define "app.spring_cloud_config_administration_address" -}} +{{ printf "http://%s.%s:8080" ( coalesce .Values.administrationName "administration" ) .Release.Namespace }} +{{- end -}} + {{- define "app.baseUrl" -}} {{- required "baseUrl muss angegeben sein" .Values.baseUrl }} {{- end -}} diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml index edfb381cc4c6e5a540411f140df4b359727c044d..585408d9e599665f5ac4777b117051c601ebeaec 100644 --- a/src/main/helm/templates/deployment.yaml +++ b/src/main/helm/templates/deployment.yaml @@ -109,6 +109,8 @@ spec: value: {{ ((.Values.ozgcloud).xdomea).behoerdenschluesselUri}} - name: ozgcloud_xdomea_behoerdenschluesselVersion value: {{ ((.Values.ozgcloud).xdomea).behoerdenschluesselVersion | quote }} + - name: ozgcloud_administration_address + value: {{ include "app.spring_cloud_config_administration_address" . }} - name: grpc_client_zufi-manager_address value: {{ .Values.zufiManager.address }} - name: grpc_client_zufi-manager_negotiationType diff --git a/src/main/helm/templates/network_policy.yaml b/src/main/helm/templates/network_policy.yaml index ee37649c47d584833c401a8f68748ba46a4d8fd2..fe9816c1f6700cc2b82b051eaa6c9741fd51a725 100644 --- a/src/main/helm/templates/network_policy.yaml +++ b/src/main/helm/templates/network_policy.yaml @@ -14,6 +14,13 @@ spec: ingress: - ports: - port: 8080 + - from: + - namespaceSelector: + matchLabels: + name: {{ (.Values.networkPolicy).monitoringNamespace | default "openshift-user-workload-monitoring" }} + ports: + - protocol: TCP + port: 8081 {{- with (.Values.networkPolicy).additionalIngressConfigLocal }} {{ toYaml . | indent 2 }} {{- end }} @@ -26,7 +33,7 @@ spec: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: {{ required "zufiManager.namespace must be set if zufiManager server is enabled" (.Values.zufiManager).namespace }} - podSelector: + podSelector: matchLabels: component: zufi-server ports: @@ -34,15 +41,22 @@ spec: protocol: TCP {{- end }} - to: - - podSelector: + - podSelector: matchLabels: component: vorgang-manager ports: - port: 9090 protocol: TCP + - to: + - podSelector: + matchLabels: + component: administration + ports: + - port: 8080 + protocol: TCP # public keycloak ip - to: - - ipBlock: + - ipBlock: cidr: {{ required "networkPolicy.ssoPublicIp must be set" (.Values.networkPolicy).ssoPublicIp }} - to: - namespaceSelector: @@ -58,7 +72,7 @@ spec: - port: 5353 protocol: TCP - to: - - podSelector: + - podSelector: matchLabels: component: user-manager ports: diff --git a/src/test/helm/deployment_config_client_env_test.yaml b/src/test/helm/deployment_config_client_env_test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62ef728deb884eca479351daa21a1080ef30c23f --- /dev/null +++ b/src/test/helm/deployment_config_client_env_test.yaml @@ -0,0 +1,32 @@ +suite: deployment collaboration env +release: + name: alfa + namespace: sh-helm-test +templates: + - templates/deployment.yaml +set: + baseUrl: test.company.local + ozgcloud: + environment: test + bundesland: sh + bezeichner: helm + sso: + serverUrl: https://sso.company.local + imagePullSecret: image-pull-secret +tests: + - it: should set default administration server address + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_administration_address + value: http://administration.sh-helm-test:8080 + - it: should have set administration server address + set: + administrationName: custom_admin_name + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_administration_address + value: http://custom_admin_name.sh-helm-test:8080 diff --git a/src/test/helm/deployment_defaults_env_test.yaml b/src/test/helm/deployment_defaults_env_test.yaml index 0bf3a7adbf32e293791d0af1a2804bf7c8c4d6df..f02a3b9989743688a6baa2527e7376ca7c9945f4 100644 --- a/src/test/helm/deployment_defaults_env_test.yaml +++ b/src/test/helm/deployment_defaults_env_test.yaml @@ -48,7 +48,7 @@ tests: path: spec.template.spec.containers[0].env content: name: grpc_client_vorgang-manager_address - value: vorgang-manager.sh-helm-test:9090 + value: dns:///vorgang-manager.sh-helm-test:9090 - contains: path: spec.template.spec.containers[0].env content: diff --git a/src/test/helm/deployment_vorgang_manager_address_env_test.yaml b/src/test/helm/deployment_vorgang_manager_address_env_test.yaml index 794e933ec92b521e7664244bae38f8b5b05b6469..9c0e685c4e9256e0053ebe3b4203e392f816e271 100644 --- a/src/test/helm/deployment_vorgang_manager_address_env_test.yaml +++ b/src/test/helm/deployment_vorgang_manager_address_env_test.yaml @@ -46,4 +46,4 @@ tests: path: spec.template.spec.containers[0].env content: name: grpc_client_vorgang-manager_address - value: my-test-vorgang-manager-name.sh-helm-test:9090 + value: dns:///my-test-vorgang-manager-name.sh-helm-test:9090 diff --git a/src/test/helm/network_policy_test.yaml b/src/test/helm/network_policy_test.yaml index b1b35ecddd7608c33ed412b7a036829d4e966bb6..37eadd62d18c858ec89095fb7849c3144c035988 100644 --- a/src/test/helm/network_policy_test.yaml +++ b/src/test/helm/network_policy_test.yaml @@ -76,6 +76,13 @@ tests: ingress: - ports: - port: 8080 + - from: + - namespaceSelector: + matchLabels: + name: openshift-user-workload-monitoring + ports: + - port: 8081 + protocol: TCP egress: - to: - podSelector: @@ -84,6 +91,13 @@ tests: ports: - port: 9090 protocol: TCP + - to: + - podSelector: + matchLabels: + component: administration + ports: + - port: 8080 + protocol: TCP # public keycloak ip - to: - ipBlock: @@ -259,4 +273,21 @@ tests: collaborationEnabled: true asserts: - failedTemplate: - errorMessage: zufiManager.namespace must be set if zufiManager server is enabled \ No newline at end of file + errorMessage: zufiManager.namespace must be set if zufiManager server is enabled + - it: should set monitoring namesapce + set: + networkPolicy: + ssoPublicIp: 1.1.1.1 + dnsServerNamespace: test-dns-server-namespace + monitoringNamespace: test-monitoring + asserts: + - contains: + path: spec.ingress + content: + from: + - namespaceSelector: + matchLabels: + name: test-monitoring + ports: + - protocol: TCP + port: 8081 \ No newline at end of file