Skip to content

Commit cfddb85

Browse files
author
vikasrohit
authored
Merge pull request #653 from topcoder-platform/develop
Prod release - 3.4.0
2 parents 3ff46df + f8d45c5 commit cfddb85

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ workflows:
152152
- UnitTests
153153
filters:
154154
branches:
155-
only: ['develop', 'connect-performance-testing', 'feature/get-markup-from-billing-account']
155+
only: ['develop', 'connect-performance-testing', 'feature/shapeup_billing_accounts_protections']
156156
- deployProd:
157157
context : org-global
158158
requires:

config/development.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"identityServiceEndpoint": "https://api.topcoder-dev.com/v3/",
1010
"taasJobApiUrl": "https://api.topcoder-dev.com/v5/jobs",
1111
"sfdcBillingAccountNameField": "Billing_Account_Name__c",
12-
"sfdcBillingAccountMarkupField": "Mark_Up__c"
12+
"sfdcBillingAccountMarkupField": "Mark_Up__c",
13+
"sfdcBillingAccountActiveField": "Active__c"
1314
}

config/production.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"authDomain": "topcoder.com",
33
"connectProjectsUrl": "https://connect.topcoder.com/projects/",
44
"sfdcBillingAccountNameField": "Billing_Account_name__c",
5-
"sfdcBillingAccountMarkupField": "Mark_up__c"
5+
"sfdcBillingAccountMarkupField": "Mark_up__c",
6+
"sfdcBillingAccountActiveField": "Active__c"
67
}

src/permissions/constants.js

+7
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ export const PERMISSION = { // eslint-disable-line import/prefer-default-export
293293
group: 'Project Billing Accounts',
294294
description: 'Who can view the details of the Billing Account attached to the project',
295295
},
296+
projectRoles: [
297+
...PROJECT_ROLES_MANAGEMENT,
298+
PROJECT_MEMBER_ROLE.COPILOT,
299+
],
300+
topcoderRoles: [
301+
USER_ROLE.TOPCODER_ADMIN,
302+
],
296303
scopes: SCOPES_PROJECTS_READ_BILLING_ACCOUNT_DETAILS,
297304
},
298305

src/routes/billingAccounts/get.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ module.exports = [
4242
}
4343
const { accessToken, instanceUrl } = await SalesforceService.authenticate();
4444
// eslint-disable-next-line
45-
const sql = `SELECT TopCoder_Billing_Account_Id__c, Mark_Up__c from Topcoder_Billing_Account__c tba where TopCoder_Billing_Account_Id__c='${billingAccountId}'`;
45+
const sql = `SELECT TopCoder_Billing_Account_Id__c, Mark_Up__c, Active__c from Topcoder_Billing_Account__c tba where TopCoder_Billing_Account_Id__c='${billingAccountId}'`;
4646
req.log.debug(sql);
4747
const billingAccount = await SalesforceService.queryBillingAccount(sql, accessToken, instanceUrl, req.log);
48+
const isMachineToken = _.get(req, 'authUser.isMachine', false);
49+
if (!isMachineToken) {
50+
// delete sensitive information for non machine access
51+
// does not revalidate the scope as it assumes that is already taken care
52+
delete billingAccount.markup;
53+
}
4854
res.json(billingAccount);
4955
} catch (error) {
5056
req.log.error(error);

src/routes/billingAccounts/get.spec.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import server from '../../app';
88
import testUtil from '../../tests/util';
99
import SalesforceService from '../../services/salesforceService';
1010

11-
chai.should();
11+
const should = chai.should();
1212

1313
// demo data which might be returned by the `SalesforceService.query`
1414
const billingAccountData = {
@@ -114,16 +114,6 @@ describe('Project Billing Accounts list', () => {
114114
.expect(403, done);
115115
});
116116

117-
it('should return 403 for admin', (done) => {
118-
request(server)
119-
.get(`/v5/projects/${project1.id}/billingAccount`)
120-
.set({
121-
Authorization: `Bearer ${testUtil.jwts.admin}`,
122-
})
123-
.send()
124-
.expect(403, done);
125-
});
126-
127117
it('should return 404 if the project is not found', (done) => {
128118
request(server)
129119
.get('/v5/projects/11223344/billingAccount')
@@ -163,5 +153,26 @@ describe('Project Billing Accounts list', () => {
163153
}
164154
});
165155
});
156+
157+
it('should return billing account details using user token but without markup field',
158+
(done) => {
159+
request(server)
160+
.get(`/v5/projects/${project1.id}/billingAccount`)
161+
.set({
162+
Authorization: `Bearer ${testUtil.jwts.admin}`,
163+
})
164+
.send()
165+
.expect(200)
166+
.end((err, res) => {
167+
if (err) {
168+
done(err);
169+
} else {
170+
const resJson = res.body;
171+
resJson.tcBillingAccountId.should.be.eql(billingAccountData.tcBillingAccountId);
172+
should.not.exist(resJson.markup);
173+
done();
174+
}
175+
});
176+
});
166177
});
167178
});

src/services/salesforceService.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class SalesforceService {
102102
null, // fallback to null if cannot parse
103103
),
104104
markup: _.get(o, config.get('sfdcBillingAccountMarkupField')),
105+
active: _.get(o, config.get('sfdcBillingAccountActiveField')),
105106
}));
106107
return billingAccounts.length > 0 ? billingAccounts[0] : {};
107108
});

0 commit comments

Comments
 (0)