Skip to content

Commit

Permalink
fixed domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
pgiertych committed Apr 9, 2024
1 parent b3cbfeb commit 5a289b4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/app/shared/users/privileges/userprivileges.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,33 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit {
if (this.authService.hasRole(Role[Role.ROLE_SYSTEM_ADMIN])) {
this.domainService.getAll().subscribe((domains) => {
this.domains = domains
this.saveDomainsInCache(domains);
this.saveMultipleDomainsInCache(domains);
});
} else if (this.authService.hasRole(Role[Role.ROLE_DOMAIN_ADMIN])) {
const domainIds: number[] = this.authService.getDomainsWithRole(Role[Role.ROLE_DOMAIN_ADMIN]);
domainIds.forEach((domainId) => {
this.domainService.getOne(domainId).subscribe((domain) => this.domains.push(domain));
this.domainService.getOne(domainId).subscribe((domain) => {
this.domains.push(domain)
this.saveDomainInCache(domain)
});
});
} else {
this.getMyDomains();
}
}

private saveDomainsInCache(domains: Domain[]) {
domains.forEach(domain => {
if (!this.domainCache.hasData(domain.id)) {
this.domainCache.setData(domain.id, domain)
}
})
private saveMultipleDomainsInCache(domains: Domain[]) {
domains.forEach(domain => this.saveDomainInCache(domain))
}

private saveDomainInCache(domain: Domain) {
if (!this.domainCache.hasData(domain.id)) {
this.domainCache.setData(domain.id, domain)
}
}

public getMyDomains() {
this.domainService.getMyDomains().subscribe(domains => {
this.saveDomainsInCache(domains)
})
this.domainService.getMyDomains().subscribe(domains => this.saveMultipleDomainsInCache(domains))
}

public add(): void {
Expand All @@ -140,7 +143,9 @@ export class UserPrivilegesComponent extends BaseComponent implements OnInit {
}

public getDomainName(domainId: number): Observable<string> {
console.warn('retrieving domain name')
if (this.domainCache.hasData(domainId)) {
console.warn('hasData')
return of(this.domainCache.getData(domainId).name);
}
}
Expand Down

0 comments on commit 5a289b4

Please sign in to comment.