From 22d6f33cf24da5ae55ca241750c91a7b73a86330 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 10 Jul 2018 13:19:26 +0100 Subject: [PATCH 1/5] customize error message for copilots --- src/permissions/project.view.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/permissions/project.view.js b/src/permissions/project.view.js index b3c0e218..d08091be 100644 --- a/src/permissions/project.view.js +++ b/src/permissions/project.view.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import util from '../util'; import models from '../models'; -import { USER_ROLE } from '../constants'; +import { USER_ROLE, PROJECT_STATUS } from '../constants'; /** * Super admin, Topcoder Managers are allowed to view any projects @@ -37,8 +37,30 @@ module.exports = freq => new Promise((resolve, reject) => { }) .then((hasAccess) => { if (!hasAccess) { + let errorMessage = 'You do not have permissions to perform this action'; + // customize error message for copilots + if (util.hasRole(freq, USER_ROLE.COPILOT)) { + if (_.findIndex(freq.context.currentProjectMembers, m => m.role === USER_ROLE.COPILOT) >= 0) { + errorMessage = 'Project is already claimed by another copilot'; + } else { + models.Project + .find({ + where: { id: projectId }, + attributes: ['status'], + raw: true, + }) + .then((project) => { + if (!project || [PROJECT_STATUS.DRAFT, PROJECT_STATUS.IN_REVIEW].indexOf(project.status) >= 0) { + errorMessage = 'Project is not yet available to copilots'; + } else { + // project status is 'active' or higher so it's not available to copilots + errorMessage = 'Project has already started'; + } + }); + } + } // user is not an admin nor is a registered project member - return reject(new Error('You do not have permissions to perform this action')); + return reject(new Error(errorMessage)); } return resolve(true); }); From d2f9da812710592c87fb7911be1f50efcd228b32 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 10 Jul 2018 13:20:20 +0100 Subject: [PATCH 2/5] deploy feature branch --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c3db4502..bfd86010 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,7 @@ workflows: - test filters: branches: - only: ['dev', 'feature/dev-challenges'] + only: ['dev', 'feature/dev-challenges', 'feature/projectStatusCopilotMessages'] - deployProd: requires: - test From 9ece8681258ccf9efc96f3c57b51ed8cf4e11374 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 10 Jul 2018 14:24:07 +0100 Subject: [PATCH 3/5] update error messages --- src/permissions/project.view.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/permissions/project.view.js b/src/permissions/project.view.js index d08091be..6844de18 100644 --- a/src/permissions/project.view.js +++ b/src/permissions/project.view.js @@ -41,9 +41,10 @@ module.exports = freq => new Promise((resolve, reject) => { // customize error message for copilots if (util.hasRole(freq, USER_ROLE.COPILOT)) { if (_.findIndex(freq.context.currentProjectMembers, m => m.role === USER_ROLE.COPILOT) >= 0) { - errorMessage = 'Project is already claimed by another copilot'; - } else { - models.Project + errorMessage = 'Copilot: Project is already claimed by another copilot'; + return Promise.resolve(errorMessage); + } + return models.Project .find({ where: { id: projectId }, attributes: ['status'], @@ -51,14 +52,20 @@ module.exports = freq => new Promise((resolve, reject) => { }) .then((project) => { if (!project || [PROJECT_STATUS.DRAFT, PROJECT_STATUS.IN_REVIEW].indexOf(project.status) >= 0) { - errorMessage = 'Project is not yet available to copilots'; + errorMessage = 'Copilot: Project is not yet available to copilots'; } else { // project status is 'active' or higher so it's not available to copilots - errorMessage = 'Project has already started'; + errorMessage = 'Copilot: Project has already started'; } + return Promise.resolve(errorMessage); }); - } } + // user is not an admin nor is a registered project member + return Promise.resolve(errorMessage); + } + return Promise.resolve(null); + }).then((errorMessage) => { + if (errorMessage) { // user is not an admin nor is a registered project member return reject(new Error(errorMessage)); } From 765d37d7fa2f65d20a33dea6240c887747e46d25 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 10 Jul 2018 14:39:35 +0100 Subject: [PATCH 4/5] update error messages --- src/permissions/project.view.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/permissions/project.view.js b/src/permissions/project.view.js index 6844de18..b82cd1dc 100644 --- a/src/permissions/project.view.js +++ b/src/permissions/project.view.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import util from '../util'; import models from '../models'; -import { USER_ROLE, PROJECT_STATUS } from '../constants'; +import { USER_ROLE, PROJECT_STATUS, PROJECT_MEMBER_ROLE } from '../constants'; /** * Super admin, Topcoder Managers are allowed to view any projects @@ -40,7 +40,7 @@ module.exports = freq => new Promise((resolve, reject) => { let errorMessage = 'You do not have permissions to perform this action'; // customize error message for copilots if (util.hasRole(freq, USER_ROLE.COPILOT)) { - if (_.findIndex(freq.context.currentProjectMembers, m => m.role === USER_ROLE.COPILOT) >= 0) { + if (_.findIndex(freq.context.currentProjectMembers, m => m.role === PROJECT_MEMBER_ROLE.COPILOT) >= 0) { errorMessage = 'Copilot: Project is already claimed by another copilot'; return Promise.resolve(errorMessage); } From dce240474ebef7b341296432a7f435967c6b6bb6 Mon Sep 17 00:00:00 2001 From: Samir Gondzetovic Date: Tue, 10 Jul 2018 14:41:41 +0100 Subject: [PATCH 5/5] remove feature branch from deployment --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bfd86010..c3db4502 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,7 @@ workflows: - test filters: branches: - only: ['dev', 'feature/dev-challenges', 'feature/projectStatusCopilotMessages'] + only: ['dev', 'feature/dev-challenges'] - deployProd: requires: - test