implement organisation management
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { CanActivateFn, Router } from '@angular/router';
|
||||
import { catchError, filter, of, switchMap, take } from 'rxjs';
|
||||
import { CredentialService } from '../services/credential.service';
|
||||
|
||||
export const superAdminGuard: CanActivateFn = () => {
|
||||
const credentialService = inject(CredentialService);
|
||||
const router = inject(Router);
|
||||
|
||||
return credentialService.validating.pipe(
|
||||
filter((validating) => !validating),
|
||||
take(1),
|
||||
switchMap(() => {
|
||||
if (!credentialService.isAuthenticated.value) {
|
||||
void router.navigate(['/login']);
|
||||
return of(false);
|
||||
}
|
||||
|
||||
return credentialService.validateCurrentSession().pipe(
|
||||
switchMap(() => {
|
||||
if (!credentialService.isEffectiveSuperAdmin()) {
|
||||
void router.navigate(['/dashboard']);
|
||||
return of(false);
|
||||
}
|
||||
return of(true);
|
||||
}),
|
||||
catchError(() => of(false)),
|
||||
);
|
||||
}),
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Configuration } from '../../api';
|
||||
|
||||
export interface OrganizationProfile {
|
||||
id: string;
|
||||
name: string;
|
||||
other_inst_id?: string | null;
|
||||
deleted: boolean;
|
||||
member_count: number;
|
||||
}
|
||||
|
||||
export interface OrganizationPage {
|
||||
items: OrganizationProfile[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface CreateOrganizationPayload {
|
||||
name: string;
|
||||
other_inst_id?: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateOrganizationPayload {
|
||||
name?: string;
|
||||
other_inst_id?: string | null;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OrganizationManagementService {
|
||||
private readonly httpClient = inject(HttpClient);
|
||||
private readonly apiConfiguration = inject(Configuration, { optional: true });
|
||||
|
||||
getOrganizations(page: number, pageSize: number): Observable<OrganizationPage> {
|
||||
const params = new HttpParams()
|
||||
.set('page', page)
|
||||
.set('page_size', pageSize);
|
||||
return this.httpClient.get<OrganizationPage>(
|
||||
`${this.apiBasePath}/api/organizations`,
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
createOrganization(
|
||||
payload: CreateOrganizationPayload,
|
||||
): Observable<OrganizationProfile> {
|
||||
return this.httpClient.post<OrganizationProfile>(
|
||||
`${this.apiBasePath}/api/organizations`,
|
||||
payload,
|
||||
);
|
||||
}
|
||||
|
||||
updateOrganization(
|
||||
organizationId: string,
|
||||
payload: UpdateOrganizationPayload,
|
||||
): Observable<OrganizationProfile> {
|
||||
return this.httpClient.put<OrganizationProfile>(
|
||||
`${this.apiBasePath}/api/organizations/${organizationId}`,
|
||||
payload,
|
||||
);
|
||||
}
|
||||
|
||||
deleteOrganization(organizationId: string): Observable<void> {
|
||||
return this.httpClient.delete<void>(
|
||||
`${this.apiBasePath}/api/organizations/${organizationId}`,
|
||||
);
|
||||
}
|
||||
|
||||
private get apiBasePath(): string {
|
||||
return this.apiConfiguration?.basePath ?? '';
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,11 @@
|
||||
<mat-nav-list class="nav-list">
|
||||
@for (item of navItems; track item.label) {
|
||||
@if (
|
||||
!item.adminOnly ||
|
||||
credentialService.isEffectiveSuperAdmin() ||
|
||||
credentialService.isEffectiveAdmin()
|
||||
(!item.adminOnly ||
|
||||
credentialService.isEffectiveSuperAdmin() ||
|
||||
credentialService.isEffectiveAdmin()) &&
|
||||
(!item.superAdminOnly ||
|
||||
credentialService.isEffectiveSuperAdmin())
|
||||
) {
|
||||
@if (collapsed()) {
|
||||
<a
|
||||
@@ -108,7 +110,6 @@
|
||||
(credentialService.login | async) || 'Max Mustermann'
|
||||
}}</strong>
|
||||
<strong>{{ credentialService.organizationName | async }}</strong>
|
||||
<span>Startup Coach</span>
|
||||
</div>
|
||||
<mat-icon>expand_more</mat-icon>
|
||||
</div>
|
||||
|
||||
@@ -22,6 +22,7 @@ type NavItem = {
|
||||
disabled: boolean;
|
||||
queryParams?: Record<string, string | number | boolean>;
|
||||
adminOnly?: boolean;
|
||||
superAdminOnly?: boolean;
|
||||
};
|
||||
|
||||
@Component({
|
||||
@@ -106,6 +107,13 @@ export class AppMenuComponent {
|
||||
disabled: false,
|
||||
adminOnly: true,
|
||||
},
|
||||
{
|
||||
label: 'Organisationen',
|
||||
icon: 'domain',
|
||||
route: '/organizations',
|
||||
disabled: false,
|
||||
superAdminOnly: true,
|
||||
},
|
||||
];
|
||||
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user