Skip to content
Snippets Groups Projects
Commit 20d84131 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5294: change abschliessen button visibility

parent d569c362
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@
unter der Lizenz sind dem Lizenztext zu entnehmen.
-->
<ng-container *ngIf="vorgang | hasLink: linkRel.ABSCHLIESSEN">
<ng-container *ngIf="isVisible">
<ozgcloud-stroked-button-with-spinner
*ngIf="!showAsIconButton"
data-test-id="abschliessen-button"
......
......@@ -22,22 +22,10 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { CommandResource } from '@alfa-client/command-shared';
import {
HasLinkPipe,
StateResource,
createEmptyStateResource,
createStateResource,
} from '@alfa-client/tech-shared';
import { createEmptyStateResource, createStateResource, HasLinkPipe, StateResource, } from '@alfa-client/tech-shared';
import { mock } from '@alfa-client/test-utils';
import {
IconButtonWithSpinnerComponent,
OzgcloudStrokedButtonWithSpinnerComponent,
} from '@alfa-client/ui';
import {
VorgangCommandService,
VorgangStatus,
VorgangWithEingangLinkRel,
} from '@alfa-client/vorgang-shared';
import { IconButtonWithSpinnerComponent, OzgcloudStrokedButtonWithSpinnerComponent, } from '@alfa-client/ui';
import { VorgangCommandService, VorgangWithEingangLinkRel, VorgangWithEingangResource, } from '@alfa-client/vorgang-shared';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { createCommandResource } from 'libs/command-shared/test/command';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
......@@ -126,7 +114,7 @@ describe('AbschliessenButtonComponent', () => {
});
it('should be hidden', () => {
component.vorgang = createVorgangWithEingangResource();
component.isVisible = false;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector(abschliessenButton);
......@@ -135,9 +123,7 @@ describe('AbschliessenButtonComponent', () => {
});
it('should be visible', () => {
component.vorgang = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.ABSCHLIESSEN,
]);
component.isVisible = true;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector(abschliessenButton);
......@@ -153,7 +139,7 @@ describe('AbschliessenButtonComponent', () => {
});
it('should be hidden', () => {
component.vorgang = createVorgangWithEingangResource();
component.isVisible = false;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector(abschliessenIconButton);
......@@ -161,11 +147,8 @@ describe('AbschliessenButtonComponent', () => {
expect(buttonElement).not.toBeInstanceOf(HTMLElement);
});
it('should be visible', () => {
component.vorgang = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.ABSCHLIESSEN,
]);
component.isVisible = true;
fixture.detectChanges();
const buttonElement = fixture.nativeElement.querySelector(abschliessenIconButton);
......@@ -173,4 +156,58 @@ describe('AbschliessenButtonComponent', () => {
expect(buttonElement).toBeInstanceOf(HTMLElement);
});
});
describe('set vorgang', () => {
it('should set vorgang with eingang resource', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
component.vorgang = vorgang;
expect(component.vorgangWithEingangResource).toBe(vorgang);
});
it('should set visible to true', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.ABSCHLIESSEN,
]);
component.vorgang = vorgang;
const isVisible: boolean = component.isVisible;
expect(isVisible).toBeTruthy();
});
it('should set visible to false', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
component.vorgang = vorgang;
const isVisible: boolean = component.isVisible;
expect(isVisible).toBeFalsy();
});
it('should set visible to false if have createBescheidDraft link', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.ABSCHLIESSEN,
VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT,
]);
component.vorgang = vorgang;
const isVisible: boolean = component.isVisible;
expect(isVisible).toBeFalsy();
});
it('should set visible to false if have bescheidDraft link', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.ABSCHLIESSEN,
VorgangWithEingangLinkRel.BESCHEID_DRAFT,
]);
component.vorgang = vorgang;
const isVisible: boolean = component.isVisible;
expect(isVisible).toBeFalsy();
});
});
});
......@@ -22,13 +22,10 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { CommandResource } from '@alfa-client/command-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import {
VorgangCommandService,
VorgangWithEingangLinkRel,
VorgangWithEingangResource,
} from '@alfa-client/vorgang-shared';
import { createEmptyStateResource, notHasLink, StateResource } from '@alfa-client/tech-shared';
import { VorgangCommandService, VorgangWithEingangLinkRel, VorgangWithEingangResource, } from '@alfa-client/vorgang-shared';
import { Component, Input, OnInit } from '@angular/core';
import { hasLink } from '@ngxp/rest';
import { Observable, of } from 'rxjs';
@Component({
......@@ -37,9 +34,19 @@ import { Observable, of } from 'rxjs';
styleUrls: ['./abschliessen-button.component.scss'],
})
export class AbschliessenButtonComponent implements OnInit {
@Input() vorgang: VorgangWithEingangResource;
@Input() set vorgang(vorgang: VorgangWithEingangResource) {
this.vorgangWithEingangResource = vorgang;
this.isVisible =
hasLink(vorgang, VorgangWithEingangLinkRel.ABSCHLIESSEN) &&
notHasLink(vorgang, VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT) &&
notHasLink(vorgang, VorgangWithEingangLinkRel.BESCHEID_DRAFT);
}
@Input() showAsIconButton: boolean = false;
public isVisible: boolean = false;
vorgangWithEingangResource: VorgangWithEingangResource;
commandStateResource$: Observable<StateResource<CommandResource>> = of(
createEmptyStateResource<CommandResource>(),
);
......@@ -53,6 +60,8 @@ export class AbschliessenButtonComponent implements OnInit {
}
public abschliessen(): void {
this.commandStateResource$ = this.vorgangCommandService.abschliessen(this.vorgang);
this.commandStateResource$ = this.vorgangCommandService.abschliessen(
this.vorgangWithEingangResource,
);
}
}
......@@ -15,6 +15,7 @@ import de.ozgcloud.alfa.bescheid.BescheidController.BescheidByVorgangController;
import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.command.CommandController.CommandByRelationController;
import de.ozgcloud.alfa.common.user.CurrentUserService;
import de.ozgcloud.alfa.vorgang.Vorgang;
import de.ozgcloud.alfa.vorgang.VorgangWithEingang;
import lombok.RequiredArgsConstructor;
......@@ -29,11 +30,12 @@ class BescheidVorgangProcessor implements RepresentationModelProcessor<EntityMod
private final BescheidService bescheidService;
private final FeatureToggleProperties featureToggleProperties;
private final CurrentUserService currentUserService;
@Override
public EntityModel<VorgangWithEingang> process(EntityModel<VorgangWithEingang> model) {
var vorgang = model.getContent();
if (Objects.isNull(vorgang)) {
if (Objects.isNull(vorgang) || currentUserService.isCurrentUserEinheitlicherAnsprechpartner()) {
return model;
}
return ModelBuilder.fromModel(model)
......
......@@ -60,6 +60,10 @@ public class CurrentUserService {
return CurrentUserHelper.hasRole(role) || hasRoleReachable(role);
}
public boolean isCurrentUserEinheitlicherAnsprechpartner() {
return hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
}
private boolean hasRoleReachable(String role) {
var reachableRoles = roleHierarchy.getReachableGrantedAuthorities(getAuthorities());
......
......@@ -22,6 +22,7 @@ import org.springframework.hateoas.Link;
import de.ozgcloud.alfa.common.FeatureToggleProperties;
import de.ozgcloud.alfa.common.UserProfileUrlProvider;
import de.ozgcloud.alfa.common.user.CurrentUserService;
import de.ozgcloud.alfa.vorgang.Vorgang;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangWithEingang;
......@@ -35,8 +36,11 @@ class BescheidVorgangProcessorTest {
@Spy
@InjectMocks
private BescheidVorgangProcessor processor;
@Mock
private BescheidService service;
@Mock
private CurrentUserService currentUserService;
@Mock
private FeatureToggleProperties featureToggleProperties;
......@@ -53,6 +57,16 @@ class BescheidVorgangProcessorTest {
assertThat(processedModel).isEqualTo(inputModel);
}
@Test
void shouldReturnTheSameModelWhenUserIsEinheitlicherAnsprechpartner() {
var inputModel = EntityModel.of(VorgangWithEingangTestFactory.create());
when(currentUserService.isCurrentUserEinheitlicherAnsprechpartner()).thenReturn(true);
var processedModel = processor.process(inputModel);
assertThat(processedModel).isEqualTo(inputModel);
}
@Test
void shouldCallExistsBescheid() {
initUserProfileUrlProvider(new UserProfileUrlProvider());
......
......@@ -139,4 +139,35 @@ class CurrentUserServiceTest {
}
}
}
@Nested
class TestICurrentUserEinheitlicherAnsprechpartner {
@Test
void shouldCheckRole() {
doReturn(false).when(service).hasRole(any());
service.isCurrentUserEinheitlicherAnsprechpartner();
verify(service).hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
}
@Test
void shouldReturnTrue() {
doReturn(true).when(service).hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
var isEinhetlicherAnsprechpartner = service.isCurrentUserEinheitlicherAnsprechpartner();
assertThat(isEinhetlicherAnsprechpartner).isTrue();
}
@Test
void shouldReturnFalse() {
doReturn(false).when(service).hasRole(any());
var isEinhetlicherAnsprechpartner = service.isCurrentUserEinheitlicherAnsprechpartner();
assertThat(isEinhetlicherAnsprechpartner).isFalse();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment