Skip to content

Commit

Permalink
BC-5461 - fix check on undefined prop
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP committed Oct 4, 2023
1 parent 13f4d7a commit 77dfd0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/services/fileStorage/proxy-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ const signedUrlService = {
throw new NotFound('File seems not to be there.');
}

// deprecated: author check via file.permissions[0].refId is deprecated and will be removed in the next release
// deprecated: author check via file.permissions[0]?.refId is deprecated and will be removed in the next release
const creatorId =
fileObject.creator ||
(fileObject.permissions[0].refPermModel !== 'user' ? userId : fileObject.permissions[0].refId);
(fileObject.permissions[0]?.refPermModel !== 'user' ? userId : fileObject.permissions[0]?.refId);

if (download && fileObject.securityCheck && fileObject.securityCheck.status === SecurityCheckStatusTypes.BLOCKED) {
throw new Forbidden('File access blocked by security check.');
Expand Down Expand Up @@ -456,11 +456,11 @@ const signedUrlService = {
throw new NotFound('File seems not to be there.');
}

// deprecated: author check via file.permissions[0].refId is deprecated and will be removed in the next release
// deprecated: author check via file.permissions[0]?.refId is deprecated and will be removed in the next release
const creatorId =
fileObject.creator || fileObject.permissions[0].refPermModel !== 'user'
fileObject.creator || fileObject.permissions[0]?.refPermModel !== 'user'
? userId
: fileObject.permissions[0].refId;
: fileObject.permissions[0]?.refId;

return canRead(userId, id)
.then(() =>
Expand Down Expand Up @@ -899,8 +899,8 @@ const filePermissionService = {
const { refOwnerModel, owner } = fileObj;
const rolePermissions = fileObj.permissions.filter(({ refPermModel }) => refPermModel === 'role');
const rolePromises = rolePermissions.map(({ refId }) => RoleModel.findOne({ _id: refId }).lean().exec());
// deprecated: author check via file.permissions[0].refId is deprecated and will be removed in the next release
const isFileCreator = equalIds(fileObj.creator || fileObj.permissions[0].refId, userId);
// deprecated: author check via file.permissions[0]?.refId is deprecated and will be removed in the next release
const isFileCreator = equalIds(fileObj.creator || fileObj.permissions[0]?.refId, userId);

const actionMap = {
user: () => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/fileStorage/utils/filePermissionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const checkTeamPermission = async ({ user, file, permission }) => {
rolesToTest = rolesToTest.concat(roleIndex[roleId].roles || []);
}

// deprecated: author check via file.permissions[0].refId is deprecated and will be removed in the next release
// deprecated: author check via file.permissions[0]?.refId is deprecated and will be removed in the next release
const { role: creatorRole } = file.owner.userIds.find((_) =>
equalIds(_.userId, file.creator || file.permissions[0].refId)
equalIds(_.userId, file.creator || file.permissions[0]?.refId)
);

const findRole = (roleId) => (roles) => roles.findIndex((r) => equalIds(r._id, roleId)) > -1;
Expand Down

0 comments on commit 77dfd0f

Please sign in to comment.