Skip to content

Commit

Permalink
Disable versioning checkbox after bucket creation if it is already en…
Browse files Browse the repository at this point in the history
…abled

This is to prevent the user from disabling the versioning because right now you can go from:

- unversioned to versioned any time.
- versioned -> unversioned is not supported in S3.
- versioned -> suspended versioned is not supported by us.

Fixes: https://github.com/aquarist-labs/s3gw/issues/672

References:
- https://github.com/aquarist-labs/s3gw/issues/534
- https://github.com/aquarist-labs/s3gw/pull/497

Signed-off-by: Volker Theile <vtheile@suse.com>
  • Loading branch information
votdev committed Aug 17, 2023
1 parent 9b9ef81 commit d48b130
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.20.0]

### Changed

- Disable versioning checkbox after bucket creation (gh#aquarist-labs/s3gw#672).

## [0.19.0]

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
fields: []
};

private readonly editing: boolean;
private listIds$: Observable<string[]>;
private ownerOptions: Record<any, string> = {};

Expand All @@ -41,7 +42,8 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
private adminOpsUserService: AdminOpsUserService,
private router: Router
) {
this.createForm(this.router.url.startsWith(`/admin/buckets/edit`));
this.editing = this.router.url.startsWith(`/admin/buckets/edit`);
this.createForm();
(this.listIds$ = this.adminOpsUserService.listIds()).subscribe({
next: (users: string[]) => {
// Update the options of the 'owner' field.
Expand Down Expand Up @@ -89,6 +91,9 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
if (bucket.retention_enabled) {
this.form.getControl('retention_enabled')?.disable();
}
if (this.editing && bucket.versioning_enabled) {
this.form.getControl('versioning_enabled')?.disable();
}
},
error: (err) => {
this.pageStatus = PageStatus.loadingError;
Expand All @@ -104,7 +109,7 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
return !this.form.pristine;
}

private createForm(editing: boolean) {
private createForm() {
this.config = {
buttons: [
{
Expand All @@ -114,9 +119,9 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
},
{
type: 'submit',
text: editing ? TEXT('Update') : TEXT('Create'),
text: this.editing ? TEXT('Update') : TEXT('Create'),
click: () => {
if (editing) {
if (this.editing) {
this.updateBucket();
} else {
this.createBucket();
Expand All @@ -129,16 +134,16 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
type: 'hidden',
name: 'id',
value: '',
submitValue: editing
submitValue: this.editing
},
{
type: 'text',
name: 'bucket',
label: TEXT('Name'),
hint: TEXT('The name of the bucket.'),
value: '',
readonly: editing,
autofocus: !editing,
readonly: this.editing,
autofocus: !this.editing,
validators: {
required: true,
custom: S3gwValidators.bucketName(),
Expand All @@ -151,7 +156,7 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
label: TEXT('Owner'),
hint: TEXT('The owner of the bucket.'),
value: '',
readonly: editing,
readonly: this.editing,
options: this.ownerOptions,
validators: {
required: true
Expand Down Expand Up @@ -216,10 +221,10 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
name: 'object_lock_enabled',
label: TEXT('Enabled'),
hint: TEXT(
'Enable object locking only if you need to prevent objects from being deleted. Can only be enabled while bucket creation.'
'Enable object locking only if you need to prevent objects from being deleted. Can only be enabled during bucket creation.'
),
value: false,
readonly: editing,
readonly: this.editing,
modifiers: [
{
type: 'value',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
fields: []
};

private readonly editing: boolean;

constructor(
private route: ActivatedRoute,
private s3BucketService: S3BucketService,
private router: Router
) {
this.createForm(this.router.url.startsWith(`/buckets/edit`));
this.editing = this.router.url.startsWith(`/buckets/edit`);
this.createForm();
}

ngOnInit(): void {
Expand Down Expand Up @@ -70,6 +73,9 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
if (bucket.RetentionEnabled) {
this.form.getControl('RetentionEnabled')?.disable();
}
if (this.editing && bucket.VersioningEnabled) {
this.form.getControl('VersioningEnabled')?.disable();
}
},
error: (err) => {
this.pageStatus = PageStatus.loadingError;
Expand All @@ -85,7 +91,7 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
return !this.form.pristine;
}

private createForm(editing: boolean) {
private createForm() {
this.config = {
buttons: [
{
Expand All @@ -95,9 +101,9 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
},
{
type: 'submit',
text: editing ? TEXT('Update') : TEXT('Create'),
text: this.editing ? TEXT('Update') : TEXT('Create'),
click: () => {
if (editing) {
if (this.editing) {
this.updateBucket();
} else {
this.createBucket();
Expand All @@ -110,16 +116,16 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
type: 'hidden',
name: 'id',
value: '',
submitValue: editing
submitValue: this.editing
},
{
type: 'text',
name: 'Name',
label: TEXT('Name'),
hint: TEXT('The name of the bucket.'),
value: '',
readonly: editing,
autofocus: !editing,
readonly: this.editing,
autofocus: !this.editing,
validators: {
required: true,
custom: S3gwValidators.bucketName(),
Expand Down Expand Up @@ -154,7 +160,9 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
type: 'checkbox',
name: 'VersioningEnabled',
label: TEXT('Enabled'),
hint: TEXT('Enable versioning for the objects in this bucket.'),
hint: TEXT(
'Enable versioning for the objects in this bucket. Can only be enabled during bucket creation.'
),
value: false,
modifiers: [
{
Expand Down Expand Up @@ -185,10 +193,10 @@ export class BucketFormPageComponent implements OnInit, IsDirty {
name: 'ObjectLockEnabled',
label: TEXT('Enabled'),
hint: TEXT(
'Enable object locking only if you need to prevent objects from being deleted. Can only be enabled while bucket creation.'
'Enable object locking only if you need to prevent objects from being deleted. Can only be enabled during bucket creation.'
),
value: false,
readonly: editing,
readonly: this.editing,
modifiers: [
{
type: 'value',
Expand Down

0 comments on commit d48b130

Please sign in to comment.