Merge branch 'next' into develop

This commit is contained in:
Erik Tiekstra
2021-09-27 15:11:21 +02:00
17 changed files with 262 additions and 157 deletions

View File

@@ -0,0 +1,7 @@
<digi-notification-alert af-heading="Personalkontot saknar behörigheter!" af-variation="danger">
<p>
Ditt personalkonto behöver tilldelas en tjänst och utförande verksamheter för att det ska fungera korrekt. Ändra
ditt personalkonto via personallistan eller kontakta din behörighetsadministratör om du inte kan ändra dina egna
behörigheter.
</p>
</digi-notification-alert>

View File

@@ -0,0 +1,26 @@
/* tslint:disable:no-unused-variable */
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UnauthorizedAlertComponent } from './unauthorized-alert.component';
describe('UnauthorizedAlertComponent', () => {
let component: UnauthorizedAlertComponent;
let fixture: ComponentFixture<UnauthorizedAlertComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [UnauthorizedAlertComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(UnauthorizedAlertComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
@Component({
selector: 'msfa-unauthorized-alert',
templateUrl: './unauthorized-alert.component.html',
styleUrls: ['./unauthorized-alert.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UnauthorizedAlertComponent {}

View File

@@ -0,0 +1,11 @@
import { CommonModule } from '@angular/common';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { UnauthorizedAlertComponent } from './unauthorized-alert.component';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
declarations: [UnauthorizedAlertComponent],
imports: [CommonModule],
exports: [UnauthorizedAlertComponent],
})
export class UnauthorizedAlertModule {}

View File

@@ -7,9 +7,10 @@ import { HandledareResponse } from '@msfa-models/api/handledare.response.model';
import { Params } from '@msfa-models/api/params.model';
import { AvropFilter, mapResponseToAvropFilter } from '@msfa-models/avrop-filter.model';
import { AvropCompact, AvropCompactData, mapAvropResponseToAvrop } from '@msfa-models/avrop.model';
import { CustomError, errorToCustomError } from '@msfa-models/error/custom-error';
import { Handledare, mapHandledareResponseToHandledare } from '@msfa-models/handledare.model';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { filter, map, tap } from 'rxjs/operators';
import { catchError, filter, map, tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
@@ -18,6 +19,8 @@ export class AvropApiService {
private _apiBaseUrl = `${environment.api.url}/avrop`;
private _lockedAvropSnapshot$ = new BehaviorSubject<AvropCompact[]>(null);
private _availableHandledareSnapshot$ = new BehaviorSubject<Handledare[]>(null);
private _showUnauthorizedError$ = new BehaviorSubject<boolean>(false);
public showUnauthorizedError$: Observable<boolean> = this._showUnauthorizedError$.asObservable();
constructor(private httpClient: HttpClient) {}
@@ -28,7 +31,19 @@ export class AvropApiService {
fetchAvrop$(params: Params): Observable<AvropCompactData> {
return this.httpClient
.get<AvropApiResponse>(`${this._apiBaseUrl}`, { params })
.pipe(map(({ data, meta }) => ({ data: data.map(avrop => mapAvropResponseToAvrop(avrop)), meta })));
.pipe(
map(({ data, meta }) => ({ data: data.map(avrop => mapAvropResponseToAvrop(avrop)), meta })),
catchError((error: Error & { status: number }) => {
if (error.status === 403) {
this._showUnauthorizedError$.next(true);
return of(null);
} else {
throw new CustomError(
errorToCustomError({ ...error, message: `Kunde inte hämta deltagare.\n\n${error.message}` })
);
}
})
);
}
fetchAvailableHandledare$(avrop: AvropCompact[]): Observable<Handledare[]> {

View File

@@ -34,6 +34,8 @@ export class DeltagareApiService {
private _apiBaseUrl = `${environment.api.url}/deltagare`;
private _deltagareLoading$ = new BehaviorSubject<boolean>(false);
public deltagareLoading$: Observable<boolean> = this._deltagareLoading$.asObservable();
private _showUnauthorizedError$ = new BehaviorSubject<boolean>(false);
public showUnauthorizedError$: Observable<boolean> = this._showUnauthorizedError$.asObservable();
constructor(private httpClient: HttpClient) {}
@@ -65,10 +67,15 @@ export class DeltagareApiService {
this._deltagareLoading$.next(false);
return { data: data.map(deltagare => mapResponseToDeltagareCompact(deltagare)), meta };
}),
catchError((error: Error) => {
throw new CustomError(
errorToCustomError({ ...error, message: `Kunde inte hämta deltagare.\n\n${error.message}` })
);
catchError((error: Error & { status: number }) => {
if (error.status === 403) {
this._showUnauthorizedError$.next(true);
return of(null);
} else {
throw new CustomError(
errorToCustomError({ ...error, message: `Kunde inte hämta deltagare.\n\n${error.message}` })
);
}
})
);
}

View File

@@ -45,7 +45,7 @@ export class AvropService {
public handledareIsConfirmed$: Observable<boolean> = this._handledareIsConfirmed$.asObservable();
public avropIsSubmitted$: Observable<boolean> = this._avropIsSubmitted$.asObservable();
public error$: Observable<string> = this._error$.asObservable();
public showUnauthorizedError$: Observable<boolean> = this.avropApiService.showUnauthorizedError$;
public avropData$: Observable<AvropCompactData> = combineLatest([
this._filteredTjanster$,
this._filteredUtforandeVerksamheter$,

View File

@@ -16,6 +16,7 @@ export class DeltagareService {
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._sort$.asObservable();
private _onlyMyDeltagare$ = new BehaviorSubject<boolean>(false);
public onlyMyDeltagare$: Observable<boolean> = this._onlyMyDeltagare$.asObservable();
public showUnauthorizedError$: Observable<boolean> = this.deltagareApiService.showUnauthorizedError$;
public deltagareLoading$: Observable<boolean> = this.deltagareApiService.deltagareLoading$;
public allDeltagareData$: Observable<DeltagareCompactData> = combineLatest([
this._limit$,