Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 16b4d69

Browse files
committed
1 parent 04352e2 commit 16b4d69

19 files changed

+435
-451
lines changed

configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The following config parameters are supported, they are defined in `src/config.j
2424
| HOOK_BASE_URL | The base URL of the topcoder-x-receiver, used when adding webhooks automatically to repositories | |
2525
| TOPCODER_ENV | The topcoder environment to use, can support 'dev' or 'prod' | 'dev' |
2626
|LABELS| Labels we are going to add to the repository in the form of array of object with `name` and `color` property. Color should be hex code without hash||
27+
|ALLOWED_TOPCODER_ROLES| The allowed Topcoder role to use Topcoder X app| see configuration |
28+
|COPILOT_ROLE| The role to identify copilot|'copilot'|
2729

2830
## GitHub OAuth App Setup
2931

src/app.js

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ _.forEach(routes, (verbs, path) => {
7676
return next();
7777
});
7878
}
79+
if (def.allowedRoles) {
80+
actions.push((req, res, next) => {
81+
// check if user has allowed roles
82+
if (_(req.currentUser.roles).map((i) => i.toLowerCase())
83+
.intersection(_.map(def.allowedRoles, (j) => j.toLowerCase())).size() === 0) {
84+
const statusCode = 403;
85+
return res.status(statusCode).json({
86+
code: 'Forbidden',
87+
message: 'You are not allowed to access this resource.',
88+
});
89+
}
90+
return next();
91+
});
92+
}
7993
actions.push(method);
8094
app[verb](`/api/${config.API_VERSION}${path}`, actions);
8195
});

src/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
},
3636
HOOK_BASE_URL: process.env.HOOK_BASE_URL || 'http://topcoderx.topcoder-dev.com',
3737
TOPCODER_ENV: process.env.TOPCODER_ENV || 'dev',
38-
LABELS: process.env.LABELS || [{ name: 'Open for pickup', color: '428BCA' }, { name: 'Assigned', color: '004E00' }, { name: 'Ready for review', color: 'D1D100' }, { name: 'Paid', color: '7F8C8D' }, { name: 'Feedback', color: 'FF0000' }, { name: 'Fix accepted', color: '69D100' }],
38+
LABELS: process.env.LABELS || [{ name: 'tcx_OpenForPickup', color: '428BCA' }, { name: 'tcx_Assigned', color: '004E00' }, { name: 'tcx_ReadyForReview', color: 'D1D100' }, { name: 'tcx_Paid', color: '7F8C8D' }, { name: 'tcx_Feedback', color: 'FF0000' }, { name: 'tcx_FixAccepted', color: '69D100' }],
3939
ALLOWED_TOPCODER_ROLES: process.env.ALLOWED_TOPCODER_ROLES || ['administrator', 'admin', 'connect manager', 'connect admin', 'copilot', 'connect copilot'],
40+
COPILOT_ROLE: process.env.COPILOT_ROLE || 'copilot',
4041
};

src/controllers/PaymentController.js renamed to src/controllers/CopilotPaymentController.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @version 1.0
1010
*/
1111
const helper = require('../common/helper');
12-
const PaymentService = require('../services/PaymentService');
12+
const CopilotPaymentService = require('../services/CopilotPaymentService');
1313

1414
/**
1515
* update payments status
@@ -18,7 +18,7 @@ const PaymentService = require('../services/PaymentService');
1818
* @returns {Promise} fetch payment updates execution
1919
*/
2020
async function updateAll(req) {
21-
return await PaymentService.updateAll(req.currentUser);
21+
return await CopilotPaymentService.updateAll(req.currentUser);
2222
}
2323

2424
/**
@@ -28,12 +28,12 @@ async function updateAll(req) {
2828
* @returns {Object} the result
2929
*/
3030
async function getAll(req) {
31-
const payments = await PaymentService.getAll(req.query);
31+
const payments = await CopilotPaymentService.getAll(req.query, req.currentUser);
3232
const active = [];
3333
const closed = [];
3434

3535
payments.forEach(function (payment) {
36-
if (payment.closed === "true") {
36+
if (payment.closed === true) {
3737
closed.push(payment);
3838
} else {
3939
active.push(payment);
@@ -49,7 +49,7 @@ async function getAll(req) {
4949
* @returns {Object} the result
5050
*/
5151
async function create(req) {
52-
return await PaymentService.create(req.currentUser, req.body.payment);
52+
return await CopilotPaymentService.create(req.currentUser, req.body.payment);
5353
}
5454

5555
/**
@@ -59,7 +59,7 @@ async function create(req) {
5959
* @returns {Object} the result
6060
*/
6161
async function update(req) {
62-
return await PaymentService.update(req.currentUser, req.body.payment);
62+
return await CopilotPaymentService.update(req.currentUser, req.body.payment);
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ async function update(req) {
6969
* @returns {Object} the result
7070
*/
7171
async function remove(req) {
72-
return await PaymentService.remove(req.params.id, req.currentUser);
72+
return await CopilotPaymentService.remove(req.params.id, req.currentUser);
7373
}
7474

7575

Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
'use strict';
22

33
angular.module('topcoderX')
4-
.controller('AddPaymentController', ['$scope', '$log', '$state', 'PaymentService', 'ProjectService', '$filter', '$rootScope', '$timeout', 'Alert',
5-
function ($scope, $log, $state, PaymentService, ProjectService, $filter, $rootScope, $timeout, Alert) {
4+
.controller('AddCopilotPaymentController', ['$scope', '$log', '$state', 'CopilotPaymentService', 'ProjectService', '$filter', '$rootScope', '$timeout', 'Alert',
5+
function ($scope, $log, $state, CopilotPaymentService, ProjectService, $filter, $rootScope, $timeout, Alert) {
66
// below logic is trying to identify whether we are editing a payment
77
$scope.editing = true;
88
$scope.projects = [];
99
$scope.payment = {
1010
project: null,
1111
amount: null,
1212
description: '',
13-
challenge: '',
1413
};
1514
if ($rootScope.payment) {
1615
$scope.title = 'Edit a Payment';
17-
$scope.payment = $rootScope.payment;
16+
$scope.payment = angular.copy($rootScope.payment);
1817
$scope.payment.id = $rootScope.payment.id;
18+
$scope.payment.project = $rootScope.payment.project.id;
1919
$scope.editing = true;
2020
} else {
2121
$scope.title = 'Add a Payment';
@@ -27,49 +27,40 @@ angular.module('topcoderX')
2727
ProjectService.getProjects().then(function (response) {
2828
$scope.projects = response.data;
2929
}).catch(function (error) {
30-
_handleError({
31-
data:
32-
{ error: error, message: 'There are not projects in Topcoder-X. Please create a project first.' }
33-
});
30+
_handleError(error, 'There are no projects in Topcoder-X. Please create a project first.');
3431
});
3532
};
3633

3734
$scope.getProjects();
3835

3936
// handle error output
40-
function _handleError(error, defualtMsg) {
41-
const errMsg = error.data ? error.data.message : defualtMsg;
42-
Alert(errMsg, $scope);
37+
function _handleError(error, defaultMsg) {
38+
const errMsg = error.data ? error.data.message : defaultMsg;
39+
Alert.error(errMsg, $scope);
4340
}
4441

4542
// create/update payment item
4643
$scope.save = function () {
4744
if (!$scope.editing) {
48-
PaymentService.create($scope.payment).then(function (res) {
49-
$log.info(res);
45+
CopilotPaymentService.create($scope.payment).then(function () {
5046
$state.go('app.copilotPayments');
51-
}).catch(function () {
52-
Alert.error('Error Creating Payment', $scope);
47+
}).catch(function (error) {
48+
_handleError(error, 'An error occurred while creating Payment.');
5349
});
5450
}
5551
if ($scope.editing) {
56-
PaymentService.update({
52+
CopilotPaymentService.update({
5753
id: $scope.payment.id,
5854
project: $scope.payment.project,
5955
amount: $scope.payment.amount,
6056
description: $scope.payment.description,
61-
challenge: $scope.payment.challenge,
62-
closed: $scope.payment.closed
63-
}).then(function (res) {
64-
$timeout(function () {
65-
$log.info(res);
66-
$rootScope.payment = null;
67-
$state.go('app.copilotPayments');
68-
}, 6000);
69-
}).catch(function () {
70-
Alert.error('Error Updating Payment', $scope);
57+
}).then(function () {
58+
$rootScope.payment = null;
59+
$state.go('app.copilotPayments');
60+
}).catch(function (error) {
61+
_handleError(error, 'An error occurred while updating Payment.');
7162
});
7263
}
73-
};
64+
};
7465
}
7566
]);

src/front/src/app/add-payment/add-payment.html renamed to src/front/src/app/add-copilot-payment/add-copilot-payment.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div ng-controller="AddPaymentController">
1+
<div ng-controller="AddCopilotPaymentController">
22
<div class="col-md-10 col-md-offset-1" ng-include src="'components/alert/alert.html'"></div>
33
<div class="row wrapper border-bottom white-bg page-heading">
44
<div class="col-lg-4">
@@ -21,14 +21,10 @@ <h2>{{title}}</h2>
2121
<input class="form-control" type="number" ng-model="payment.amount" required/>
2222
<span ng-show="paymentForm.payment.amount.$touched && paymentForm.payment.amount.$invalid">The payment Amount is required.</span>
2323
<br />
24-
<label class="form-label">Desciption:</label>
24+
<label class="form-label">Description:</label>
2525
<input class="form-control" type="text" ng-model="payment.description" required/>
2626
<span ng-show="paymentForm.payment.description.$touched && paymentForm.payment.description.$invalid">The payment Description is required.</span>
2727
<br />
28-
<label class="form-label">Challenge:</label>
29-
<input class="form-control" type="number" ng-model="payment.challenge" required/>
30-
<span ng-show="paymentForm.payment.challenge.$touched && paymentForm.payment.challenge.$invalid">The payment Challenge is required.</span>
31-
<br />
3228
<br />
3329
<button type="submit" class="with-button btn btn-sm btn-info" ng-click="paymentForm.$valid && save()">
3430
<strong>

src/front/src/app/add-payment/add-payment-service.js

-55
This file was deleted.

src/front/src/app/app.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ angular.module('topcoderX', [
137137
resolve: { auth: authenticate }
138138
})
139139
.state('app.addPayment', {
140-
url: '/add-payment',
141-
templateUrl: 'app/add-payment/add-payment.html',
142-
controller: 'AddPaymentController',
140+
url: '/copilot-payment',
141+
templateUrl: 'app/add-copilot-payment/add-copilot-payment.html',
142+
controller: 'AddCopilotPaymentController',
143143
controllerAs: 'vm',
144144
resolve: { auth: authenticate }
145145
});

src/front/src/app/copilot-payments/copilot-payment.service.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
angular.module('topcoderX')
9-
.factory('PaymentService', ['$http', 'Helper', function ($http, Helper) {
9+
.factory('CopilotPaymentService', ['$http', 'Helper', function ($http, Helper) {
1010
var baseUrl = Helper.baseUrl;
1111
var service = {};
1212

@@ -15,7 +15,7 @@ angular.module('topcoderX')
1515
*
1616
*/
1717
service.updateAll = function () {
18-
return $http.post(baseUrl + '/api/v1/payments/updates/').then(function (response) {
18+
return $http.post(baseUrl + '/api/v1/payments/copilot/updates/').then(function (response) {
1919
return response;
2020
});
2121
};
@@ -25,7 +25,7 @@ angular.module('topcoderX')
2525
*
2626
*/
2727
service.getAll = function (query) {
28-
return $http.get(baseUrl + '/api/v1/payments?sortBy=' + query).then(function (response) {
28+
return $http.get(baseUrl + '/api/v1/payments/copilot?sortBy=' + query).then(function (response) {
2929
return response;
3030
});
3131
};
@@ -35,7 +35,7 @@ angular.module('topcoderX')
3535
*
3636
*/
3737
service.create = function (bodyParam) {
38-
return $http.post(baseUrl + '/api/v1/payments/', { payment: bodyParam }).then(function (response) {
38+
return $http.post(baseUrl + '/api/v1/payments/copilot/', { payment: bodyParam }).then(function (response) {
3939
return response;
4040
});
4141
};
@@ -45,7 +45,7 @@ angular.module('topcoderX')
4545
*
4646
*/
4747
service.update = function (bodyParam) {
48-
return $http.put(baseUrl + '/api/v1/payments/', { payment: bodyParam }).then(function (response) {
48+
return $http.put(baseUrl + '/api/v1/payments/copilot/', { payment: bodyParam }).then(function (response) {
4949
return response;
5050
});
5151
};
@@ -55,7 +55,7 @@ angular.module('topcoderX')
5555
*
5656
*/
5757
service.delete = function (id) {
58-
return $http.delete(baseUrl + '/api/v1/payments/' + (id || '')).then(function (response) {
58+
return $http.delete(baseUrl + '/api/v1/payments/copilot/' + id).then(function (response) {
5959
return response.data;
6060
});
6161
};

0 commit comments

Comments
 (0)