From bc9310345a1cdb01bb8fabffcff8fdf77747ebbb Mon Sep 17 00:00:00 2001 From: prik73 Date: Wed, 28 May 2025 00:34:37 +0530 Subject: [PATCH] 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 Signed-off-by: Afreen Misbah --- .../frontend/cypress/support/commands.ts | 5 +++-- .../iscsi-target-details.component.spec.ts | 3 ++- .../iscsi-target-details.component.ts | 3 ++- ...si-target-discovery-modal.component.spec.ts | 3 ++- .../iscsi-target-discovery-modal.component.ts | 12 ++++++------ .../iscsi-target-form.component.ts | 18 +++++++++--------- .../rbd-snapshot-list.component.spec.ts | 4 ++-- .../multi-cluster-form.component.ts | 4 ++-- .../multi-cluster/multi-cluster.component.ts | 6 ++++-- .../service-form.component.spec.ts | 9 +++++---- .../cluster/upgrade/upgrade.component.spec.ts | 3 ++- .../ceph/cluster/upgrade/upgrade.component.ts | 3 ++- .../dashboard/dashboard-v3.component.spec.ts | 3 ++- .../dashboard/dashboard-v3.component.ts | 3 ++- .../rgw-daemon-list.component.spec.ts | 3 ++- ...multisite-sync-pipe-modal.component.spec.ts | 5 +++-- .../rgw-overview-dashboard.component.spec.ts | 3 ++- .../rgw-rate-limit-details.component.spec.ts | 3 ++- .../rgw-rate-limit/rgw-rate-limit.component.ts | 5 +++-- .../rgw-user-details.component.ts | 3 ++- .../rgw-user-form.component.spec.ts | 7 ++++--- .../rgw-user-form/rgw-user-form.component.ts | 6 +++--- .../smb-cluster-form.component.spec.ts | 3 ++- .../smb-join-auth-form.component.spec.ts | 7 ++++--- .../smb-usersgroups-form.component.spec.ts | 7 ++++--- .../frontend/src/app/ceph/smb/smb.model.ts | 7 ++++--- .../auth/role-form/role-form.component.spec.ts | 3 ++- .../core/auth/user-form/user-form.component.ts | 6 +++--- .../core/auth/user-list/user-list.component.ts | 4 ++-- .../navigation/about/about.component.spec.ts | 3 ++- .../navigation/navigation.component.ts | 13 +++++++------ .../src/app/shared/api/auth.service.spec.ts | 5 +++-- .../src/app/shared/api/rgw-zone.service.ts | 3 ++- .../src/app/shared/api/smb.service.spec.ts | 5 +++-- .../src/app/shared/api/upgrade.service.spec.ts | 3 ++- .../src/app/shared/api/upgrade.service.ts | 3 ++- .../pipes/ceph-release-name.pipe.spec.ts | 11 +++++------ .../app/shared/pipes/ceph-release-name.pipe.ts | 5 ++++- .../pipes/ceph-short-version.pipe.spec.ts | 6 +++--- .../shared/pipes/ceph-short-version.pipe.ts | 3 ++- .../services/auth-storage.service.spec.ts | 5 +++-- .../shared/services/auth-storage.service.ts | 12 +++++------- 42 files changed, 130 insertions(+), 98 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts b/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts index f437ebbdc554c..2cf450fa6db1c 100644 --- a/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts +++ b/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts @@ -18,11 +18,12 @@ declare global { import { CdHelperClass } from '../../src/app/shared/classes/cd-helper.class'; import { Permissions } from '../../src/app/shared/models/permissions'; import { table } from 'table'; +import { LocalStorage } from '~/app/shared/enum/local-storage-enum'; /* tslint:enable*/ let auth: any; const fillAuth = () => { - window.localStorage.setItem('dashboard_username', auth.username); + window.localStorage.setItem(LocalStorage.DASHBOARD_USRENAME, auth.username); window.localStorage.setItem('dashboard_permissions', auth.permissions); window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate); window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired); @@ -64,7 +65,7 @@ Cypress.Commands.add('ceph2Login', (username, password) => { url, { args }, ({ uname, permissions, pwdExpirationDate, pwdUpdateRequired, sso }: any) => { - window.localStorage.setItem('dashboard_username', uname); + window.localStorage.setItem(LocalStorage.DASHBOARD_USRENAME, uname); window.localStorage.setItem('dashboard_permissions', permissions); window.localStorage.setItem('user_pwd_expiration_date', pwdExpirationDate); window.localStorage.setItem('user_pwd_update_required', pwdUpdateRequired); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts index 1c2c007055b5f..13e8ff23e40ab 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts @@ -6,6 +6,7 @@ import { TreeviewModule } from 'carbon-components-angular'; import { SharedModule } from '~/app/shared/shared.module'; import { configureTestBed } from '~/testing/unit-test-helper'; import { IscsiTargetDetailsComponent } from './iscsi-target-details.component'; +import { USER } from '~/app/shared/constants/app.constants'; describe('IscsiTargetDetailsComponent', () => { let component: IscsiTargetDetailsComponent; @@ -234,7 +235,7 @@ describe('IscsiTargetDetailsComponent', () => { ); component.onNodeSelected(node); expect(component.data).toEqual([ - { current: 'myiscsiusername', default: undefined, displayName: 'user' }, + { current: 'myiscsiusername', default: undefined, displayName: USER }, { current: 'myhost', default: undefined, displayName: 'alias' }, { current: ['192.168.200.1'], default: undefined, displayName: 'ip_address' }, { current: ['node1'], default: undefined, displayName: 'logged_in' } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts index 4d985093172bb..7dcd81843d6dc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts @@ -2,6 +2,7 @@ import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@an import { Node } from 'carbon-components-angular/treeview/tree-node.types'; import _ from 'lodash'; +import { USER } from '~/app/shared/constants/app.constants'; import { TableComponent } from '~/app/shared/datatable/table/table.component'; import { Icons } from '~/app/shared/enum/icons.enum'; @@ -322,7 +323,7 @@ export class IscsiTargetDetailsComponent implements OnChanges, OnInit { }); // Target level authentication was introduced in ceph-iscsi config v11 if (this.cephIscsiConfigVersion > 10) { - ['user', 'password', 'mutual_user', 'mutual_password'].forEach((key) => { + [USER, 'password', 'mutual_user', 'mutual_password'].forEach((key) => { this.data.push({ displayName: key, default: null, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts index 0f540f18e9b4a..8ef136617def5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts @@ -15,6 +15,7 @@ import { Permission } from '~/app/shared/models/permissions'; import { SharedModule } from '~/app/shared/shared.module'; import { configureTestBed, FormHelper, IscsiHelper } from '~/testing/unit-test-helper'; import { IscsiTargetDiscoveryModalComponent } from './iscsi-target-discovery-modal.component'; +import { USER } from '~/app/shared/constants/app.constants'; describe('IscsiTargetDiscoveryModalComponent', () => { let component: IscsiTargetDiscoveryModalComponent; @@ -125,7 +126,7 @@ describe('IscsiTargetDiscoveryModalComponent', () => { const formHelper = new FormHelper(control); formHelper.expectValid(control); - IscsiHelper.validateUser(formHelper, 'user'); + IscsiHelper.validateUser(formHelper, USER); IscsiHelper.validatePassword(formHelper, 'password'); IscsiHelper.validateUser(formHelper, 'mutual_user'); IscsiHelper.validatePassword(formHelper, 'mutual_password'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts index d20525fdd43d9..259327822a327 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts @@ -4,7 +4,7 @@ import { UntypedFormControl, Validators } from '@angular/forms'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { IscsiService } from '~/app/shared/api/iscsi.service'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { NotificationType } from '~/app/shared/enum/notification-type.enum'; import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; import { CdValidators } from '~/app/shared/forms/cd-validators'; @@ -52,7 +52,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit { }); CdValidators.validateIf( - this.discoveryForm.get('user'), + this.discoveryForm.get(USER), () => this.discoveryForm.getValue('password') || this.discoveryForm.getValue('mutual_user') || @@ -69,13 +69,13 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit { CdValidators.validateIf( this.discoveryForm.get('password'), () => - this.discoveryForm.getValue('user') || + this.discoveryForm.getValue(USER) || this.discoveryForm.getValue('mutual_user') || this.discoveryForm.getValue('mutual_password'), [Validators.required], [Validators.pattern(this.PASSWORD_REGEX)], [ - this.discoveryForm.get('user'), + this.discoveryForm.get(USER), this.discoveryForm.get('mutual_user'), this.discoveryForm.get('mutual_password') ] @@ -87,7 +87,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit { [Validators.required], [Validators.pattern(this.USER_REGEX)], [ - this.discoveryForm.get('user'), + this.discoveryForm.get(USER), this.discoveryForm.get('password'), this.discoveryForm.get('mutual_password') ] @@ -99,7 +99,7 @@ export class IscsiTargetDiscoveryModalComponent implements OnInit { [Validators.required], [Validators.pattern(this.PASSWORD_REGEX)], [ - this.discoveryForm.get('user'), + this.discoveryForm.get(USER), this.discoveryForm.get('password'), this.discoveryForm.get('mutual_user') ] diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts index 21caa0b2e7035..0d5de9a72ae9c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts @@ -10,7 +10,7 @@ import { IscsiService } from '~/app/shared/api/iscsi.service'; import { RbdService } from '~/app/shared/api/rbd.service'; import { SelectMessages } from '~/app/shared/components/select/select-messages.model'; import { SelectOption } from '~/app/shared/components/select/select-option.model'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { Icons } from '~/app/shared/enum/icons.enum'; import { CdForm } from '~/app/shared/forms/cd-form'; import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; @@ -460,7 +460,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { setAuthValidator(fg: CdFormGroup) { CdValidators.validateIf( - fg.get('user'), + fg.get(USER), () => fg.getValue('password') || fg.getValue('mutual_user') || fg.getValue('mutual_password'), [Validators.required], [Validators.pattern(this.USER_REGEX)], @@ -469,10 +469,10 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { CdValidators.validateIf( fg.get('password'), - () => fg.getValue('user') || fg.getValue('mutual_user') || fg.getValue('mutual_password'), + () => fg.getValue(USER) || fg.getValue('mutual_user') || fg.getValue('mutual_password'), [Validators.required], [Validators.pattern(this.PASSWORD_REGEX)], - [fg.get('user'), fg.get('mutual_user'), fg.get('mutual_password')] + [fg.get(USER), fg.get('mutual_user'), fg.get('mutual_password')] ); CdValidators.validateIf( @@ -480,7 +480,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { () => fg.getValue('mutual_password'), [Validators.required], [Validators.pattern(this.USER_REGEX)], - [fg.get('user'), fg.get('password'), fg.get('mutual_password')] + [fg.get(USER), fg.get('password'), fg.get('mutual_password')] ); CdValidators.validateIf( @@ -488,7 +488,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { () => fg.getValue('mutual_user'), [Validators.required], [Validators.pattern(this.PASSWORD_REGEX)], - [fg.get('user'), fg.get('password'), fg.get('mutual_user')] + [fg.get(USER), fg.get('password'), fg.get('mutual_user')] ); } @@ -658,8 +658,8 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { // Target level authentication was introduced in ceph-iscsi config v11 if (this.cephIscsiConfigVersion > 10) { const targetAuth: CdFormGroup = this.targetForm.get('auth') as CdFormGroup; - if (!targetAuth.getValue('user')) { - targetAuth.get('user').setValue(''); + if (!targetAuth.getValue(USER)) { + targetAuth.get(USER).setValue(''); } if (!targetAuth.getValue('password')) { targetAuth.get('password').setValue(''); @@ -672,7 +672,7 @@ export class IscsiTargetFormComponent extends CdForm implements OnInit { } const acl_enabled = this.targetForm.getValue('acl_enabled'); request['auth'] = { - user: acl_enabled ? '' : targetAuth.getValue('user'), + user: acl_enabled ? '' : targetAuth.getValue(USER), password: acl_enabled ? '' : targetAuth.getValue('password'), mutual_user: acl_enabled ? '' : targetAuth.getValue('mutual_user'), mutual_password: acl_enabled ? '' : targetAuth.getValue('mutual_password') diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts index 924feb6cf4331..f42a1f7ede91e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts @@ -10,7 +10,7 @@ import { Subject, throwError as observableThrowError } from 'rxjs'; import { RbdService } from '~/app/shared/api/rbd.service'; import { ComponentsModule } from '~/app/shared/components/components.module'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { DataTableModule } from '~/app/shared/datatable/datatable.module'; import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component'; import { CdTableSelection } from '~/app/shared/models/cd-table-selection'; @@ -120,7 +120,7 @@ describe('RbdSnapshotListComponent', () => { rbdService = new RbdService(null, null); notificationService = new NotificationService(null, null, null); authStorageService = new AuthStorageService(); - authStorageService.set('user', { 'rbd-image': ['create', 'read', 'update', 'delete'] }); + authStorageService.set(USER, { 'rbd-image': ['create', 'read', 'update', 'delete'] }); component = new RbdSnapshotListComponent( authStorageService, null, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts index 481cf9ddce651..2c95c5cc4c6d4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts @@ -4,7 +4,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import _ from 'lodash'; import { Subscription } from 'rxjs'; import { MultiClusterService } from '~/app/shared/api/multi-cluster.service'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { NotificationType } from '~/app/shared/enum/notification-type.enum'; import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; import { CdValidators } from '~/app/shared/forms/cd-validators'; @@ -66,7 +66,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy { [this.clusterAliasNames, this.clusterUrls, this.clusterUsers] = [ 'cluster_alias', 'url', - 'user' + USER ].map((prop) => this.clustersData?.map((cluster) => cluster[prop])); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts index 02579680b852b..a843a34cc4191 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts @@ -8,6 +8,8 @@ import { MultiClusterFormComponent } from './multi-cluster-form/multi-cluster-fo import { PrometheusService } from '~/app/shared/api/prometheus.service'; import { CdTableColumn } from '~/app/shared/models/cd-table-column'; import { CellTemplate } from '~/app/shared/enum/cell-template.enum'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; + import { Router } from '@angular/router'; import { @@ -491,8 +493,8 @@ export class MultiClusterComponent implements OnInit, OnDestroy { } getVersion(fullVersion: string) { - const version = fullVersion.replace('ceph version ', '').split(' '); - return version[0] + ' ' + version.slice(2, version.length).join(' '); + const version = fullVersion.replace(`${VERSION_PREFIX} `, '').split(' '); + return version[0] + ' ' + version.slice(2).join(' '); } generateQueryLabel(query: any, name = false, count = this.COUNT_OF_UTILIZATION_CHARTS) { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts index bf1ac3ddf43ca..c6bd579489b2b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts @@ -16,6 +16,7 @@ import { SharedModule } from '~/app/shared/shared.module'; import { configureTestBed, FormHelper, Mocks } from '~/testing/unit-test-helper'; import { ServiceFormComponent } from './service-form.component'; import { PoolService } from '~/app/shared/api/pool.service'; +import { USER } from '~/app/shared/constants/app.constants'; // for 'nvmeof' service const mockPools = [ @@ -314,7 +315,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== beforeEach(() => { formHelper.setValue('service_type', 'iscsi'); formHelper.setValue('pool', 'xyz'); - formHelper.setValue('api_user', 'user'); + formHelper.setValue('api_user', USER); formHelper.setValue('api_password', 'password'); formHelper.setValue('ssl', false); }); @@ -326,7 +327,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== placement: {}, unmanaged: false, pool: 'xyz', - api_user: 'user', + api_user: USER, api_password: 'password', api_secure: false }); @@ -341,7 +342,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== placement: {}, unmanaged: false, pool: 'xyz', - api_user: 'user', + api_user: USER, api_password: 'password', api_secure: true, ssl_cert: '', @@ -358,7 +359,7 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== placement: {}, unmanaged: false, pool: 'xyz', - api_user: 'user', + api_user: USER, api_password: 'password', api_secure: false, api_port: 456 diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.spec.ts index 8c3e1c9eb2813..2ff6fe2ae6938 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.spec.ts @@ -15,11 +15,12 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ToastrModule } from 'ngx-toastr'; import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; import { RouterTestingModule } from '@angular/router/testing'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; export class SummaryServiceMock { summaryDataSource = new BehaviorSubject({ version: - 'ceph version 17.0.0-12222-gcd0cd7cb ' + + `${VERSION_PREFIX} 17.0.0-12222-gcd0cd7cb ` + '(b8193bb4cda16ccc5b028c3e1df62bc72350a15d) quincy (dev)' }); summaryData$ = this.summaryDataSource.asObservable(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.ts index 80ae0c4aadacb..d71b440802e64 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.ts @@ -16,6 +16,7 @@ import { SummaryService } from '~/app/shared/services/summary.service'; import { ExecutingTask } from '~/app/shared/models/executing-task'; import { Router } from '@angular/router'; import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; @Component({ selector: 'cd-upgrade', @@ -76,7 +77,7 @@ export class UpgradeComponent implements OnInit, OnDestroy { this.subs.add( this.summaryService.subscribe((summary) => { - const version = summary.version.replace('ceph version ', '').split('-'); + const version = summary.version.replace(VERSION_PREFIX, '').split('-'); this.version = version[0]; this.executingTasks = summary.executing_tasks.filter((tasks) => tasks.name.includes('progress/Upgrade') diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts index 1f168561cd4c8..0bb9a79501cb2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts @@ -24,11 +24,12 @@ import { DashboardV3Component } from './dashboard-v3.component'; import { OrchestratorService } from '~/app/shared/api/orchestrator.service'; import { AlertClass } from '~/app/shared/enum/health-icon.enum'; import { HealthSnapshotMap } from '~/app/shared/models/health.interface'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; export class SummaryServiceMock { summaryDataSource = new BehaviorSubject({ version: - 'ceph version 17.0.0-12222-gcd0cd7cb ' + + `${VERSION_PREFIX} 17.0.0-12222-gcd0cd7cb ` + '(b8193bb4cda16ccc5b028c3e1df62bc72350a15d) quincy (dev)' }); summaryData$ = this.summaryDataSource.asObservable(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts index b11b748f7f2b6..2b8fee828c9f3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts @@ -39,6 +39,7 @@ import { IscsiMap, PgStateCount } from '~/app/shared/models/health.interface'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; @Component({ selector: 'cd-dashboard-v3', @@ -175,7 +176,7 @@ export class DashboardV3Component extends PrometheusListHelper implements OnInit }); this.subs.add( this.summaryService.subscribe((summary) => { - const version = summary.version.replace('ceph version ', '').split(' '); + const version = summary.version.replace(`${VERSION_PREFIX} `, '').split(' '); this.detailsCardData.cephVersion = version[0] + ' ' + version.slice(2, version.length).join(' '); }) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts index 85aa96be10dff..d8ffa7df03a23 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts @@ -18,6 +18,7 @@ import { configureTestBed, TabHelper } from '~/testing/unit-test-helper'; import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component'; import { RgwDaemonListComponent } from './rgw-daemon-list.component'; import { TableComponent } from '~/app/shared/datatable/table/table.component'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; describe('RgwDaemonListComponent', () => { let component: RgwDaemonListComponent; @@ -29,7 +30,7 @@ describe('RgwDaemonListComponent', () => { const daemon: RgwDaemon = { id: '8000', service_map_id: '4803', - version: 'ceph version', + version: VERSION_PREFIX, server_hostname: 'ceph', realm_name: 'realm1', zonegroup_name: 'zg1-realm1', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts index faf382b78028e..143f6a0bab564 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts @@ -10,6 +10,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { of } from 'rxjs'; import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service'; import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; +import { USER } from '~/app/shared/constants/app.constants'; class MultisiteServiceMock { createEditSyncPipe = jest.fn().mockReturnValue(of(null)); @@ -113,7 +114,7 @@ describe('RgwMultisiteSyncPipeModalComponent', () => { id: 'pipi1', params: { dest: {}, - mode: 'user', + mode: USER, priority: 0, source: { filter: { tags: [] } }, user: 'dashboard' @@ -130,7 +131,7 @@ describe('RgwMultisiteSyncPipeModalComponent', () => { expect(putDataSpy).toHaveBeenCalled(); expect(putDataSpy).toHaveBeenCalledWith({ ...component.pipeForm.getRawValue(), - mode: 'user', + mode: USER, user: 'dashboard' }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-overview-dashboard/rgw-overview-dashboard.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-overview-dashboard/rgw-overview-dashboard.component.spec.ts index 03077cd47a8b5..de135658842f9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-overview-dashboard/rgw-overview-dashboard.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-overview-dashboard/rgw-overview-dashboard.component.spec.ts @@ -16,6 +16,7 @@ import { SharedModule } from '~/app/shared/shared.module'; import { ToastrModule } from 'ngx-toastr'; import { CommonModule } from '@angular/common'; import { ActivatedRoute } from '@angular/router'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; describe('RgwOverviewDashboardComponent', () => { let component: RgwOverviewDashboardComponent; @@ -36,7 +37,7 @@ describe('RgwOverviewDashboardComponent', () => { const daemon: RgwDaemon = { id: '8000', service_map_id: '4803', - version: 'ceph version', + version: VERSION_PREFIX, server_hostname: 'ceph', realm_name: 'realm1', zonegroup_name: 'zg1-realm1', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit-details/rgw-rate-limit-details.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit-details/rgw-rate-limit-details.component.spec.ts index cc7256d9991a7..e1ae67bbab538 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit-details/rgw-rate-limit-details.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit-details/rgw-rate-limit-details.component.spec.ts @@ -3,6 +3,7 @@ import { RgwRateLimitDetailsComponent } from './rgw-rate-limit-details.component import { ComponentFixture, TestBed } from '@angular/core/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { configureTestBed } from '~/testing/unit-test-helper'; +import { USER } from '~/app/shared/constants/app.constants'; describe('RgwRateLimitDetailsComponent', () => { let component: RgwRateLimitDetailsComponent; @@ -15,7 +16,7 @@ describe('RgwRateLimitDetailsComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(RgwRateLimitDetailsComponent); component = fixture.componentInstance; - component.type = 'user'; + component.type = USER; component.rateLimitConfig = { enabled: true, max_read_bytes: 987648, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit/rgw-rate-limit.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit/rgw-rate-limit.component.ts index 2cc291ef9a084..8281a9335accd 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit/rgw-rate-limit.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit/rgw-rate-limit.component.ts @@ -10,6 +10,7 @@ import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service'; import _ from 'lodash'; import { NotificationService } from '~/app/shared/services/notification.service'; import { NotificationType } from '~/app/shared/enum/notification-type.enum'; +import { USER } from '~/app/shared/constants/app.constants'; @Component({ selector: 'cd-rgw-rate-limit', @@ -45,7 +46,7 @@ export class RgwRateLimitComponent implements OnInit, AfterViewInit { ngOnInit(): void { // get the global rate Limit - if (this.type === 'user') { + if (this.type === USER) { this.rgwUserService.getGlobalUserRateLimit().subscribe( (data: GlobalRateLimitConfig) => { if (data && data.user_ratelimit !== undefined) { @@ -158,7 +159,7 @@ export class RgwRateLimitComponent implements OnInit, AfterViewInit { * on load for user and bucket */ private getRateLimitFormValues() { - if (this.type === 'user') { + if (this.type === USER) { this.rgwUserService.getUserRateLimit(this.id).subscribe( (resp: GlobalRateLimitConfig) => { this.populateFormValues(resp.user_ratelimit); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts index f95134494d991..736d61ff8f28b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts @@ -14,6 +14,7 @@ import { CdTableAction } from '~/app/shared/models/cd-table-action'; import { Permissions } from '~/app/shared/models/permissions'; import { RgwRateLimitConfig } from '../models/rgw-rate-limit'; import { ModalCdsService } from '~/app/shared/services/modal-cds.service'; +import { USER } from '~/app/shared/constants/app.constants'; @Component({ selector: 'cd-rgw-user-details', @@ -113,7 +114,7 @@ export class RgwUserDetailsComponent implements OnChanges, OnInit { }); } - this.keys = _.sortBy(this.keys, 'user'); + this.keys = _.sortBy(this.keys, USER); } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts index 915bd38e9ed95..95aff3b517370 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts @@ -24,6 +24,7 @@ import { RgwRateLimitComponent } from '../rgw-rate-limit/rgw-rate-limit.componen import { By } from '@angular/platform-browser'; import { CheckboxModule, NumberModule, SelectModule } from 'carbon-components-angular'; import { LoadingStatus } from '~/app/shared/forms/cd-form'; +import { USER } from '~/app/shared/constants/app.constants'; describe('RgwUserFormComponent', () => { let component: RgwUserFormComponent; @@ -580,7 +581,7 @@ describe('RgwUserFormComponent', () => { // Assertions expect(result).toEqual({ - quota_type: 'user', + quota_type: USER, enabled: true, max_size_kb: -1, max_objects: -1 @@ -604,7 +605,7 @@ describe('RgwUserFormComponent', () => { const result = component._getUserQuotaArgs(); expect(toBytesSpy).toHaveBeenCalledWith(2048); expect(result).toEqual({ - quota_type: 'user', + quota_type: USER, enabled: true, max_size_kb: '2048', // Expect the converted KB value max_objects: -1 @@ -624,7 +625,7 @@ describe('RgwUserFormComponent', () => { const result = component._getUserQuotaArgs(); expect(result).toEqual({ - quota_type: 'user', + quota_type: USER, enabled: true, max_size_kb: -1, max_objects: 1000 diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts index a46a3c5cc3f00..8ad1d896ea868 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts @@ -6,7 +6,7 @@ import _ from 'lodash'; import { concat as observableConcat, forkJoin as observableForkJoin, Observable } from 'rxjs'; import { RgwUserService } from '~/app/shared/api/rgw-user.service'; -import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, URLVerbs, USER } from '~/app/shared/constants/app.constants'; import { Icons } from '~/app/shared/enum/icons.enum'; import { NotificationType } from '~/app/shared/enum/notification-type.enum'; import { CdForm } from '~/app/shared/forms/cd-form'; @@ -229,7 +229,7 @@ export class RgwUserFormComponent extends CdForm implements OnInit { break; } // Map the quota values. - ['user', 'bucket'].forEach((type) => { + [USER, 'bucket'].forEach((type) => { const quota = resp[1][type + '_quota']; value[type + '_quota_enabled'] = quota.enabled; if (quota.max_size < 0) { @@ -804,7 +804,7 @@ export class RgwUserFormComponent extends CdForm implements OnInit { */ _getUserQuotaArgs(): Record { const result = { - quota_type: 'user', + quota_type: USER, enabled: this.userForm.getValue('user_quota_enabled'), max_size_kb: -1, max_objects: -1 diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.spec.ts index b15e40a24e271..f115f07f43bc3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.spec.ts @@ -11,6 +11,7 @@ import { AUTHMODE } from '../smb.model'; import { FOO_USERSGROUPS } from '../smb-usersgroups-form/smb-usersgroups-form.component.spec'; import { of } from 'rxjs'; import { By } from '@angular/platform-browser'; +import { USER } from '~/app/shared/constants/app.constants'; describe('SmbClusterFormComponent', () => { let component: SmbClusterFormComponent; @@ -73,7 +74,7 @@ describe('SmbClusterFormComponent', () => { it('should change the form when authmode is changed', () => { const authModeControl = component.smbForm.get('auth_mode'); - authModeControl?.setValue('user'); + authModeControl?.setValue(USER); component.onAuthModeChange(); fixture.detectChanges(); const joinSourcesControl = component.smbForm.get('joinSources') as FormArray; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-join-auth-form/smb-join-auth-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-join-auth-form/smb-join-auth-form.component.spec.ts index 1db85d9993ff7..35cbbc6bf5a8b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-join-auth-form/smb-join-auth-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-join-auth-form/smb-join-auth-form.component.spec.ts @@ -10,11 +10,12 @@ import { ReactiveFormsModule } from '@angular/forms'; import { SmbService } from '~/app/shared/api/smb.service'; import { JOIN_AUTH_RESOURCE } from '../smb.model'; import { of } from 'rxjs'; +import { USER } from '~/app/shared/constants/app.constants'; export const FOO_JOIN_AUTH = { auth_id: 'foo', auth: { - username: 'user', + username: USER, password: 'pass' }, resource_type: JOIN_AUTH_RESOURCE @@ -54,7 +55,7 @@ describe('SmbJoinAuthFormComponent', () => { it('should submit the form', () => { component.form.controls['authId'].setValue('foo'); - component.form.controls['username'].setValue('user'); + component.form.controls['username'].setValue(USER); component.form.controls['password'].setValue('pass'); component.form.controls['linkedToCluster'].setValue(undefined); @@ -75,7 +76,7 @@ describe('SmbJoinAuthFormComponent', () => { expect(getJoinAuth).toHaveBeenCalled(); expect(component.form.getRawValue()).toEqual({ authId: 'foo', - username: 'user', + username: USER, password: 'pass', linkedToCluster: undefined }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-usersgroups-form/smb-usersgroups-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-usersgroups-form/smb-usersgroups-form.component.spec.ts index 39c9fe51cf664..8cfc7b39ab30d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-usersgroups-form/smb-usersgroups-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-usersgroups-form/smb-usersgroups-form.component.spec.ts @@ -10,13 +10,14 @@ import { SharedModule } from '~/app/shared/shared.module'; import { SmbService } from '~/app/shared/api/smb.service'; import { USERSGROUPS_RESOURCE } from '../smb.model'; import { of } from 'rxjs'; +import { USER } from '~/app/shared/constants/app.constants'; export const FOO_USERSGROUPS = { users_groups_id: 'foo', values: { users: [ { - name: 'user', + name: USER, password: 'pass' } ], @@ -65,7 +66,7 @@ describe('SmbUsersgroupsFormComponent', () => { const user = component.users.controls[0] as FormGroup; component.form.controls['usersGroupsId'].setValue('foo'); component.form.controls['linkedToCluster'].setValue(undefined); - user.controls['name'].setValue('user'); + user.controls['name'].setValue(USER); user.controls['password'].setValue('pass'); component.addGroup(); const group = component.groups.controls[0] as FormGroup; @@ -90,7 +91,7 @@ describe('SmbUsersgroupsFormComponent', () => { usersGroupsId: 'foo', users: [ { - name: 'user', + name: USER, password: 'pass' } ], diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb.model.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb.model.ts index 97b123fd86b24..99244e9ec1e05 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb.model.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb.model.ts @@ -1,4 +1,5 @@ import { CephServicePlacement } from '~/app/shared/models/service.interface'; +import { USER } from '~/app/shared/constants/app.constants'; export interface SMBCluster { resource_type: typeof CLUSTER_RESOURCE; @@ -32,7 +33,7 @@ interface SMBCephfs { interface SMBShareLoginControl { name: string; access: 'read' | 'read-write' | 'none' | 'admin'; - category?: 'user' | 'group'; + category?: typeof USER | 'group'; } export interface Filesystem { @@ -67,7 +68,7 @@ export const RESOURCE = { }; export const AUTHMODE = { - User: 'user', + User: USER, ActiveDirectory: 'active-directory' }; @@ -100,7 +101,7 @@ interface SMBCephfs { interface SMBShareLoginControl { name: string; access: 'read' | 'read-write' | 'none' | 'admin'; - category?: 'user' | 'group'; + category?: typeof USER | 'group'; } export interface SMBJoinAuth { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts index 7eb708d6e7953..df39eaf025924 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts @@ -16,6 +16,7 @@ import { SharedModule } from '~/app/shared/shared.module'; import { configureTestBed, FormHelper } from '~/testing/unit-test-helper'; import { RoleFormComponent } from './role-form.component'; import { RoleFormModel } from './role-form.model'; +import { USER } from '~/app/shared/constants/app.constants'; describe('RoleFormComponent', () => { let component: RoleFormComponent; @@ -107,7 +108,7 @@ describe('RoleFormComponent', () => { description: 'Role 1', scopes_permissions: { osd: ['read', 'create'] } }; - const scopes = ['osd', 'user']; + const scopes = ['osd', USER]; beforeEach(() => { formHelper = new FormHelper(form); spyOn(roleService, 'get').and.callFake(() => of(role)); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts index 009d4c193e420..de25970505704 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts @@ -13,7 +13,7 @@ import { SettingsService } from '~/app/shared/api/settings.service'; import { UserService } from '~/app/shared/api/user.service'; import { ConfirmationModalComponent } from '~/app/shared/components/confirmation-modal/confirmation-modal.component'; import { SelectMessages } from '~/app/shared/components/select/select-messages.model'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { Icons } from '~/app/shared/enum/icons.enum'; import { NotificationType } from '~/app/shared/enum/notification-type.enum'; import { CdForm } from '~/app/shared/forms/cd-form'; @@ -268,8 +268,8 @@ export class UserFormComponent extends CdForm implements OnInit { private hasUserReadUpdatePermissions(roles: Array = []) { for (const role of this.allRoles) { - if (roles.indexOf(role.name) !== -1 && role.scopes_permissions['user']) { - const userPermissions = role.scopes_permissions['user']; + if (roles.indexOf(role.name) !== -1 && role.scopes_permissions[USER]) { + const userPermissions = role.scopes_permissions[USER]; return ['read', 'update'].every((permission) => { return userPermissions.indexOf(permission) !== -1; }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts index 18c07cb445e29..97ef4232fa764 100755 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts @@ -5,7 +5,7 @@ import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { SettingsService } from '~/app/shared/api/settings.service'; import { UserService } from '~/app/shared/api/user.service'; import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component'; -import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; +import { ActionLabelsI18n, USER } from '~/app/shared/constants/app.constants'; import { CellTemplate } from '~/app/shared/enum/cell-template.enum'; import { DeletionImpact } from '~/app/shared/enum/delete-confirmation-modal-impact.enum'; import { Icons } from '~/app/shared/enum/icons.enum'; @@ -176,7 +176,7 @@ export class UserListComponent implements OnInit { this.modalRef = this.modalService.show(DeleteConfirmationModalComponent, { impact: DeletionImpact.high, - itemDescription: 'User', + itemDescription: USER, itemNames: [username], submitAction: () => this.deleteUser(username) }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.spec.ts index 74ca78434e6fb..c05b430790a74 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.spec.ts @@ -9,11 +9,12 @@ import { SharedModule } from '~/app/shared/shared.module'; import { environment } from '~/environments/environment'; import { configureTestBed } from '~/testing/unit-test-helper'; import { AboutComponent } from './about.component'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; export class SummaryServiceMock { summaryDataSource = new BehaviorSubject({ version: - 'ceph version 14.0.0-855-gb8193bb4cd ' + + `${VERSION_PREFIX} 14.0.0-855-gb8193bb4cd ` + '(b8193bb4cda16ccc5b028c3e1df62bc72350a15d) nautilus (dev)', mgr_host: 'http://localhost:11000/' }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts index b276da84ff6af..7b7fe9690e360 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts @@ -17,6 +17,7 @@ import { import { NotificationService } from '~/app/shared/services/notification.service'; import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service'; import { SummaryService } from '~/app/shared/services/summary.service'; +import { USER } from '~/app/shared/constants/app.constants'; @Component({ selector: 'cd-navigation', @@ -74,7 +75,7 @@ export class NavigationComponent implements OnInit, OnDestroy { Object.keys(clustersConfig).forEach((clusterKey: string) => { const clusterDetailsList = clustersConfig[clusterKey]; clusterDetailsList.forEach((clusterDetails: MultiCluster) => { - const clusterUser = clusterDetails['user']; + const clusterUser = clusterDetails[USER]; const clusterUrl = clusterDetails['url']; const clusterUniqueKey = `${clusterUrl}-${clusterUser}`; this.clustersMap.set(clusterUniqueKey, clusterDetails); @@ -169,10 +170,10 @@ export class NavigationComponent implements OnInit, OnDestroy { if (value['cluster_alias'] === 'local-cluster') { localStorage.setItem('cluster_api_url', ''); } else { - localStorage.setItem('current_cluster_name', `${value['name']}-${value['user']}`); + localStorage.setItem('current_cluster_name', `${value['name']}-${value[USER]}`); localStorage.setItem('cluster_api_url', value['url']); } - this.selectedCluster = this.clustersMap.get(`${value['url']}-${value['user']}`) || {}; + this.selectedCluster = this.clustersMap.get(`${value['url']}-${value[USER]}`) || {}; const clustersConfig = resp['config']; if (clustersConfig && typeof clustersConfig === 'object') { Object.keys(clustersConfig).forEach((clusterKey: string) => { @@ -181,11 +182,11 @@ export class NavigationComponent implements OnInit, OnDestroy { clusterDetailsList.forEach((clusterDetails: any) => { const clusterName = clusterDetails['name']; const clusterToken = clusterDetails['token']; - const clusterUser = clusterDetails['user']; + const clusterUser = clusterDetails[USER]; if ( - clusterName === this.selectedCluster['name'] && - clusterUser === this.selectedCluster['user'] && + clusterName === this.selectedCluster[USER] && + clusterUser === this.selectedCluster[USER] && clusterDetails['cluster_alias'] !== 'local-cluster' ) { this.cookieService.setToken(`${clusterName}-${clusterUser}`, clusterToken); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts index c32f0ea05fc96..5204064a8f2fe 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts @@ -6,6 +6,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { configureTestBed } from '~/testing/unit-test-helper'; import { AuthStorageService } from '../services/auth-storage.service'; import { AuthService } from './auth.service'; +import { LocalStorage } from '~/app/shared/enum/local-storage-enum'; describe('AuthService', () => { let service: AuthService; @@ -40,7 +41,7 @@ describe('AuthService', () => { expect(req.request.body).toEqual(fakeCredentials); req.flush(fakeResponse); tick(); - expect(localStorage.getItem('dashboard_username')).toBe('foo'); + expect(localStorage.getItem(LocalStorage.DASHBOARD_USRENAME)).toBe('foo'); })); it('should logout and remove the user', () => { @@ -51,7 +52,7 @@ describe('AuthService', () => { const req = httpTesting.expectOne('api/auth/logout'); expect(req.request.method).toBe('POST'); req.flush({ redirect_url: '#/login' }); - expect(localStorage.getItem('dashboard_username')).toBe(null); + expect(localStorage.getItem(LocalStorage.DASHBOARD_USRENAME)).toBe(null); expect(router.navigate).toBeCalledTimes(1); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts index 02877816102a5..bfa651fa1e2bf 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { RgwRealm, RgwZone, RgwZonegroup } from '~/app/ceph/rgw/models/rgw-multisite'; import { Icons } from '../enum/icons.enum'; +import { USER } from '~/app/shared/constants/app.constants'; @Injectable({ providedIn: 'root' @@ -128,7 +129,7 @@ export class RgwZoneService { const secret_key = zoneInfo[0].system_key['secret_key']; nodes['access_key'] = access_key ? access_key : ''; nodes['secret_key'] = secret_key ? secret_key : ''; - nodes['user'] = access_key && access_key !== '' ? true : false; + nodes[USER] = access_key && access_key !== '' ? true : false; } if (nodes['access_key'] === '' || nodes['access_key'] === 'null') { nodes['show_warning'] = true; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts index 0d1d92114e057..53b020ad5b023 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts @@ -13,6 +13,7 @@ import { NotificationService } from '../services/notification.service'; import { ToastrModule } from 'ngx-toastr'; import { NotificationType } from '../enum/notification-type.enum'; import { SharedModule } from '../shared.module'; +import { USER } from '~/app/shared/constants/app.constants'; describe('SmbService', () => { let service: SmbService; @@ -165,7 +166,7 @@ describe('SmbService', () => { resource_type: JOIN_AUTH_RESOURCE, auth_id: 'foo', auth: { - username: 'user', + username: USER, password: 'pass' }, linked_to_cluster: '' @@ -188,7 +189,7 @@ describe('SmbService', () => { values: { users: [ { - name: 'user', + name: USER, password: 'pass' } ], diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.spec.ts index 5acd490cfe764..502567042efb4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.spec.ts @@ -4,11 +4,12 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/ import { TestBed } from '@angular/core/testing'; import { SummaryService } from '../services/summary.service'; import { BehaviorSubject } from 'rxjs'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; export class SummaryServiceMock { summaryDataSource = new BehaviorSubject({ version: - 'ceph version 18.1.3-12222-gcd0cd7cb ' + + `${VERSION_PREFIX} 18.1.3-12222-gcd0cd7cb ` + '(b8193bb4cda16ccc5b028c3e1df62bc72350a15d) reef (dev)' }); summaryData$ = this.summaryDataSource.asObservable(); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.ts index 3a2e6dc0fad3d..cd44a83f48ba6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.ts @@ -8,6 +8,7 @@ import { Observable } from 'rxjs'; import { UpgradeStartModalComponent } from '~/app/ceph/cluster/upgrade/upgrade-form/upgrade-start-modal.component'; import { ModalService } from '../services/modal.service'; import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; const CACHE_SIZE = 1; @@ -54,7 +55,7 @@ export class UpgradeService extends ApiClient { versionAvailableForUpgrades(upgradeInfo: UpgradeInfoInterface): UpgradeInfoInterface { let version = ''; this.summaryService.subscribe((summary) => { - version = summary.version.replace('ceph version ', '').split('-')[0]; + version = summary.version.replace(`${VERSION_PREFIX}`, '').split('-')[0]; }); const upgradableVersions = upgradeInfo.versions.filter((targetVersion) => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.spec.ts index 3e1f1f7ca2dee..3498552451b7a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.spec.ts @@ -1,4 +1,5 @@ import { CephReleaseNamePipe } from './ceph-release-name.pipe'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; describe('CephReleaseNamePipe', () => { const pipe = new CephReleaseNamePipe(); @@ -8,16 +9,14 @@ describe('CephReleaseNamePipe', () => { }); it('recognizes a stable release', () => { - const value = - 'ceph version 13.2.1 \ - (5533ecdc0fda920179d7ad84e0aa65a127b20d77) mimic (stable)'; + const value = `${VERSION_PREFIX} 13.2.1 \ + (5533ecdc0fda920179d7ad84e0aa65a127b20d77) mimic (stable)`; expect(pipe.transform(value)).toBe('mimic'); }); it('recognizes a development release as the main branch', () => { - const value = - 'ceph version 13.1.0-534-g23d3751b89 \ - (23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) nautilus (dev)'; + const value = `${VERSION_PREFIX} 13.1.0-534-g23d3751b89 \ + (23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) nautilus (dev)`; expect(pipe.transform(value)).toBe('main'); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.ts index c63c794a9188b..154e673f980a9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.ts @@ -1,4 +1,5 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; @Pipe({ name: 'cephReleaseName' @@ -7,7 +8,9 @@ export class CephReleaseNamePipe implements PipeTransform { transform(value: any): any { // Expect "ceph version 13.1.0-419-g251e2515b5 // (251e2515b563856349498c6caf34e7a282f62937) nautilus (dev)" - const result = /ceph version\s+[^ ]+\s+\(.+\)\s+(.+)\s+\((.+)\)/.exec(value); + const result = new RegExp(`${VERSION_PREFIX}\\s+[^ ]+\\s+\\(.+\\)\\s+(.+)\\s+\\((.+)\\)`).exec( + value + ); if (result) { if (result[2] === 'dev') { // Assume this is actually main diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts index 0242839df07fb..53f3cccf9a6ce 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts @@ -1,4 +1,5 @@ import { CephShortVersionPipe } from './ceph-short-version.pipe'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; describe('CephShortVersionPipe', () => { const pipe = new CephShortVersionPipe(); @@ -8,9 +9,8 @@ describe('CephShortVersionPipe', () => { }); it('transforms with correct version format', () => { - const value = - 'ceph version 13.1.0-534-g23d3751b89 \ - (23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) nautilus (dev)'; + const value = `${VERSION_PREFIX} 13.1.0-534-g23d3751b89 \ + (23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) nautilus (dev)`; expect(pipe.transform(value)).toBe('13.1.0-534-g23d3751b89'); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.ts index 03e75dfb38592..d69c5e8dd33aa 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.ts @@ -1,4 +1,5 @@ import { Pipe, PipeTransform } from '@angular/core'; +import { VERSION_PREFIX } from '~/app/shared/constants/app.constants'; @Pipe({ name: 'cephShortVersion' @@ -6,7 +7,7 @@ import { Pipe, PipeTransform } from '@angular/core'; export class CephShortVersionPipe implements PipeTransform { transform(value: any): any { // Expect "ceph version 1.2.3-g9asdasd (as98d7a0s8d7)" - const result = /ceph version\s+([^ ]+)\s+\(.+\)/.exec(value); + const result = new RegExp(`${VERSION_PREFIX}\\s+([^ ]+)\\s+\\(.+\\)`).exec(value); if (result) { // Return the "1.2.3-g9asdasd" part return result[1]; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.spec.ts index f202c095f4791..76e3290ed9080 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.spec.ts @@ -1,4 +1,5 @@ import { AuthStorageService } from './auth-storage.service'; +import { LocalStorage } from '~/app/shared/enum/local-storage-enum'; describe('AuthStorageService', () => { let service: AuthStorageService; @@ -14,13 +15,13 @@ describe('AuthStorageService', () => { it('should store username', () => { service.set(username, ''); - expect(localStorage.getItem('dashboard_username')).toBe(username); + expect(localStorage.getItem(LocalStorage.DASHBOARD_USRENAME)).toBe(username); }); it('should remove username', () => { service.set(username, ''); service.remove(); - expect(localStorage.getItem('dashboard_username')).toBe(null); + expect(localStorage.getItem(LocalStorage.DASHBOARD_USRENAME)).toBe(null); }); it('should be loggedIn', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.ts index 15e21f9ed540d..02c4feede3bc9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.ts @@ -1,9 +1,7 @@ import { Injectable } from '@angular/core'; - import { BehaviorSubject } from 'rxjs'; - import { Permissions } from '../models/permissions'; - +import { LocalStorage } from '~/app/shared/enum/local-storage-enum'; @Injectable({ providedIn: 'root' }) @@ -18,7 +16,7 @@ export class AuthStorageService { pwdExpirationDate: number = null, pwdUpdateRequired: boolean = false ) { - localStorage.setItem('dashboard_username', username); + localStorage.setItem(LocalStorage.DASHBOARD_USRENAME, username); localStorage.setItem('dashboard_permissions', JSON.stringify(new Permissions(permissions))); localStorage.setItem('user_pwd_expiration_date', String(pwdExpirationDate)); localStorage.setItem('user_pwd_update_required', String(pwdUpdateRequired)); @@ -26,17 +24,17 @@ export class AuthStorageService { } remove() { - localStorage.removeItem('dashboard_username'); + localStorage.removeItem(LocalStorage.DASHBOARD_USRENAME); localStorage.removeItem('user_pwd_expiration_data'); localStorage.removeItem('user_pwd_update_required'); } isLoggedIn() { - return localStorage.getItem('dashboard_username') !== null; + return localStorage.getItem(LocalStorage.DASHBOARD_USRENAME) !== null; } getUsername() { - return localStorage.getItem('dashboard_username'); + return localStorage.getItem(LocalStorage.DASHBOARD_USRENAME); } getPermissions(): Permissions { -- 2.39.5