From 7805e7a2b6039f74ce175ce5489cdecbc463f015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Thu, 10 Jun 2021 15:23:00 +0200 Subject: [PATCH] mgr/dashboard: bucket details: show lock retention period only in days MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: https://tracker.ceph.com/issues/51164 Signed-off-by: Alfonso Martínez (cherry picked from commit b927dc5bff56be742dc4f8608994f243ab18d2d2) --- .../rgw-bucket-details.component.html | 5 ----- .../rgw-bucket-details/rgw-bucket-details.component.ts | 1 + .../rgw-bucket-form/rgw-bucket-form.component.spec.ts | 5 ----- .../rgw/rgw-bucket-form/rgw-bucket-form.component.ts | 10 +--------- .../src/app/shared/api/rgw-bucket.service.spec.ts | 6 ++++++ .../frontend/src/app/shared/api/rgw-bucket.service.ts | 8 ++++++++ 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html index 310de113c4aac..bf4bdcb08d959 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.html @@ -121,11 +121,6 @@ class="bold">Days {{ selection.lock_retention_period_days }} - - Years - {{ selection.lock_retention_period_years }} - diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.ts index 5ec44bcbd32aa..f9a351367daad 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-details/rgw-bucket-details.component.ts @@ -16,6 +16,7 @@ export class RgwBucketDetailsComponent implements OnChanges { ngOnChanges() { if (this.selection) { this.rgwBucketService.get(this.selection.bid).subscribe((bucket: object) => { + bucket['lock_retention_period_days'] = this.rgwBucketService.getLockDays(bucket); this.selection = bucket; }); } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.spec.ts index 574d807215f2f..72a37309c4eb7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.spec.ts @@ -372,10 +372,5 @@ describe('RgwBucketFormComponent', () => { it('should have valid values [2]', () => { expectValidLockInputs(false, 'Compliance', '2'); }); - - it('should convert retention years to days', () => { - expect(component['getLockDays']({ lock_retention_period_years: 1000 })).toBe(365242); - expect(component['getLockDays']({ lock_retention_period_days: 5 })).toBe(5); - }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.ts index b1e3a4400a704..07160445206d3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-form/rgw-bucket-form.component.ts @@ -132,7 +132,7 @@ export class RgwBucketFormComponent extends CdForm implements OnInit { // the Angular react framework will throw an error if there is no // field for a given key. let value: object = _.pick(bidResp, _.keys(defaults)); - value['lock_retention_period_days'] = this.getLockDays(bidResp); + value['lock_retention_period_days'] = this.rgwBucketService.getLockDays(bidResp); value['placement-target'] = bidResp['placement_rule']; value['versioning'] = bidResp['versioning'] === RgwBucketVersioning.ENABLED; value['mfa-delete'] = bidResp['mfa_delete'] === RgwBucketMfaDelete.ENABLED; @@ -358,12 +358,4 @@ export class RgwBucketFormComponent extends CdForm implements OnInit { getMfaDeleteStatus() { return this.isMfaDeleteEnabled ? RgwBucketMfaDelete.ENABLED : RgwBucketMfaDelete.DISABLED; } - - private getLockDays(bucketData: object): number { - if (bucketData['lock_retention_period_years'] > 0) { - return Math.floor(bucketData['lock_retention_period_years'] * 365.242); - } - - return bucketData['lock_retention_period_days']; - } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.spec.ts index e457c2ab12277..6e3fbf660ca2f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.spec.ts @@ -85,4 +85,10 @@ describe('RgwBucketService', () => { req.flush(['foo', 'bar']); expect(result).toBe(true); }); + + it('should convert lock retention period to days', () => { + expect(service.getLockDays({ lock_retention_period_years: 1000 })).toBe(365242); + expect(service.getLockDays({ lock_retention_period_days: 5 })).toBe(5); + expect(service.getLockDays({})).toBe(0); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts index c1c02629cdd5f..47126f186d19c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts @@ -108,4 +108,12 @@ export class RgwBucketService { }) ); } + + getLockDays(bucketData: object): number { + if (bucketData['lock_retention_period_years'] > 0) { + return Math.floor(bucketData['lock_retention_period_years'] * 365.242); + } + + return bucketData['lock_retention_period_days'] || 0; + } } -- 2.39.5