Skip to content

Commit 8bc1235

Browse files
authored
Merge pull request ceph#62149 from rhcs-dashboard/fix-access-perm-ui
mgr/dashboard: fix access control permissions for roles Reviewed-by: Afreen Misbah <[email protected]>
2 parents 40fce9c + 3d6de8a commit 8bc1235

File tree

11 files changed

+80
-45
lines changed

11 files changed

+80
-45
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard-pie/dashboard-pie.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export class DashboardPieComponent implements OnChanges, OnInit {
1515
@Input()
1616
data: any;
1717
@Input()
18-
highThreshold: number;
18+
highThreshold = 0;
1919
@Input()
20-
lowThreshold: number;
20+
lowThreshold = 0;
2121

2222
color: string;
2323

@@ -162,15 +162,15 @@ export class DashboardPieComponent implements OnChanges, OnInit {
162162
const percentAvailable = this.calcPercentage(max - current, max);
163163
const percentUsed = this.calcPercentage(current, max);
164164

165-
if (fullRatioPercent >= 0 && percentUsed >= fullRatioPercent) {
165+
if (fullRatioPercent > 0 && percentUsed >= fullRatioPercent) {
166166
this.color = 'chart-color-red';
167-
} else if (nearFullRatioPercent >= 0 && percentUsed >= nearFullRatioPercent) {
167+
} else if (nearFullRatioPercent > 0 && percentUsed >= nearFullRatioPercent) {
168168
this.color = 'chart-color-yellow';
169169
} else {
170170
this.color = 'chart-color-blue';
171171
}
172172

173-
if (fullRatioPercent >= 0 && nearFullRatioPercent >= 0) {
173+
if (fullRatioPercent > 0 && nearFullRatioPercent > 0) {
174174
chart.dataset[0].data = [
175175
Math.round(nearFullRatioPercent),
176176
Math.round(Math.abs(nearFullRatioPercent - fullRatioPercent)),

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
[fullHeight]="true"
228228
aria-label="Capacity card">
229229
<ng-container class="ms-4 me-4"
230-
*ngIf="capacity && osdSettings">
230+
*ngIf="capacity">
231231
<cd-dashboard-pie [data]="{max: capacity.total_bytes, current: capacity.total_used_raw_bytes}"
232232
[lowThreshold]="osdSettings.nearfull_ratio"
233233
[highThreshold]="osdSettings.full_ratio">

src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { MgrModuleService } from '~/app/shared/api/mgr-module.service';
2626
import { AlertClass } from '~/app/shared/enum/health-icon.enum';
2727
import { HardwareService } from '~/app/shared/api/hardware.service';
2828
import { SettingsService } from '~/app/shared/api/settings.service';
29+
import { OsdSettings } from '~/app/shared/models/osd-settings';
2930

3031
@Component({
3132
selector: 'cd-dashboard-v3',
@@ -35,7 +36,7 @@ import { SettingsService } from '~/app/shared/api/settings.service';
3536
export class DashboardV3Component extends PrometheusListHelper implements OnInit, OnDestroy {
3637
detailsCardData: DashboardDetails = {};
3738
osdSettingsService: any;
38-
osdSettings: any;
39+
osdSettings = new OsdSettings();
3940
interval = new Subscription();
4041
permissions: Permissions;
4142
enabledFeature$: FeatureTogglesMap$;
@@ -117,7 +118,8 @@ export class DashboardV3Component extends PrometheusListHelper implements OnInit
117118
}
118119
this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
119120
this.getHealth();
120-
this.getCapacityCardData();
121+
this.getCapacity();
122+
if (this.permissions.configOpt.read) this.getOsdSettings();
121123
if (this.hardwareEnabled) this.hardwareSubject.next([]);
122124
});
123125
this.getPrometheusData(this.prometheusService.lastHourDateObject);
@@ -165,16 +167,19 @@ export class DashboardV3Component extends PrometheusListHelper implements OnInit
165167
);
166168
}
167169

168-
getCapacityCardData() {
170+
private getCapacity() {
171+
this.capacityService = this.healthService.getClusterCapacity().subscribe((data: any) => {
172+
this.capacity = data;
173+
});
174+
}
175+
176+
private getOsdSettings() {
169177
this.osdSettingsService = this.osdService
170178
.getOsdSettings()
171179
.pipe(take(1))
172-
.subscribe((data: any) => {
180+
.subscribe((data: OsdSettings) => {
173181
this.osdSettings = data;
174182
});
175-
this.capacityService = this.healthService.getClusterCapacity().subscribe((data: any) => {
176-
this.capacity = data;
177-
});
178183
}
179184

180185
public getPrometheusData(selectedTime: any) {

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-details/rgw-multisite-details.component.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<cd-rgw-multisite-tabs></cd-rgw-multisite-tabs>
22
<div>
3-
<cd-alert-panel *ngIf="!rgwModuleStatus"
3+
<!-- Show the alert only when the user has the permission to configure -->
4+
<cd-alert-panel *ngIf="permissions.configOpt.create && !rgwModuleStatus"
45
type="info"
56
spacingClass="mb-3"
67
class="d-flex align-items-center"
@@ -18,32 +19,32 @@
1819
Cluster->Services</a>
1920
</cd-alert-panel>
2021
<cd-table-actions class="btn-group mb-4 me-2"
21-
[permission]="permission"
22+
[permission]="permissions.rgw"
2223
[selection]="selection"
2324
[tableActions]="multisiteReplicationActions">
2425
</cd-table-actions>
2526
<cd-table-actions *ngIf="showMigrateAndReplicationActions"
2627
class="btn-group mb-4 me-2 secondary"
27-
[permission]="permission"
28+
[permission]="permissions.rgw"
2829
[btnColor]="'light'"
2930
[selection]="selection"
3031
[tableActions]="migrateTableAction">
3132
</cd-table-actions>
3233
<cd-table-actions *ngIf="!showMigrateAndReplicationActions"
3334
class="btn-group mb-4 me-2"
34-
[permission]="permission"
35+
[permission]="permissions.rgw"
3536
[selection]="selection"
3637
[tableActions]="createTableActions"
3738
[primaryDropDown]="true">
3839
</cd-table-actions>
3940
<cd-table-actions class="btn-group mb-4 me-2"
40-
[permission]="permission"
41+
[permission]="permissions.rgw"
4142
[btnColor]="'light'"
4243
[selection]="selection"
4344
[tableActions]="importAction">
4445
</cd-table-actions>
4546
<cd-table-actions class="btn-group mb-4 me-2"
46-
[permission]="permission"
47+
[permission]="permissions.rgw"
4748
[btnColor]="'light'"
4849
[selection]="selection"
4950
[tableActions]="exportAction">

src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-details/rgw-multisite-details.component.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Icons } from '~/app/shared/enum/icons.enum';
2121
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
2222
import { CdTableAction } from '~/app/shared/models/cd-table-action';
2323
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
24-
import { Permission } from '~/app/shared/models/permissions';
24+
import { Permissions } from '~/app/shared/models/permissions';
2525
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
2626
import { ModalService } from '~/app/shared/services/modal.service';
2727
import { NotificationService } from '~/app/shared/services/notification.service';
@@ -43,6 +43,8 @@ import { RgwMultisiteWizardComponent } from '../rgw-multisite-wizard/rgw-multisi
4343
import { RgwMultisiteSyncPolicyComponent } from '../rgw-multisite-sync-policy/rgw-multisite-sync-policy.component';
4444
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
4545
import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
46+
import { MgrModuleInfo } from '~/app/shared/models/mgr-modules.interface';
47+
import { RGW } from '../utils/constants';
4648

4749
const BASE_URL = 'rgw/multisite/configuration';
4850

@@ -68,7 +70,7 @@ export class RgwMultisiteDetailsComponent implements OnDestroy, OnInit {
6870
blockUI: NgBlockUI;
6971

7072
icons = Icons;
71-
permission: Permission;
73+
permissions: Permissions;
7274
selection = new CdTableSelection();
7375
createTableActions: CdTableAction[];
7476
migrateTableAction: CdTableAction[];
@@ -144,7 +146,7 @@ export class RgwMultisiteDetailsComponent implements OnDestroy, OnInit {
144146
private rgwMultisiteService: RgwMultisiteService,
145147
private changeDetectionRef: ChangeDetectorRef
146148
) {
147-
this.permission = this.authStorageService.getPermissions().rgw;
149+
this.permissions = this.authStorageService.getPermissions();
148150
}
149151

150152
openModal(entity: any | string, edit = false) {
@@ -305,27 +307,24 @@ export class RgwMultisiteDetailsComponent implements OnDestroy, OnInit {
305307
},
306308
(_error) => {}
307309
);
308-
this.mgrModuleService.list().subscribe((moduleData: any) => {
309-
this.rgwModuleData = moduleData.filter((module: object) => module['name'] === 'rgw');
310-
if (this.rgwModuleData.length > 0) {
311-
this.rgwModuleStatus = this.rgwModuleData[0].enabled;
312-
}
313-
});
310+
311+
// Only get the module status if you can read from configOpt
312+
if (this.permissions.configOpt.read) this.getRgwModuleStatus();
314313
}
315-
/* setConfigValues() {
316-
this.rgwDaemonService
317-
.setMultisiteConfig(
318-
this.defaultsInfo['defaultRealmName'],
319-
this.defaultsInfo['defaultZonegroupName'],
320-
this.defaultsInfo['defaultZoneName']
321-
)
322-
.subscribe(() => {});
323-
}*/
324314

325315
ngOnDestroy() {
326316
this.sub.unsubscribe();
327317
}
328318

319+
private getRgwModuleStatus() {
320+
this.mgrModuleService.list().subscribe((moduleData: MgrModuleInfo[]) => {
321+
this.rgwModuleData = moduleData.filter((module: MgrModuleInfo) => module.name === RGW);
322+
if (this.rgwModuleData.length > 0) {
323+
this.rgwModuleStatus = this.rgwModuleData[0].enabled;
324+
}
325+
});
326+
}
327+
329328
private abstractTreeData(multisiteInfo: [object, object, object]): any[] {
330329
let allNodes: object[] = [];
331330
let rootNodes = {};
@@ -637,7 +636,7 @@ export class RgwMultisiteDetailsComponent implements OnDestroy, OnInit {
637636
};
638637

639638
if (!this.rgwModuleStatus) {
640-
$obs = this.mgrModuleService.enable('rgw');
639+
$obs = this.mgrModuleService.enable(RGW);
641640
}
642641
$obs.subscribe(
643642
() => undefined,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const RGW = 'rgw';

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/administration/administration.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<cds-overflow-menu [customTrigger]="customTrigger"
22
[flip]="true">
3-
<li class="cds--overflow-menu-options__option mb-2"
4-
*ngIf="userPermission.read">
3+
<li class="cds--overflow-menu-options__option mb-2">
54
<button routerLink="/user-management"
65
class="cds--overflow-menu-options__btn"
76
i18n>User management</button>

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
<div class="cds--btn cds--btn--icon-only cds--header__action">
4141
<cd-dashboard-help></cd-dashboard-help>
4242
</div>
43-
<div class="cds--btn cds--btn--icon-only cds--header__action">
43+
<div class="cds--btn cds--btn--icon-only cds--header__action"
44+
*ngIf="permissions.user.read">
4445
<cd-administration></cd-administration>
4546
</div>
4647
<div class="cds--btn cds--btn--icon-only cds--header__action">
@@ -94,6 +95,7 @@
9495
</cds-sidenav-item>
9596
<!-- Multi-cluster Dashboard -->
9697
<cds-sidenav-menu title="Multi-Cluster"
98+
*ngIf="permissions.configOpt.read"
9799
i18n-title>
98100
<svg cdsIcon="edge-cluster"
99101
icon

src/pybind/mgr/dashboard/frontend/src/app/shared/api/mgr-module.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Observable, timer as observableTimer } from 'rxjs';
66
import { NotificationService } from '../services/notification.service';
77
import { TableComponent } from '../datatable/table/table.component';
88
import { Router } from '@angular/router';
9+
import { MgrModuleInfo } from '../models/mgr-modules.interface';
910

1011
@Injectable({
1112
providedIn: 'root'
@@ -28,8 +29,8 @@ export class MgrModuleService {
2829
* Get the list of Ceph Mgr modules and their state (enabled/disabled).
2930
* @return {Observable<Object[]>}
3031
*/
31-
list(): Observable<Object[]> {
32-
return this.http.get<Object[]>(`${this.url}`);
32+
list(): Observable<MgrModuleInfo[]> {
33+
return this.http.get<MgrModuleInfo[]>(`${this.url}`);
3334
}
3435

3536
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export interface MgrModuleInfo {
2+
name: string;
3+
enabled: boolean;
4+
always_on: boolean;
5+
options: Record<string, MgrModuleOption>;
6+
}
7+
8+
interface MgrModuleOption {
9+
name: string;
10+
type: string;
11+
level: string;
12+
flags: number;
13+
default_value: number;
14+
min: string;
15+
max: string;
16+
enum_allowed: string[];
17+
desc: string;
18+
long_desc: string;
19+
tags: string[];
20+
see_also: string[];
21+
}

0 commit comments

Comments
 (0)