@@ -16,7 +16,7 @@ import * as xml2js from 'xml2js';
1616import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service' ;
1717import { RgwSiteService } from '~/app/shared/api/rgw-site.service' ;
1818import { RgwUserService } from '~/app/shared/api/rgw-user.service' ;
19- import { ActionLabelsI18n , URLVerbs } from '~/app/shared/constants/app.constants' ;
19+ import { ActionLabelsI18n , AppConstants , URLVerbs } from '~/app/shared/constants/app.constants' ;
2020import { Icons } from '~/app/shared/enum/icons.enum' ;
2121import { NotificationType } from '~/app/shared/enum/notification-type.enum' ;
2222import { CdForm } from '~/app/shared/forms/cd-form' ;
@@ -41,6 +41,8 @@ import { TextAreaXmlFormatterService } from '~/app/shared/services/text-area-xml
4141import { RgwRateLimitComponent } from '../rgw-rate-limit/rgw-rate-limit.component' ;
4242import { RgwRateLimitConfig } from '../models/rgw-rate-limit' ;
4343import { ModalCdsService } from '~/app/shared/services/modal-cds.service' ;
44+ import { RgwUserAccountsService } from '~/app/shared/api/rgw-user-accounts.service' ;
45+ import { RgwUser } from '../models/rgw-user' ;
4446
4547@Component ( {
4648 selector : 'cd-rgw-bucket-form' ,
@@ -55,7 +57,9 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
5557
5658 bucketForm : CdFormGroup ;
5759 editing = false ;
58- owners : string [ ] = null ;
60+ owners : RgwUser [ ] = null ;
61+ accounts : string [ ] = [ ] ;
62+ accountUsers : RgwUser [ ] = [ ] ;
5963 kmsProviders : string [ ] = null ;
6064 action : string ;
6165 resource : string ;
@@ -104,7 +108,8 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
104108 public actionLabels : ActionLabelsI18n ,
105109 private readonly changeDetectorRef : ChangeDetectorRef ,
106110 private rgwMultisiteService : RgwMultisiteService ,
107- private rgwDaemonService : RgwDaemonService
111+ private rgwDaemonService : RgwDaemonService ,
112+ private rgwAccountsService : RgwUserAccountsService
108113 ) {
109114 super ( ) ;
110115 this . editing = this . router . url . startsWith ( `/rgw/bucket/${ URLVerbs . EDIT } ` ) ;
@@ -137,7 +142,14 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
137142 ? [ ]
138143 : [ CdValidators . bucketName ( ) , CdValidators . bucketExistence ( false , this . rgwBucketService ) ]
139144 ] ,
140- owner : [ null , [ Validators . required ] ] ,
145+ owner : [
146+ null ,
147+ [
148+ CdValidators . requiredIf ( {
149+ isAccountOwner : false
150+ } )
151+ ]
152+ ] ,
141153 kms_provider : [ 'vault' ] ,
142154 'placement-target' : [ null ] ,
143155 versioning : [ null ] ,
@@ -169,13 +181,23 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
169181 lifecycle : [ '{}' , CdValidators . jsonOrXml ( ) ] ,
170182 grantee : [ Grantee . Owner , [ Validators . required ] ] ,
171183 aclPermission : [ [ aclPermission . FullControl ] , [ Validators . required ] ] ,
172- replication : [ false ]
184+ replication : [ false ] ,
185+ isAccountOwner : [ false ] ,
186+ accountUser : [
187+ null ,
188+ [
189+ CdValidators . requiredIf ( {
190+ isAccountOwner : true
191+ } )
192+ ]
193+ ]
173194 } ) ;
174195 }
175196
176197 ngOnInit ( ) {
177198 const promises = {
178- owners : this . rgwUserService . enumerate ( )
199+ owners : this . rgwUserService . enumerate ( true ) ,
200+ accounts : this . rgwAccountsService . list ( )
179201 } ;
180202 this . multisiteStatus$ = this . rgwMultisiteService . status ( ) ;
181203 this . isDefaultZoneGroup$ = this . rgwDaemonService . selectedDaemon$ . pipe (
@@ -217,8 +239,9 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
217239
218240 forkJoin ( promises ) . subscribe ( ( data : any ) => {
219241 // Get the list of possible owners.
220- this . owners = ( < string [ ] > data . owners ) . sort ( ) ;
221-
242+ this . accounts = data . accounts ;
243+ this . accountUsers = data . owners . filter ( ( owner : RgwUser ) => owner . account_id ) ;
244+ this . owners = data . owners . filter ( ( owner : RgwUser ) => ! owner . account_id ) ;
222245 // Get placement targets:
223246 if ( data [ 'getPlacementTargets' ] ) {
224247 const placementTargets = data [ 'getPlacementTargets' ] ;
@@ -269,13 +292,21 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
269292 }
270293 this . bucketForm . setValue ( value ) ;
271294 if ( this . editing ) {
272- // temporary fix until the s3 account management is implemented in
273- // the frontend. Disable changing the owner of the bucket in case
295+ // Disable changing the owner of the bucket in case
274296 // its owned by the account.
275- // @TODO : Introduce account selection for a bucket.
276- if ( ! this . owners . includes ( value [ 'owner' ] ) ) {
277- this . owners . push ( value [ 'owner' ] ) ;
278- this . bucketForm . get ( 'owner' ) . disable ( ) ;
297+ const ownersList = data . owners . map ( ( owner : RgwUser ) => owner . uid ) ;
298+ if ( ! ownersList . includes ( value [ 'owner' ] ) ) {
299+ // creating dummy user object to show the account owner
300+ // here value['owner] is the account user id
301+ const user = Object . assign (
302+ { uid : value [ 'owner' ] } ,
303+ ownersList . find ( ( owner : RgwUser ) => owner . uid === AppConstants . defaultUser )
304+ ) ;
305+ this . accountUsers . push ( user ) ;
306+ this . bucketForm . get ( 'isAccountOwner' ) . setValue ( true ) ;
307+ this . bucketForm . get ( 'isAccountOwner' ) . disable ( ) ;
308+ this . bucketForm . get ( 'accountUser' ) . setValue ( value [ 'owner' ] ) ;
309+ this . bucketForm . get ( 'accountUser' ) . disable ( ) ;
279310 }
280311 this . isVersioningAlreadyEnabled = this . isVersioningEnabled ;
281312 this . isMfaDeleteAlreadyEnabled = this . isMfaDeleteEnabled ;
@@ -340,7 +371,19 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
340371 // make the owner empty if the field is disabled.
341372 // this ensures the bucket doesn't gets updated with owner when
342373 // the bucket is owned by the account.
343- const owner = this . bucketForm . get ( 'owner' ) . disabled === true ? '' : values [ 'owner' ] ;
374+ let owner ;
375+ if ( this . bucketForm . get ( 'accountUser' ) . disabled ) {
376+ // If the bucket is owned by the account, then set the owner as account user.
377+ owner = '' ;
378+ } else if ( values [ 'isAccountOwner' ] ) {
379+ const accountUser : RgwUser = this . accountUsers . filter (
380+ ( user ) => values [ 'accountUser' ] === user . uid
381+ ) [ 0 ] ;
382+ owner = accountUser ?. account_id ?? values [ 'owner' ] ;
383+ } else {
384+ owner = values [ 'owner' ] ;
385+ }
386+
344387 this . rgwBucketService
345388 . update (
346389 values [ 'bid' ] ,
@@ -376,11 +419,12 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
376419 }
377420 ) ;
378421 } else {
422+ const owner = values [ 'isAccountOwner' ] ? values [ 'accountUser' ] : values [ 'owner' ] ;
379423 // Add
380424 this . rgwBucketService
381425 . create (
382426 values [ 'bid' ] ,
383- values [ ' owner' ] ,
427+ owner ,
384428 this . zonegroup ,
385429 values [ 'placement-target' ] ,
386430 values [ 'lock_enabled' ] ,
@@ -421,7 +465,8 @@ export class RgwBucketFormComponent extends CdForm implements OnInit, AfterViewC
421465 * Scenario 2: Changing the bucket owner from non-tenanted to tenanted
422466 * Scenario 3: Keeping the owner(tenanted) same and changing only rate limit
423467 */
424- const owner = this . bucketForm . getValue ( 'owner' ) ;
468+ // in case of creating bucket with account user, owner will be empty
469+ const owner = this . bucketForm . getValue ( 'owner' ) || '' ;
425470 const bidInput = this . bucketForm . getValue ( 'bid' ) ;
426471
427472 let bid : string ;
0 commit comments