@@ -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 ) => {
@@ -142,17 +145,8 @@ const controller = {
142145 dbBuckets = dbBuckets . filter ( b => b . bucketId !== dbBucket . bucketId ) ;
143146 } )
144147 )
145- ) ;
146- // add current user's permissions to all buckets
147- await Promise . all (
148- dbBuckets . map ( bucket => {
149- return bucketPermissionService . addPermissions (
150- bucket . bucketId ,
151- currentUserParentBucketPerms . map ( permCode => ( { userId, permCode } ) ) ,
152- undefined ,
153- trx
154- ) ;
155- } )
148+ // TODO: delete COMS S3 Policies for deleted COMS buckets and child objects.
149+ // Also consider when using DEL /Bucket endpoint, should we delete policies?
156150 ) ;
157151
158152 // Create buckets only found in S3 in COMS db
@@ -177,6 +171,22 @@ const controller = {
177171 } ) ;
178172 } )
179173 ) ;
174+
175+ // Update permissions and Sync Public status
176+ await Promise . all (
177+ // for each bucket
178+ dbBuckets . map ( async bucket => {
179+ // --- Add current user's permissions that exist on parent bucket if they dont already exist
180+ await bucketPermissionService . addPermissions (
181+ bucket . bucketId ,
182+ currentUserParentBucketPerms . map ( permCode => ( { userId, permCode } ) ) ,
183+ undefined ,
184+ trx
185+ ) ;
186+ // --- Sync S3 Bucket Policies applied by COMS
187+ await this . syncBucketPublic ( bucket . key , bucket . bucketId , userId ) ;
188+ } )
189+ ) ;
180190 return dbBuckets ;
181191 }
182192 catch ( err ) {
@@ -185,6 +195,18 @@ const controller = {
185195 }
186196 } ,
187197
198+ async syncBucketPublic ( key , bucketId , userId ) {
199+ let isPublic = false ;
200+ isPublic = await storageService . getPublic ( { path : key , bucketId : bucketId } ) ;
201+ bucketService . update ( {
202+ bucketId : bucketId ,
203+ updatedBy : userId ,
204+ public : isPublic
205+ // TODO: consider changing this to actual lastSyncDate
206+ // lastSyncRequestedDate: now(),
207+ } ) ;
208+ } ,
209+
188210 /**
189211 * @function queueObjectRecords
190212 * Synchronizes (creates / prunes) COMS db object records with state in S3
0 commit comments