mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:17:33 +00:00
fix(console): hide domains settings for unauthorized users (#6602)
fix: hide domains settings for unauthorized users Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
<ng-container *ngIf="currentSetting === 'login'">
|
<ng-container *ngIf="currentSetting === 'login'">
|
||||||
<cnsl-login-policy [serviceType]="serviceType"></cnsl-login-policy>
|
<cnsl-login-policy [serviceType]="serviceType"></cnsl-login-policy>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="currentSetting === 'domain'">
|
<ng-container *ngIf="currentSetting === 'domain' && (['iam.policy.write'] | hasRole | async) === true">
|
||||||
<cnsl-domain-policy [serviceType]="serviceType"></cnsl-domain-policy>
|
<cnsl-domain-policy [serviceType]="serviceType"></cnsl-domain-policy>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="currentSetting === 'idp'">
|
<ng-container *ngIf="currentSetting === 'idp'">
|
||||||
|
@@ -48,8 +48,8 @@ export const DOMAIN: SidenavSetting = {
|
|||||||
i18nKey: 'SETTINGS.LIST.DOMAIN',
|
i18nKey: 'SETTINGS.LIST.DOMAIN',
|
||||||
groupI18nKey: 'SETTINGS.GROUPS.DOMAIN',
|
groupI18nKey: 'SETTINGS.GROUPS.DOMAIN',
|
||||||
requiredRoles: {
|
requiredRoles: {
|
||||||
[PolicyComponentServiceType.MGMT]: ['policy.read'],
|
[PolicyComponentServiceType.MGMT]: ['iam.policy.write'],
|
||||||
[PolicyComponentServiceType.ADMIN]: ['iam.policy.read'],
|
[PolicyComponentServiceType.ADMIN]: ['iam.policy.write'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -28,11 +28,6 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
(click)="value = setting.id"
|
(click)="value = setting.id"
|
||||||
*ngIf="
|
|
||||||
!setting.requiredRoles ||
|
|
||||||
(setting.requiredRoles.mgmt && (setting.requiredRoles.mgmt | hasRole | async)) ||
|
|
||||||
(setting.requiredRoles.admin && (setting.requiredRoles.admin | hasRole | async))
|
|
||||||
"
|
|
||||||
class="sidenav-setting-list-element hide-on-mobile"
|
class="sidenav-setting-list-element hide-on-mobile"
|
||||||
[ngClass]="{ active: currentSetting === setting.id, show: currentSetting === undefined }"
|
[ngClass]="{ active: currentSetting === setting.id, show: currentSetting === undefined }"
|
||||||
[attr.data-e2e]="'sidenav-element-' + setting.id"
|
[attr.data-e2e]="'sidenav-element-' + setting.id"
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import { Component, OnDestroy } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { Subject, takeUntil } from 'rxjs';
|
import { Subject, takeUntil } from 'rxjs';
|
||||||
import { PolicyComponentServiceType } from 'src/app/modules/policies/policy-component-types.enum';
|
import { PolicyComponentServiceType } from 'src/app/modules/policies/policy-component-types.enum';
|
||||||
import { SidenavSetting } from 'src/app/modules/sidenav/sidenav.component';
|
import { SidenavSetting } from 'src/app/modules/sidenav/sidenav.component';
|
||||||
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
|
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
|
||||||
|
|
||||||
|
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
|
||||||
import {
|
import {
|
||||||
BRANDING,
|
BRANDING,
|
||||||
COMPLEXITY,
|
COMPLEXITY,
|
||||||
@@ -21,16 +22,17 @@ import {
|
|||||||
SECRETS,
|
SECRETS,
|
||||||
SECURITY,
|
SECURITY,
|
||||||
} from '../../modules/settings-list/settings';
|
} from '../../modules/settings-list/settings';
|
||||||
|
import { checkSettingsPermissions } from '../org-settings/org-settings.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'cnsl-instance-settings',
|
selector: 'cnsl-instance-settings',
|
||||||
templateUrl: './instance-settings.component.html',
|
templateUrl: './instance-settings.component.html',
|
||||||
styleUrls: ['./instance-settings.component.scss'],
|
styleUrls: ['./instance-settings.component.scss'],
|
||||||
})
|
})
|
||||||
export class InstanceSettingsComponent implements OnDestroy {
|
export class InstanceSettingsComponent implements OnInit, OnDestroy {
|
||||||
public id: string = '';
|
public id: string = '';
|
||||||
public PolicyComponentServiceType: any = PolicyComponentServiceType;
|
public PolicyComponentServiceType: any = PolicyComponentServiceType;
|
||||||
public settingsList: SidenavSetting[] = [
|
public defaultSettingsList: SidenavSetting[] = [
|
||||||
GENERAL,
|
GENERAL,
|
||||||
// notifications
|
// notifications
|
||||||
// { showWarn: true, ...NOTIFICATIONS },
|
// { showWarn: true, ...NOTIFICATIONS },
|
||||||
@@ -53,8 +55,10 @@ export class InstanceSettingsComponent implements OnDestroy {
|
|||||||
SECURITY,
|
SECURITY,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public settingsList: SidenavSetting[] = [];
|
||||||
|
|
||||||
private destroy$: Subject<void> = new Subject();
|
private destroy$: Subject<void> = new Subject();
|
||||||
constructor(breadcrumbService: BreadcrumbService, activatedRoute: ActivatedRoute) {
|
constructor(breadcrumbService: BreadcrumbService, activatedRoute: ActivatedRoute, public authService: GrpcAuthService) {
|
||||||
const breadcrumbs = [
|
const breadcrumbs = [
|
||||||
new Breadcrumb({
|
new Breadcrumb({
|
||||||
type: BreadcrumbType.INSTANCE,
|
type: BreadcrumbType.INSTANCE,
|
||||||
@@ -72,6 +76,16 @@ export class InstanceSettingsComponent implements OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
checkSettingsPermissions(this.defaultSettingsList, PolicyComponentServiceType.ADMIN, this.authService).subscribe(
|
||||||
|
(allowed) => {
|
||||||
|
this.settingsList = this.defaultSettingsList.filter((setting, index) => {
|
||||||
|
return allowed[index];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router';
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { take } from 'rxjs';
|
import { forkJoin, of, take } from 'rxjs';
|
||||||
import { PolicyComponentServiceType } from 'src/app/modules/policies/policy-component-types.enum';
|
import { PolicyComponentServiceType } from 'src/app/modules/policies/policy-component-types.enum';
|
||||||
import { SidenavSetting } from 'src/app/modules/sidenav/sidenav.component';
|
import { SidenavSetting } from 'src/app/modules/sidenav/sidenav.component';
|
||||||
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
|
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
|
||||||
|
|
||||||
|
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
|
||||||
import {
|
import {
|
||||||
BRANDING,
|
BRANDING,
|
||||||
COMPLEXITY,
|
COMPLEXITY,
|
||||||
@@ -23,10 +24,11 @@ import {
|
|||||||
templateUrl: './org-settings.component.html',
|
templateUrl: './org-settings.component.html',
|
||||||
styleUrls: ['./org-settings.component.scss'],
|
styleUrls: ['./org-settings.component.scss'],
|
||||||
})
|
})
|
||||||
export class OrgSettingsComponent {
|
export class OrgSettingsComponent implements OnInit {
|
||||||
public id: string = '';
|
public id: string = '';
|
||||||
public PolicyComponentServiceType: any = PolicyComponentServiceType;
|
public PolicyComponentServiceType: any = PolicyComponentServiceType;
|
||||||
public settingsList: SidenavSetting[] = [
|
|
||||||
|
private defaultSettingsList: SidenavSetting[] = [
|
||||||
LOGIN,
|
LOGIN,
|
||||||
IDP,
|
IDP,
|
||||||
COMPLEXITY,
|
COMPLEXITY,
|
||||||
@@ -39,7 +41,9 @@ export class OrgSettingsComponent {
|
|||||||
PRIVACYPOLICY,
|
PRIVACYPOLICY,
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor(breadcrumbService: BreadcrumbService, activatedRoute: ActivatedRoute) {
|
public settingsList: SidenavSetting[] = [];
|
||||||
|
|
||||||
|
constructor(breadcrumbService: BreadcrumbService, activatedRoute: ActivatedRoute, public authService: GrpcAuthService) {
|
||||||
const breadcrumbs = [
|
const breadcrumbs = [
|
||||||
new Breadcrumb({
|
new Breadcrumb({
|
||||||
type: BreadcrumbType.ORG,
|
type: BreadcrumbType.ORG,
|
||||||
@@ -55,4 +59,42 @@ export class OrgSettingsComponent {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
checkSettingsPermissions(this.defaultSettingsList, PolicyComponentServiceType.MGMT, this.authService).subscribe(
|
||||||
|
(allowed) => {
|
||||||
|
this.settingsList = this.defaultSettingsList.filter((setting, index) => {
|
||||||
|
return allowed[index];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a Observables<boolean>[] that will wait till all service calls are finished to then check if user is allowed to see a setting
|
||||||
|
export function checkSettingsPermissions(settings: SidenavSetting[], serviceType: string, authService: GrpcAuthService) {
|
||||||
|
return forkJoin(
|
||||||
|
settings
|
||||||
|
.filter((setting) => {
|
||||||
|
if (serviceType === PolicyComponentServiceType.ADMIN) {
|
||||||
|
return setting.requiredRoles && setting.requiredRoles.admin;
|
||||||
|
} else {
|
||||||
|
return setting.requiredRoles && setting.requiredRoles.mgmt;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map((setting) => {
|
||||||
|
if (!setting.requiredRoles) {
|
||||||
|
return of(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!setting.requiredRoles.mgmt) {
|
||||||
|
return of(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setting.requiredRoles.mgmt) {
|
||||||
|
return authService.isAllowed(setting.requiredRoles.mgmt).pipe(take(1));
|
||||||
|
}
|
||||||
|
return of(false);
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user