Skip to content

Commit 6403806

Browse files
committed
Manage legacy public ACL's
Sync Bucket and Object public status Tidy code
1 parent 13ccaa1 commit 6403806

File tree

8 files changed

+134
-136
lines changed

8 files changed

+134
-136
lines changed

app/src/components/utils.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const utils = {
9898
data.bucket = bucketData.bucket;
9999
data.endpoint = bucketData.endpoint;
100100
data.key = bucketData.key;
101-
// data.public = bucketData.public;
102101
data.secretAccessKey = bucketData.secretAccessKey;
103102
if (bucketData.region) data.region = bucketData.region;
104103
} else if (utils.getConfigBoolean('objectStorage.enabled')) {
@@ -496,7 +495,7 @@ const utils = {
496495

497496
/**
498497
* @function stripDelimit
499-
* Yields a string `s` that will never have a trailing delimiter. Returns an empty string if falsy.
498+
* Yields a string `s` that will never have a trailing delimiter.
500499
* @param {string} s The input string
501500
* @returns {string} The string `s` without the trailing delimiter, or an empty string.
502501
*/
@@ -505,6 +504,23 @@ const utils = {
505504
else return '';
506505
},
507506

507+
/**
508+
* @function trimResourcePath
509+
* Yields a string `s` without trailing delimiters or asterixes.
510+
* @param {string} s The input string
511+
* @returns {string} The string `s` without trailing delimiters or asterix, or an empty string.
512+
*/
513+
trimResourcePath(s) {
514+
switch (true) {
515+
case s.endsWith(DELIMITER):
516+
return utils.stripDelimit(s.slice(0, -1));
517+
case s.endsWith(DELIMITER + '*'):
518+
return utils.stripDelimit(s.slice(0, -2));
519+
default:
520+
return s;
521+
}
522+
},
523+
508524
/**
509525
* @function toLowerKeys
510526
* Converts all key names for all objects in an array to lowercase

app/src/controllers/bucket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ const controller = {
361361
};
362362
// Update S3 Policy
363363
await storageService.updatePublic(data).catch((e) => {
364-
log.warn('Failed to apply permission changes to S3' + e, { function: 'togglePublic', ...data });
364+
log.warn('Failed to apply permission changes to S3 ' + e, { function: 'togglePublic', ...data });
365365
});
366366

367367
// Child bucket cannot be non-public when parent is public

app/src/controllers/object.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,6 @@ const controller = {
10341034
* @returns {function} Express middleware function
10351035
*/
10361036
async searchObjects(req, res, next) {
1037-
// TODO: Consider support for filtering by set of permissions?
1038-
// TODO: handle additional parameters. Eg: deleteMarker, latest
10391037
try {
10401038
const bucketIds = mixedQueryToArray(req.query.bucketId);
10411039
const objIds = mixedQueryToArray(req.query.objectId);
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
exports.up = function (knex) {
22
return Promise.resolve()
3-
// // allow null for object.public
4-
// .then(() => knex.schema.alterTable('object', table => {
5-
// table.boolean('public').nullable().alter();
6-
// }))
7-
// // where object.public is false, set to null
8-
// .then(() => knex('object')
9-
// .where({ 'public': false })
10-
// .update({ 'public': null }))
11-
// .then(() => knex.schema.alterTable('object', table => {
12-
// table.boolean('public').nullable().alter();
13-
// }))
143
// add public column to bucket table
154
.then(() => knex.schema.alterTable('bucket', table => {
165
table.boolean('public').notNullable().defaultTo(false);
@@ -23,13 +12,4 @@ exports.down = function (knex) {
2312
.then(() => knex.schema.alterTable('bucket', table => {
2413
table.dropColumn('public');
2514
}));
26-
// // where object.public is null, set to false
27-
// .then(() => knex('object')
28-
// .where({ 'public': null })
29-
// .update({ 'public': false }))
30-
31-
// disallow null for object.public
32-
// .then(() => knex.schema.alterTable('object', table => {
33-
// table.boolean('public').notNullable().defaultTo(false).alter();
34-
// }));
3515
};

app/src/middleware/authorization.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -298,38 +298,11 @@ const isBucketPublic = async (bucketId) => {
298298
return false;
299299
};
300300

301-
// alternative approach
302-
// Route middleware to check if requested bucket is public
303-
// const isBucketPublic = async (req, _res, next) => {
304-
// // if an unauthenticated request
305-
// if (!req.currentUser || req.currentUser.authType === AuthType.NONE) {
306-
// // if providing a single bucketId in query
307-
// if (mixedQueryToArray(req.query.bucketId).length === 1) {
308-
// const bucket = await bucketService.read(req.query.bucketId);
309-
// // and bucket public is truthy
310-
// if (!bucket.public) {
311-
// return next(new Problem(403, {
312-
// detail: 'Bucket is not public',
313-
// instance: req.originalUrl
314-
// }));
315-
// }
316-
// }
317-
// }
318-
// else {
319-
// return next(new Problem(403, {
320-
// detail: 'User lacks permission to complete this action',
321-
// instance: req.originalUrl
322-
// }));
323-
// }
324-
// next();
325-
// };
326-
327301
module.exports = {
328302
_checkPermission,
329303
checkAppMode,
330304
checkElevatedUser,
331305
checkS3BasicAccess,
332-
// checkGrantingPermittedPermissions
333306
currentObject,
334307
hasPermission,
335308
isBucketPublic,

app/src/services/bucket.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ const service = {
272272
* @throws If there are no records found
273273
*/
274274
searchParentBuckets: async (bucket, returnPermissions = false, userId, etrx = undefined) => {
275-
276275
let trx;
277276
try {
278277
trx = etrx ? etrx : await Bucket.startTransaction();

0 commit comments

Comments
 (0)