Skip to content

Commit

Permalink
fix(access-rights): Do not make unnecessary get users requests
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner authored and jmacura committed May 10, 2024
1 parent 6eb536e commit eaed003
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -202,7 +200,12 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {

try {
this.allUsers = await lastValueFrom(
this.$http.get<LaymanUser[]>(url, {withCredentials: true}).pipe(
of(this.allUsers).pipe(
switchMap((users) =>
users.length === 0
? this.$http.get<LaymanUser[]>(url, {withCredentials: true})
: of(users),
),
map((res: any[]) => {
return res.map((user) => {
const isCurrentUser = user.username === this.endpoint.user;
Expand Down

0 comments on commit eaed003

Please sign in to comment.