Skip to content

Commit 6be7923

Browse files
author
vikasrohit
authored
Merge pull request #18 from topcoder-platform/hotfix/remove-billing-account-permission-check
[HOTFIX] [DEV] Remove billing account permission check
2 parents d7aa00b + 7943d61 commit 6be7923

File tree

1 file changed

+0
-55
lines changed

1 file changed

+0
-55
lines changed

src/services/ProcessorService.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
AUDIT_ACTION,
1515
PERMISSION_TYPE,
1616
BUGR_CONTEST_TYPE_ID,
17-
ADMIN_ROLE,
1817
COPILOT_ROLE,
1918
MANAGER_ROLE,
2019
ACCOUNT_MANAGER_ROLE,
@@ -57,58 +56,6 @@ async function checkBillingAccountExist (connection, billingAccountId) {
5756
}
5857
}
5958

60-
/**
61-
* Check user is admin
62-
* @param {Number} userId the user id.
63-
* @returns {Boolean} true if user is admin, false otherwise
64-
*/
65-
async function checkUserIsAdmin (connection, userId) {
66-
const result = await connection.queryAsync(`select sr.description as role from common_oltp:security_user su, common_oltp:user_role_xref urx, common_oltp:security_roles sr where urx.login_id = su.login_id and sr.role_id = urx.role_id and su.login_id = ${userId}`)
67-
return _.find(result, { role: ADMIN_ROLE }) !== undefined
68-
}
69-
70-
/**
71-
* Get user handle by id
72-
* @param {Number} userId the user id.
73-
* @returns {String} the user handel
74-
*/
75-
async function getUserHandle (connection, userId) {
76-
const handleRes = await connection.queryAsync(`select handle from common_oltp:user where user_id = ${userId}`)
77-
if (handleRes.length === 0) {
78-
throw new Error(`User with id: ${userId} doesn't exist.`)
79-
}
80-
return handleRes[0].handle
81-
}
82-
83-
/**
84-
* Ensure user can access the corresponding billing account
85-
* @param {Object} connection the Informix connection
86-
* @param {Number} billingAccountId the billing account id
87-
* @param {Number} userId the user id
88-
*/
89-
async function checkCanAccessBillingAccount (connection, billingAccountId, userId) {
90-
const isAdmin = await checkUserIsAdmin(connection, userId)
91-
let directAccessIds
92-
if (isAdmin) {
93-
directAccessIds = await connection.queryAsync(`select p.project_id as id from time_oltp:project as p left join time_oltp:client_project as cp on p.project_id = cp.project_id left join time_oltp:client c on c.client_id = cp.client_id and (c.is_deleted = 0 or c.is_deleted is null) where p.active = 1 and p.start_date <= current and current <= p.end_date`)
94-
} else {
95-
const userName = await getUserHandle(connection, userId)
96-
97-
directAccessIds = await connection.queryAsync(`select p.project_id as id from time_oltp:project as p left join time_oltp:client_project as cp on p.project_id = cp.project_id left join time_oltp:client c on c.client_id = cp.client_id and (c.is_deleted = 0 or c.is_deleted is null) where p.active = 1 and p.start_date <= current and current <= p.end_date and p.active = 1 and p.project_id in (SELECT distinct project_id FROM time_oltp:project_manager p, time_oltp:user_account u WHERE p.user_account_id = u.user_account_id and p.active = 1 and upper(u.user_name) = upper('${userName}') union SELECT distinct project_id FROM time_oltp:project_worker p, time_oltp:user_account u WHERE p.start_date <= current and current <= p.end_date and p.active =1 and p.user_account_id = u.user_account_id and upper(u.user_name) = upper('${userName}'))`)
98-
}
99-
100-
if (_.find(directAccessIds, { id: billingAccountId })) {
101-
return
102-
}
103-
104-
// fetch billing account id via security groups the user has permission with
105-
const billingAccountIds = await connection.queryAsync(`select gaba.billing_account_id as id from tcs_catalog:group_associated_billing_accounts gaba, tcs_catalog:customer_group cg where gaba.group_id = cg.group_id and cg.archived<>1 and (cg.client_id in (select ca.client_id from tcs_catalog:customer_administrator ca where ca.user_id=${userId}) or cg.group_id in (select gm.group_id from tcs_catalog:group_member gm, tcs_catalog:customer_group g3 where gm.group_id=g3.group_id and (gm.use_group_default=0 and gm.specific_permission='FULL' or gm.use_group_default=1 and g3.default_permission='FULL') and gm.active=1 and gm.user_id=${userId}))`)
106-
107-
if (!_.find(billingAccountIds, { id: billingAccountId })) {
108-
throw new Error(`You don't have permission to access this billing account`)
109-
}
110-
}
111-
11259
/**
11360
* Check whether the billing account have already associated to the direct project
11461
* @param {Object} connection the Informix connection
@@ -243,8 +190,6 @@ async function calculateFeeAndCheckAssociate (connection, directProjectId, billi
243190
let fee = {}
244191

245192
await checkBillingAccountExist(connection, billingAccountId)
246-
// check user can access billing account
247-
await checkCanAccessBillingAccount(connection, billingAccountId, userId)
248193

249194
// check whether billing account already associate to this direct project
250195
// not need to perform checking if we are going to create the direct project latter

0 commit comments

Comments
 (0)