Skip to content

Commit c01c0c4

Browse files
committed
rename userIds field to allowedUsers
1 parent 3f88ca1 commit c01c0c4

File tree

8 files changed

+12
-11
lines changed

8 files changed

+12
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
--
22
-- project_attachments
33
--
4-
ALTER TABLE project_attachments ADD COLUMN "userIds" integer[];
4+
ALTER TABLE project_attachments ADD COLUMN "allowedUsers" integer[];

src/models/projectAttachment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function defineProjectAttachment(sequelize, DataTypes) {
99
description: { type: DataTypes.STRING, allowNull: true },
1010
filePath: { type: DataTypes.STRING, allowNull: false },
1111
contentType: { type: DataTypes.STRING, allowNull: false },
12-
userIds: DataTypes.ARRAY({ type: DataTypes.INTEGER, allowNull: true }),
12+
allowedUsers: DataTypes.ARRAY({ type: DataTypes.INTEGER, allowNull: true }),
1313
deletedAt: { type: DataTypes.DATE, allowNull: true },
1414
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
1515
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
@@ -51,7 +51,7 @@ module.exports = function defineProjectAttachment(sequelize, DataTypes) {
5151
$or: [{
5252
createdBy: { $eq: userId },
5353
}, {
54-
userIds: {
54+
allowedUsers: {
5555
$or: [
5656
{ $contains: [userId] },
5757
{ $eq: null },

src/permissions/project.downloadAttachment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = freq => new Promise((resolve, reject) => {
2727
return resolve(true);
2828
}
2929

30-
if (attachment.createdBy === userId || attachment.userIds === null || attachment.userIds.indexOf(userId) >= 0) {
30+
if (attachment.createdBy === userId || attachment.allowedUsers === null ||
31+
attachment.allowedUsers.indexOf(userId) >= 0) {
3132
return resolve(true);
3233
}
3334

src/routes/attachments/create.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const addAttachmentValidations = {
2525
filePath: Joi.string().required(),
2626
s3Bucket: Joi.string().required(),
2727
contentType: Joi.string().required(),
28-
userIds: Joi.array(Joi.number().integer().positive()).allow(null).default(null),
28+
allowedUsers: Joi.array(Joi.number().integer().positive()).allow(null).default(null),
2929
}).required(),
3030
},
3131
};
@@ -42,7 +42,7 @@ module.exports = [
4242
const data = req.body.param;
4343
// default values
4444
const projectId = req.params.projectId;
45-
const userIds = data.userIds;
45+
const allowedUsers = data.allowedUsers;
4646
_.assign(data, {
4747
projectId,
4848
createdBy: req.authUser.userId,
@@ -100,7 +100,7 @@ module.exports = [
100100
req.log.debug('creating db record');
101101
return models.ProjectAttachment.create({
102102
projectId,
103-
userIds,
103+
allowedUsers,
104104
createdBy: req.authUser.userId,
105105
updatedBy: req.authUser.userId,
106106
title: data.title,

src/routes/attachments/delete.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Project Attachments delete', () => {
4848
size: 12312,
4949
category: null,
5050
filePath: 'https://media.topcoder.com/projects/1/test.txt',
51-
createdBy: testUtil.userIds.copilot,
51+
createdBy: testUtil.allowedUsers.copilot,
5252
updatedBy: 1,
5353
}).then((a1) => {
5454
attachment = a1;

src/routes/attachments/download.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Project Attachments download', () => {
5252
filePath: 'https://media.topcoder.com/projects/1/test.txt',
5353
createdBy: testUtil.userIds.copilot,
5454
updatedBy: 1,
55-
userIds: [testUtil.userIds.member],
55+
allowedUsers: [testUtil.userIds.member],
5656
}).then((a1) => {
5757
attachment = a1;
5858
done();

src/routes/attachments/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const updateProjectAttachmentValidation = {
1919
param: Joi.object().keys({
2020
title: Joi.string().required(),
2121
description: Joi.string().optional().allow(null).allow(''),
22-
userIds: Joi.array(Joi.number().integer().positive()).allow(null).default(null),
22+
allowedUsers: Joi.array(Joi.number().integer().positive()).allow(null).default(null),
2323
}),
2424
},
2525
};

src/routes/attachments/update.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Project Attachments update', () => {
4949
filePath: 'https://media.topcoder.com/projects/1/test.txt',
5050
createdBy: testUtil.userIds.copilot,
5151
updatedBy: 1,
52-
userIds: [],
52+
allowedUsers: [],
5353
}).then((a1) => {
5454
attachment = a1;
5555
done();

0 commit comments

Comments
 (0)