From eaed00333c3176e39c170fd47269b6dfe3470d60 Mon Sep 17 00:00:00 2001 From: Filip Leitner Date: Wed, 10 Apr 2024 09:32:22 +0200 Subject: [PATCH] fix(access-rights): Do not make unnecessary get users requests --- .../access-rights/layman-access-rights.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/hslayers/common/layman/access-rights/layman-access-rights.component.ts b/projects/hslayers/common/layman/access-rights/layman-access-rights.component.ts index 5186709933..4f546beb9d 100644 --- a/projects/hslayers/common/layman/access-rights/layman-access-rights.component.ts +++ b/projects/hslayers/common/layman/access-rights/layman-access-rights.component.ts @@ -1,7 +1,7 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {HttpClient} from '@angular/common/http'; -import {lastValueFrom, map} from 'rxjs'; +import {lastValueFrom, map, of, switchMap} from 'rxjs'; import {AccessRightsModel} from 'hslayers-ng/types'; import {HsCommonLaymanService} from '../layman.service'; @@ -172,8 +172,6 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit { }, {read: 0, write: 0}, ); - this.allUsers = []; - this.access_rights['access_rights.read'] = rights.read > 1 ? 'EVERYONE' : 'private'; @@ -202,7 +200,12 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit { try { this.allUsers = await lastValueFrom( - this.$http.get(url, {withCredentials: true}).pipe( + of(this.allUsers).pipe( + switchMap((users) => + users.length === 0 + ? this.$http.get(url, {withCredentials: true}) + : of(users), + ), map((res: any[]) => { return res.map((user) => { const isCurrentUser = user.username === this.endpoint.user;