diff --git a/lib/api/multiObjectDelete.js b/lib/api/multiObjectDelete.js index f6dce72236..c224cb7612 100644 --- a/lib/api/multiObjectDelete.js +++ b/lib/api/multiObjectDelete.js @@ -18,8 +18,7 @@ const { preprocessingVersioningDelete } const createAndStoreObject = require('./apiUtils/object/createAndStoreObject'); const { metadataGetObject } = require('../metadata/metadataUtils'); const { config } = require('../Config'); -const { hasGovernanceBypassHeader, checkUserGovernanceBypass, ObjectLockInfo } - = require('./apiUtils/object/objectLockHelpers'); +const { isObjectLocked } = require('./apiUtils/object/objectLockHelpers'); const requestUtils = policies.requestUtils; const versionIdUtils = versioning.VersionID; @@ -230,6 +229,10 @@ function getObjMetadataAndDelete(authInfo, canonicalID, request, successfullyDeleted.push({ entry }); return callback(skipError); } + if (versionId && isObjectLocked(bucket, objMD, request.headers)) { + log.debug('trying to delete locked object'); + return callback(objectLockedError); + } if (versionId && objMD.location && Array.isArray(objMD.location) && objMD.location[0]) { // we need this information for data deletes to AWS @@ -238,47 +241,6 @@ function getObjMetadataAndDelete(authInfo, canonicalID, request, } return callback(null, objMD, versionId); }), - (objMD, versionId, callback) => { - // AWS only returns an object lock error if a version id - // is specified, else continue to create a delete marker - if (!versionId || !bucket.isObjectLockEnabled()) { - return callback(null, null, objMD, versionId); - } - const hasGovernanceBypass = hasGovernanceBypassHeader(request.headers); - if (hasGovernanceBypass && authInfo.isRequesterAnIAMUser()) { - return checkUserGovernanceBypass(request, authInfo, bucket, entry.key, log, error => { - if (error && error.is.AccessDenied) { - log.debug('user does not have BypassGovernanceRetention and object is locked', { error }); - return callback(objectLockedError); - } - if (error) { - return callback(error); - } - return callback(null, hasGovernanceBypass, objMD, versionId); - }); - } - return callback(null, hasGovernanceBypass, objMD, versionId); - }, - (hasGovernanceBypass, objMD, versionId, callback) => { - // AWS only returns an object lock error if a version id - // is specified, else continue to create a delete marker - if (!versionId || !bucket.isObjectLockEnabled()) { - return callback(null, objMD, versionId); - } - const objLockInfo = new ObjectLockInfo({ - mode: objMD.retentionMode, - date: objMD.retentionDate, - legalHold: objMD.legalHold || false, - }); - - // If the object can not be deleted raise an error - if (!objLockInfo.canModifyObject(hasGovernanceBypass)) { - log.debug('trying to delete locked object'); - return callback(objectLockedError); - } - - return callback(null, objMD, versionId); - }, (objMD, versionId, callback) => preprocessingVersioningDelete(bucketName, bucket, objMD, versionId, log, (err, options) => callback(err, options,