]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: remove hardcoded strings in About component 63531/head 66034/head
authorprik73 <prinovac@gmail.com>
Tue, 27 May 2025 19:04:37 +0000 (00:34 +0530)
committerAfreen Misbah <afreen@ibm.com>
Wed, 22 Oct 2025 18:41:49 +0000 (00:11 +0530)
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 <prinovac@gmail.com>
Signed-off-by: Afreen Misbah <afreen@ibm.com>
42 files changed:
src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-details/iscsi-target-details.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-form/iscsi-target-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/upgrade/upgrade.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard-v3/dashboard/dashboard-v3.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-multisite-sync-pipe-modal/rgw-multisite-sync-pipe-modal.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-overview-dashboard/rgw-overview-dashboard.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit-details/rgw-rate-limit-details.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-rate-limit/rgw-rate-limit.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-details/rgw-user-details.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-form/rgw-user-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-cluster-form/smb-cluster-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-join-auth-form/smb-join-auth-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb-usersgroups-form/smb-usersgroups-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/smb/smb.model.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-form/role-form.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-form/user-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/user-list/user-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/about/about.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-zone.service.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/smb.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/upgrade.service.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-release-name.pipe.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/auth-storage.service.ts

index f437ebbdc554c1b32e4750127b9541584a49ea35..2cf450fa6db1cc14b4f673e4ea5c9858fb736c2d 100644 (file)
@@ -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);
index 1c2c007055b5f4cabdfa6da399b3382adf4a60e8..13e8ff23e40abc13b152a1078b17e976d7ed69e7 100644 (file)
@@ -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' }
index 4d985093172bb08cd7442b4fc386c6b34a8eedcc..7dcd81843d6dc622494f75b34507966028298c74 100644 (file)
@@ -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,
index 0f540f18e9b4a4c48401f6cb18c167cef0198ab6..8ef136617def5592c6ae7b6b85dc0f36717c35b1 100644 (file)
@@ -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');
index d20525fdd43d98bad3bc4566ea0ff04278a018ff..259327822a327f7e4e3d7c44da5f6fc063334cc2 100644 (file)
@@ -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')
       ]
index 21caa0b2e7035d22d897cb657eaf63b1646b36c3..0d5de9a72ae9c4e8700e0293bacae8da6e504672 100644 (file)
@@ -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')
index 924feb6cf4331a1cdc9e6267233fdbdc2f486026..f42a1f7ede91e337655830066d358f98fc5a3365 100644 (file)
@@ -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,
index 481cf9ddce6516111547393f23237d50b7e2b1b8..2c95c5cc4c6d44fc2d38668d8d161bb8e9c0cffd 100644 (file)
@@ -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]));
   }
 
index 02579680b852b75d4dc43d2b1bb50b22632649c0..a843a34cc419111508d03661d59ca490049dd444 100644 (file)
@@ -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) {
index bf1ac3ddf43cad40be945d33428507ed358391fe..c6bd579489b2b1c914c858da3d06479571c944ef 100644 (file)
@@ -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
index 8c3e1c9eb28134a96886f0ab3ff98f7a5bead3c0..2ff6fe2ae69381002ad7372071d93747395c3338 100644 (file)
@@ -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();
index 80ae0c4aadacbd1a1d0c8cac01b560145efc1a77..d71b440802e64d87c579c6bdc1c592f3086fe80c 100644 (file)
@@ -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')
index 1f168561cd4c8efd58061e400266ecec9fa8b42a..0bb9a79501cb2a95dcb76696e2092c65a835f208 100644 (file)
@@ -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();
index b11b748f7f2b6d748d919cee4d5b7a4246669489..2b8fee828c9f3b7839c4ec7d326077d88d8d5165 100644 (file)
@@ -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(' ');
       })
index 85aa96be10dffbd4a5e6dae2080b4771c74dfd18..d8ffa7df03a23315e6d0ad54c4b2d4c0ad143fc3 100644 (file)
@@ -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',
index faf382b78028e34529b72a8fb2fd2597dd3d9beb..143f6a0bab564dadff0ed81d2e781dd9d5b41b68 100644 (file)
@@ -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'
     });
   });
index 03077cd47a8b50fff1823792148de3430fbcdbf1..de135658842f9250e0880c11636a89a061170d2e 100644 (file)
@@ -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',
index cc7256d9991a77bb97742fc1589c746b625002cb..e1ae67bbab538f986502ab2cb015aad6ba184bd3 100644 (file)
@@ -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,
index 2cc291ef9a084d499912fed4f498d536ac97b286..8281a9335accdfbf9372bda25fc19a684db89a9d 100644 (file)
@@ -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);
index f95134494d9912c2c2c3f0ed72b0086d4cc700e0..736d61ff8f28b1a918db9cfc278d5236f99ecbf2 100644 (file)
@@ -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);
     }
   }
 
index 915bd38e9ed95b5a240791173715aae1d8ab3912..95aff3b5173705c1f8e68596d97913e36adac95f 100644 (file)
@@ -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
index a46a3c5cc3f00abe4b7366973b7c674f53d5c913..8ad1d896ea86848692b22b8967f00074fadee33d 100644 (file)
@@ -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<string, any> {
     const result = {
-      quota_type: 'user',
+      quota_type: USER,
       enabled: this.userForm.getValue('user_quota_enabled'),
       max_size_kb: -1,
       max_objects: -1
index b15e40a24e2712dab64deb7d1533ec960897d247..f115f07f43bc3ad48ed7ee33b2ad996686ba2b42 100644 (file)
@@ -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;
index 1db85d9993ff7bfb58c9f541bd68689d121a93b4..35cbbc6bf5a8b4416e5c56bce4605013a5eede65 100644 (file)
@@ -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
       });
index 39c9fe51cf664822c2bbcf644277bcbc6eda502b..8cfc7b39ab30d14ff3961d770c690922c36a60cd 100644 (file)
@@ -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'
           }
         ],
index 97b123fd86b24ac57dc23d2d8daf589fbfed37bd..99244e9ec1e058788e3d616d956ed5178d90b524 100644 (file)
@@ -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 {
index 7eb708d6e7953608774922f7f4a3daaf5e2b29c9..df39eaf025924f23a5880a38004476bb0e33201a 100644 (file)
@@ -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));
index 009d4c193e420a82e9ff05394bd6a2e5dcb467a5..de259705057041dfddef14b024338223e784d48f 100644 (file)
@@ -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<string> = []) {
     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;
         });
index 18c07cb445e2920936a51b8e57b07344d1743ece..97ef4232fa764a7ba6e319103b1954e5bace072d 100755 (executable)
@@ -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)
     });
index 74ca78434e6fbc41bfcf5c01c3dd3ec367baadd1..c05b430790a74c47c9b743dd6614a838e74ea865 100644 (file)
@@ -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/'
   });
index b276da84ff6af3a90c6bf73f14a3c191d97261c2..7b7fe9690e360671f3563da1240b4815296fd218 100644 (file)
@@ -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);
index c32f0ea05fc9638ff060dbae35b4621ce386ebca..5204064a8f2fe3511cfdb347286da885359350bb 100644 (file)
@@ -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);
   });
 });
index 02877816102a5aa0e97f8bc48905ca1e42b1a669..bfa651fa1e2bff8b6a4c98ad891d92e38454d870 100644 (file)
@@ -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;
index 0d1d92114e057139b62c6b562f3bad79249ba7e6..53b020ad5b023f8754a2e9a5388d624d2e6aac44 100644 (file)
@@ -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'
           }
         ],
index 5acd490cfe764ac2fff2aa68698ff5fb4a0c23cb..502567042efb4877920894ef5e8915e48694119d 100644 (file)
@@ -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();
index 3a2e6dc0fad3dda2f5699598e298b4663f4c8c02..cd44a83f48ba6fdeb73d1d28dec2e16546ace24a 100644 (file)
@@ -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) => {
index 3e1f1f7ca2deea0fd3634d944b757e90df7cd7f4..3498552451b7a40d6db3b0b34ea9020e072aa5a2 100644 (file)
@@ -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');
   });
 
index c63c794a9188b2bf2b7678cb3face3a8be30051d..154e673f980a97fee73b8a779cdc334f5d16ed85 100644 (file)
@@ -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
index 0242839df07fbd8a157f1113fea315de95e9f29b..53f3cccf9a6ceff00090bb7a53f00efc65618962 100644 (file)
@@ -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');
   });
 
index 03e75dfb3859280173cda021c229c6e1d5d388a6..d69c5e8dd33aab730f67ed8db830b3ecb2c2dbe8 100644 (file)
@@ -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];
index f202c095f4791015181a2e2440b999b0dfe21088..76e3290ed908032822bacb878cb8d88357586cd0 100644 (file)
@@ -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', () => {
index 15e21f9ed540dc7c8e5e307121eeba277b50b289..02c4feede3bc95aa38d53a35ee280a12ddffd5e1 100644 (file)
@@ -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 {