@@ -9,6 +9,7 @@ const log = require('../components/log')(module.filename);
9
9
const {
10
10
addDashesToUuid,
11
11
getCurrentIdentity,
12
+ getBucket,
12
13
isTruthy,
13
14
joinPath,
14
15
mixedQueryToArray,
@@ -323,6 +324,42 @@ const controller = {
323
324
}
324
325
} ,
325
326
327
+
328
+ /**
329
+ * @function togglePublic
330
+ * Sets the public flag of a bucket (or folder)
331
+ * @param {object } req Express request object
332
+ * @param {object } res Express response object
333
+ * @param {function } next The next callback function
334
+ * @returns {function } Express middleware function
335
+ */
336
+ async togglePublic ( req , res , next ) {
337
+ try {
338
+ const bucketId = addDashesToUuid ( req . params . bucketId ) ;
339
+ const publicFlag = isTruthy ( req . query . public ) ?? false ;
340
+ const userId = await userService . getCurrentUserId ( getCurrentIdentity ( req . currentUser , SYSTEM_USER ) , SYSTEM_USER ) ;
341
+
342
+ const bucket = await getBucket ( bucketId ) ;
343
+ const data = {
344
+ bucketId : bucketId ,
345
+ path : bucket . key + '/' ,
346
+ public : publicFlag ,
347
+ userId : userId
348
+ } ;
349
+ await storageService . updatePublic ( data ) . catch ( ( ) => {
350
+ log . warn ( 'Failed to apply permission changes to S3' , { function : 'togglePublic' , ...data } ) ;
351
+ } ) ;
352
+ s3Public = await storageService . getPublic ( { path : data . path , bucketId : bucketId } ) ;
353
+
354
+ const response = await bucketService . update ( data ) ;
355
+
356
+ res . status ( 200 ) . json ( response ) ;
357
+ } catch ( e ) {
358
+ next ( errorToProblem ( SERVICE , e ) ) ;
359
+ }
360
+ } ,
361
+
362
+
326
363
/**
327
364
* @function updateBucket
328
365
* Updates a bucket
0 commit comments