@@ -56,10 +56,10 @@ const controller = {
5656 /**
5757 * sync (ie create or delete) bucket records in COMS db to match 'folders' (S3 key prefixes) that exist in S3
5858 */
59- // parent + child bucket records already in COMS db
59+ // get parent + child bucket records already in COMS db
6060 const dbChildBuckets = await bucketService . searchChildBuckets ( parentBucket , false , userId ) ;
6161 let dbBuckets = [ parentBucket ] . concat ( dbChildBuckets ) ;
62- // 'folders' that exist below (and including) the parent 'folder' in S3
62+
6363 const s3Response = await storageService . listAllObjectVersions ( { bucketId : bucketId , precisePath : false } ) ;
6464 const s3Keys = [ ...new Set ( [
6565 ...s3Response . DeleteMarkers . map ( object => formatS3KeyForCompare ( object . Key ) ) ,
@@ -68,7 +68,7 @@ const controller = {
6868
6969 // Wrap sync sql operations in a single transaction
7070 const response = await utils . trxWrapper ( async ( trx ) => {
71-
71+ // sync bucket records
7272 const syncedBuckets = await this . syncBucketRecords (
7373 dbBuckets ,
7474 s3Keys ,
@@ -106,6 +106,9 @@ const controller = {
106106 const bucket = await bucketService . read ( bucketId ) ;
107107 const userId = await userService . getCurrentUserId ( getCurrentIdentity ( req . currentUser , SYSTEM_USER ) , SYSTEM_USER ) ;
108108
109+ // sync bucket.public flag
110+ await this . syncBucketPublic ( bucket . key , bucket . bucketId , userId ) ;
111+
109112 const s3Objects = await storageService . listAllObjectVersions ( { bucketId : bucketId , filterLatest : true } ) ;
110113
111114 const response = await utils . trxWrapper ( async ( trx ) => {
@@ -141,17 +144,8 @@ const controller = {
141144 dbBuckets = dbBuckets . filter ( b => b . bucketId !== dbBucket . bucketId ) ;
142145 } )
143146 )
144- ) ;
145- // add current user's permissions to all buckets
146- await Promise . all (
147- dbBuckets . map ( bucket => {
148- return bucketPermissionService . addPermissions (
149- bucket . bucketId ,
150- currentUserParentBucketPerms . map ( permCode => ( { userId, permCode } ) ) ,
151- undefined ,
152- trx
153- ) ;
154- } )
147+ // TODO: delete COMS S3 Policies for deleted COMS buckets and child objects.
148+ // Also consider when using DEL /Bucket endpoint, should we delete policies?
155149 ) ;
156150
157151 // Create buckets only found in S3 in COMS db
@@ -176,6 +170,22 @@ const controller = {
176170 } ) ;
177171 } )
178172 ) ;
173+
174+ // Update permissions and Sync Public status
175+ await Promise . all (
176+ // for each bucket
177+ dbBuckets . map ( async bucket => {
178+ // --- Add current user's permissions that exist on parent bucket if they dont already exist
179+ await bucketPermissionService . addPermissions (
180+ bucket . bucketId ,
181+ currentUserParentBucketPerms . map ( permCode => ( { userId, permCode } ) ) ,
182+ undefined ,
183+ trx
184+ ) ;
185+ // --- Sync S3 Bucket Policies applied by COMS
186+ await this . syncBucketPublic ( bucket . key , bucket . bucketId , userId ) ;
187+ } )
188+ ) ;
179189 return dbBuckets ;
180190 }
181191 catch ( err ) {
@@ -184,6 +194,18 @@ const controller = {
184194 }
185195 } ,
186196
197+ async syncBucketPublic ( key , bucketId , userId ) {
198+ let public = false ;
199+ public = await storageService . getPublic ( { path : key , bucketId : bucketId } ) ;
200+ bucketService . update ( {
201+ bucketId : bucketId ,
202+ updatedBy : userId ,
203+ public : public
204+ // TODO: consider changing this to actual lastSyncDate
205+ // lastSyncRequestedDate: now(),
206+ } ) ;
207+ } ,
208+
187209 /**
188210 * @function queueObjectRecords
189211 * Synchronizes (creates / prunes) COMS db object records with state in S3
0 commit comments