Skip to content

Commit bc93103

Browse files
prik73afreen23
authored andcommitted
mgr/dashboard: remove hardcoded strings in About component
Replaced inline values for user role, version prefix, and localStorage keys with shared constants (`USER`, `VERSION_PREFIX`, and `LocalStorage.DASHBOARD_USERNAME`). This keeps things DRY and makes future updates easier. Addresses part of the constant reuse cleanup in the dashboard. Fixes: https://tracker.ceph.com/issues/70947 Signed-off-by: prik73 <[email protected]> Signed-off-by: Afreen Misbah <[email protected]>
1 parent a99c77a commit bc93103

File tree

42 files changed

+130
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+130
-98
lines changed

src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ declare global {
1818
import { CdHelperClass } from '../../src/app/shared/classes/cd-helper.class';
1919
import { Permissions } from '../../src/app/shared/models/permissions';
2020
import { table } from 'table';
21+
import { LocalStorage } from '~/app/shared/enum/local-storage-enum';
2122
/* tslint:enable*/
2223
let auth: any;
2324

2425
const fillAuth = () => {
25-
window.localStorage.setItem('dashboard_username', auth.username);
26+
window.localStorage.setItem(LocalStorage.DASHBOARD_USRENAME, auth.username);
2627
window.localStorage.setItem('dashboard_permissions', auth.permissions);
2728
window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate);
2829
window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired);
@@ -64,7 +65,7 @@ Cypress.Commands.add('ceph2Login', (username, password) => {
6465
url,
6566
{ args },
6667
({ uname, permissions, pwdExpirationDate, pwdUpdateRequired, sso }: any) => {
67-
window.localStorage.setItem('dashboard_username', uname);
68+
window.localStorage.setItem(LocalStorage.DASHBOARD_USRENAME, uname);
6869
window.localStorage.setItem('dashboard_permissions', permissions);
6970
window.localStorage.setItem('user_pwd_expiration_date', pwdExpirationDate);
7071
window.localStorage.setItem('user_pwd_update_required', pwdUpdateRequired);

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TreeviewModule } from 'carbon-components-angular';
66
import { SharedModule } from '~/app/shared/shared.module';
77
import { configureTestBed } from '~/testing/unit-test-helper';
88
import { IscsiTargetDetailsComponent } from './iscsi-target-details.component';
9+
import { USER } from '~/app/shared/constants/app.constants';
910

1011
describe('IscsiTargetDetailsComponent', () => {
1112
let component: IscsiTargetDetailsComponent;
@@ -234,7 +235,7 @@ describe('IscsiTargetDetailsComponent', () => {
234235
);
235236
component.onNodeSelected(node);
236237
expect(component.data).toEqual([
237-
{ current: 'myiscsiusername', default: undefined, displayName: 'user' },
238+
{ current: 'myiscsiusername', default: undefined, displayName: USER },
238239
{ current: 'myhost', default: undefined, displayName: 'alias' },
239240
{ current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' },
240241
{ current: ['node1'], default: undefined, displayName: 'logged_in' }

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@an
22

33
import { Node } from 'carbon-components-angular/treeview/tree-node.types';
44
import _ from 'lodash';
5+
import { USER } from '~/app/shared/constants/app.constants';
56

67
import { TableComponent } from '~/app/shared/datatable/table/table.component';
78
import { Icons } from '~/app/shared/enum/icons.enum';
@@ -322,7 +323,7 @@ export class IscsiTargetDetailsComponent implements OnChanges, OnInit {
322323
});
323324
// Target level authentication was introduced in ceph-iscsi config v11
324325
if (this.cephIscsiConfigVersion > 10) {
325-
['user', 'password', 'mutual_user', 'mutual_password'].forEach((key) => {
326+
[USER, 'password', 'mutual_user', 'mutual_password'].forEach((key) => {
326327
this.data.push({
327328
displayName: key,
328329
default: null,

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Permission } from '~/app/shared/models/permissions';
1515
import { SharedModule } from '~/app/shared/shared.module';
1616
import { configureTestBed, FormHelper, IscsiHelper } from '~/testing/unit-test-helper';
1717
import { IscsiTargetDiscoveryModalComponent } from './iscsi-target-discovery-modal.component';
18+
import { USER } from '~/app/shared/constants/app.constants';
1819

1920
describe('IscsiTargetDiscoveryModalComponent', () => {
2021
let component: IscsiTargetDiscoveryModalComponent;
@@ -125,7 +126,7 @@ describe('IscsiTargetDiscoveryModalComponent', () => {
125126
const formHelper = new FormHelper(control);
126127
formHelper.expectValid(control);
127128

128-
IscsiHelper.validateUser(formHelper, 'user');
129+
IscsiHelper.validateUser(formHelper, USER);
129130
IscsiHelper.validatePassword(formHelper, 'password');
130131
IscsiHelper.validateUser(formHelper, 'mutual_user');
131132
IscsiHelper.validatePassword(formHelper, 'mutual_password');

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { UntypedFormControl, Validators } from '@angular/forms';
44
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
55

66
import { IscsiService } from '~/app/shared/api/iscsi.service';
7-
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
7+
import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants';
88
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
99
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
1010
import { CdValidators } from '~/app/shared/forms/cd-validators';
@@ -52,7 +52,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit {
5252
});
5353

5454
CdValidators.validateIf(
55-
this.discoveryForm.get('user'),
55+
this.discoveryForm.get(USER),
5656
() =>
5757
this.discoveryForm.getValue('password') ||
5858
this.discoveryForm.getValue('mutual_user') ||
@@ -69,13 +69,13 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit {
6969
CdValidators.validateIf(
7070
this.discoveryForm.get('password'),
7171
() =>
72-
this.discoveryForm.getValue('user') ||
72+
this.discoveryForm.getValue(USER) ||
7373
this.discoveryForm.getValue('mutual_user') ||
7474
this.discoveryForm.getValue('mutual_password'),
7575
[Validators.required],
7676
[Validators.pattern(this.PASSWORD_REGEX)],
7777
[
78-
this.discoveryForm.get('user'),
78+
this.discoveryForm.get(USER),
7979
this.discoveryForm.get('mutual_user'),
8080
this.discoveryForm.get('mutual_password')
8181
]
@@ -87,7 +87,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit {
8787
[Validators.required],
8888
[Validators.pattern(this.USER_REGEX)],
8989
[
90-
this.discoveryForm.get('user'),
90+
this.discoveryForm.get(USER),
9191
this.discoveryForm.get('password'),
9292
this.discoveryForm.get('mutual_password')
9393
]
@@ -99,7 +99,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit {
9999
[Validators.required],
100100
[Validators.pattern(this.PASSWORD_REGEX)],
101101
[
102-
this.discoveryForm.get('user'),
102+
this.discoveryForm.get(USER),
103103
this.discoveryForm.get('password'),
104104
this.discoveryForm.get('mutual_user')
105105
]

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IscsiService } from '~/app/shared/api/iscsi.service';
1010
import { RbdService } from '~/app/shared/api/rbd.service';
1111
import { SelectMessages } from '~/app/shared/components/select/select-messages.model';
1212
import { SelectOption } from '~/app/shared/components/select/select-option.model';
13-
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
13+
import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants';
1414
import { Icons } from '~/app/shared/enum/icons.enum';
1515
import { CdForm } from '~/app/shared/forms/cd-form';
1616
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
@@ -460,7 +460,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit {
460460

461461
setAuthValidator(fg: CdFormGroup) {
462462
CdValidators.validateIf(
463-
fg.get('user'),
463+
fg.get(USER),
464464
() => fg.getValue('password') || fg.getValue('mutual_user') || fg.getValue('mutual_password'),
465465
[Validators.required],
466466
[Validators.pattern(this.USER_REGEX)],
@@ -469,26 +469,26 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit {
469469

470470
CdValidators.validateIf(
471471
fg.get('password'),
472-
() => fg.getValue('user') || fg.getValue('mutual_user') || fg.getValue('mutual_password'),
472+
() => fg.getValue(USER) || fg.getValue('mutual_user') || fg.getValue('mutual_password'),
473473
[Validators.required],
474474
[Validators.pattern(this.PASSWORD_REGEX)],
475-
[fg.get('user'), fg.get('mutual_user'), fg.get('mutual_password')]
475+
[fg.get(USER), fg.get('mutual_user'), fg.get('mutual_password')]
476476
);
477477

478478
CdValidators.validateIf(
479479
fg.get('mutual_user'),
480480
() => fg.getValue('mutual_password'),
481481
[Validators.required],
482482
[Validators.pattern(this.USER_REGEX)],
483-
[fg.get('user'), fg.get('password'), fg.get('mutual_password')]
483+
[fg.get(USER), fg.get('password'), fg.get('mutual_password')]
484484
);
485485

486486
CdValidators.validateIf(
487487
fg.get('mutual_password'),
488488
() => fg.getValue('mutual_user'),
489489
[Validators.required],
490490
[Validators.pattern(this.PASSWORD_REGEX)],
491-
[fg.get('user'), fg.get('password'), fg.get('mutual_user')]
491+
[fg.get(USER), fg.get('password'), fg.get('mutual_user')]
492492
);
493493
}
494494

@@ -658,8 +658,8 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit {
658658
// Target level authentication was introduced in ceph-iscsi config v11
659659
if (this.cephIscsiConfigVersion > 10) {
660660
const targetAuth: CdFormGroup = this.targetForm.get('auth') as CdFormGroup;
661-
if (!targetAuth.getValue('user')) {
662-
targetAuth.get('user').setValue('');
661+
if (!targetAuth.getValue(USER)) {
662+
targetAuth.get(USER).setValue('');
663663
}
664664
if (!targetAuth.getValue('password')) {
665665
targetAuth.get('password').setValue('');
@@ -672,7 +672,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit {
672672
}
673673
const acl_enabled = this.targetForm.getValue('acl_enabled');
674674
request['auth'] = {
675-
user: acl_enabled ? '' : targetAuth.getValue('user'),
675+
user: acl_enabled ? '' : targetAuth.getValue(USER),
676676
password: acl_enabled ? '' : targetAuth.getValue('password'),
677677
mutual_user: acl_enabled ? '' : targetAuth.getValue('mutual_user'),
678678
mutual_password: acl_enabled ? '' : targetAuth.getValue('mutual_password')

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Subject, throwError as observableThrowError } from 'rxjs';
1010

1111
import { RbdService } from '~/app/shared/api/rbd.service';
1212
import { ComponentsModule } from '~/app/shared/components/components.module';
13-
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
13+
import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants';
1414
import { DataTableModule } from '~/app/shared/datatable/datatable.module';
1515
import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component';
1616
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
@@ -120,7 +120,7 @@ describe('RbdSnapshotListComponent', () => {
120120
rbdService = new RbdService(null, null);
121121
notificationService = new NotificationService(null, null, null);
122122
authStorageService = new AuthStorageService();
123-
authStorageService.set('user', { 'rbd-image': ['create', 'read', 'update', 'delete'] });
123+
authStorageService.set(USER, { 'rbd-image': ['create', 'read', 'update', 'delete'] });
124124
component = new RbdSnapshotListComponent(
125125
authStorageService,
126126
null,

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
44
import _ from 'lodash';
55
import { Subscription } from 'rxjs';
66
import { MultiClusterService } from '~/app/shared/api/multi-cluster.service';
7-
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
7+
import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants';
88
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
99
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
1010
import { CdValidators } from '~/app/shared/forms/cd-validators';
@@ -66,7 +66,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
6666
[this.clusterAliasNames, this.clusterUrls, this.clusterUsers] = [
6767
'cluster_alias',
6868
'url',
69-
'user'
69+
USER
7070
].map((prop) => this.clustersData?.map((cluster) => cluster[prop]));
7171
}
7272

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { MultiClusterFormComponent } from './multi-cluster-form/multi-cluster-fo
88
import { PrometheusService } from '~/app/shared/api/prometheus.service';
99
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
1010
import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
11+
import { VERSION_PREFIX } from '~/app/shared/constants/app.constants';
12+
1113
import { Router } from '@angular/router';
1214

1315
import {
@@ -491,8 +493,8 @@ export class MultiClusterComponent implements OnInit, OnDestroy {
491493
}
492494

493495
getVersion(fullVersion: string) {
494-
const version = fullVersion.replace('ceph version ', '').split(' ');
495-
return version[0] + ' ' + version.slice(2, version.length).join(' ');
496+
const version = fullVersion.replace(`${VERSION_PREFIX} `, '').split(' ');
497+
return version[0] + ' ' + version.slice(2).join(' ');
496498
}
497499

498500
generateQueryLabel(query: any, name = false, count = this.COUNT_OF_UTILIZATION_CHARTS) {

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { SharedModule } from '~/app/shared/shared.module';
1616
import { configureTestBed, FormHelper, Mocks } from '~/testing/unit-test-helper';
1717
import { ServiceFormComponent } from './service-form.component';
1818
import { PoolService } from '~/app/shared/api/pool.service';
19+
import { USER } from '~/app/shared/constants/app.constants';
1920

2021
// for 'nvmeof' service
2122
const mockPools = [
@@ -314,7 +315,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
314315
beforeEach(() => {
315316
formHelper.setValue('service_type', 'iscsi');
316317
formHelper.setValue('pool', 'xyz');
317-
formHelper.setValue('api_user', 'user');
318+
formHelper.setValue('api_user', USER);
318319
formHelper.setValue('api_password', 'password');
319320
formHelper.setValue('ssl', false);
320321
});
@@ -326,7 +327,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
326327
placement: {},
327328
unmanaged: false,
328329
pool: 'xyz',
329-
api_user: 'user',
330+
api_user: USER,
330331
api_password: 'password',
331332
api_secure: false
332333
});
@@ -341,7 +342,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
341342
placement: {},
342343
unmanaged: false,
343344
pool: 'xyz',
344-
api_user: 'user',
345+
api_user: USER,
345346
api_password: 'password',
346347
api_secure: true,
347348
ssl_cert: '',
@@ -358,7 +359,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
358359
placement: {},
359360
unmanaged: false,
360361
pool: 'xyz',
361-
api_user: 'user',
362+
api_user: USER,
362363
api_password: 'password',
363364
api_secure: false,
364365
api_port: 456

0 commit comments

Comments
 (0)