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

Commit 9e370ae

Browse files
committed
1 parent fb55cbb commit 9e370ae

File tree

10 files changed

+58
-16
lines changed

10 files changed

+58
-16
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: configuration.md

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The following config parameters are supported, they are defined in `src/config.j
3434
|IS_LOCAL | Use Amazon DynamoDB Local or server. |true |
3535
|AWS_CONNECTION_TIMEOUT | The timeout used to check if the app is healthy. |10000 |
3636
|TC_LOGIN_URL | TC login url | |
37+
|DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT | Dynamodb wait for active timeout |10 minutes |
38+
3739

3840
## GitHub OAuth App Setup
3941

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"parse-domain": "^2.1.2",
8181
"shortid": "^2.2.8",
8282
"ssl-express-www": "^3.0.3",
83-
"superagent": "^3.6.0",
83+
"superagent": "^6.1.0",
8484
"superagent-promise": "^1.1.0",
8585
"typescript": "~2.3.3",
8686
"uuid": "^3.3.2",

Diff for: src/common/helper.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const Joi = require('joi');
1616
const getParams = require('get-parameter-names');
1717
const bluebird = require('bluebird');
1818
const bcrypt = require('bcryptjs');
19+
const moment = require('moment');
1920
const parseDomain = require('parse-domain');
2021
const config = require('../config');
2122
const logger = require('./logger');
@@ -147,9 +148,9 @@ function convertGitHubError(err, message) {
147148
*/
148149
function convertGitLabError(err, message) {
149150
let resMsg = `${message}. ${err.message}.\n`;
150-
const detail = _.get(err, 'response.body.message');
151+
const detail = _.get(err, 'response.body.message') || _.get(err, 'response.text');
151152
if (detail) {
152-
resMsg += ` Detail: ${detail}`;
153+
resMsg += ` Detail: ${JSON.stringify(detail)}`;
153154
}
154155
const apiError = new errors.ApiError(
155156
err.status || _.get(err, 'response.status', constants.SERVICE_ERROR_STATUS),
@@ -252,6 +253,16 @@ function hashCode(s) {
252253
}, 0);
253254
}
254255

256+
/**
257+
* Check if expires_at is valid
258+
*
259+
* @param {String} expiresAt the date str yyyy-MM-dd
260+
* @returns {Boolean} valid or not
261+
*/
262+
function isValidGitlabExpiresDate(expiresAt) {
263+
return moment(expiresAt, 'YYYY-MM-DD', true).isValid();
264+
}
265+
255266
module.exports = {
256267
buildService,
257268
buildController,
@@ -261,5 +272,6 @@ module.exports = {
261272
generateIdentifier,
262273
getProviderType,
263274
getProjectCopilotOrOwner,
264-
hashCode
275+
hashCode,
276+
isValidGitlabExpiresDate
265277
};

Diff for: src/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
TC_LOGIN_URL: process.env.TC_LOGIN_URL || 'https://accounts.topcoder.com/member',
6666
},
6767
},
68+
DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT: process.env.DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT || 1000 * 60 * 10 // eslint-disable-line no-magic-numbers
6869
};
6970

7071
module.exports.frontendConfigs = {

Diff for: src/front/src/app/git-access-control/access-control.html

+16-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h2>Git Access Control</h2>
1717
<div ng-if="settings.github==true">
1818
<div ng-show="tableConfig.github.initialized">
1919
<div ng-if="tableConfig.github.items.length!=0 || tableConfig.github.allItems.length!=0" class="row">
20-
<div class="col-lg-3">
20+
<div class="col-lg-4">
2121
<div class="input-group custom-search-form">
2222
<input ng-model="searchText" type="text" class="form-control" placeholder="Find teams" ng-change="onSearchChange('github', this)">
2323
<span class="input-group-btn">
@@ -27,6 +27,7 @@ <h2>Git Access Control</h2>
2727
</span>
2828
</div>
2929
</div>
30+
<div class="col-lg-6 h5">Don't see your team? Make sure you have 'Maintainer' rights.</div>
3031
</div>
3132
<table ng-if="tableConfig.github.items.length!=0 || tableConfig.github.allItems.length!=0" class="footable table table-stripped toggle-arrow-tiny">
3233
<thead>
@@ -39,8 +40,14 @@ <h2>Git Access Control</h2>
3940
</thead>
4041
<tbody>
4142
<tr ng-repeat="item in tableConfig.github.items" ng-class-even="'footable-even'" ng-class-odd="'footable-odd'">
42-
<td class="col-lg-2">{{item.name}}</td>
43-
<td class="col-lg-2">{{item.organization.login}}</td>
43+
<td class="col-lg-2">
44+
<a href="{{item.html_url}}"
45+
target="_blank">{{item.name}}</a>
46+
</td>
47+
<td class="col-lg-2">
48+
<a href="{{item.organization.html_url}}"
49+
target="_blank">{{item.organization.login}}</a>
50+
</td>
4451
<td class="col-lg-2">
4552
<button class="btn btn-sm btn-success" ng-hide="item.gettingLink" ng-click="getSharableLink(item, 'github')">
4653
<strong>Get Link</strong>
@@ -116,7 +123,7 @@ <h2>Git Access Control</h2>
116123
<div ng-if="settings.gitlab==true">
117124
<div ng-show="tableConfig.gitlab.initialized">
118125
<div ng-if="tableConfig.gitlab.items.length!=0 || tableConfig.gitlab.allItems.length!=0" class="row">
119-
<div class="col-lg-3">
126+
<div class="col-lg-4">
120127
<div class="input-group custom-search-form">
121128
<input ng-model="searchText" type="text" class="form-control" placeholder="Find groups" ng-change="onSearchChange('gitlab', this)">
122129
<span class="input-group-btn">
@@ -126,6 +133,7 @@ <h2>Git Access Control</h2>
126133
</span>
127134
</div>
128135
</div>
136+
<div class="col-lg-6 h5">Don't see your group? Make sure you have 'Owner' rights.</div>
129137
</div>
130138
<table ng-show="tableConfig.gitlab.items.length!=0 || tableConfig.gitlab.allItems.length!=0" class="footable table table-stripped toggle-arrow-tiny">
131139
<thead>
@@ -136,7 +144,10 @@ <h2>Git Access Control</h2>
136144
</thead>
137145
<tbody>
138146
<tr ng-repeat="item in tableConfig.gitlab.items" ng-class-even="'footable-even'" ng-class-odd="'footable-odd'">
139-
<td class="col-lg-2">{{item.name}}</td>
147+
<td class="col-lg-2">
148+
<a href="{{item.web_url}}"
149+
target="_blank">{{item.name}}</a>
150+
</td>
140151
<td class="col-lg-2">
141152
<button class="btn btn-sm btn-success" ng-hide="item.gettingLink" ng-click="getSharableLink(item, 'gitlab')">
142153
<strong>Get Link</strong>

Diff for: src/front/src/app/git-access-control/git-access-dialog.controller.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ angular.module('topcoderX').controller('GitAccessDialogController', [
1313
$scope.provider = provider;
1414
$scope.accessLevel = '';
1515
$scope.expiredAt = '';
16+
$scope.invalidExpiredAt = false;
1617
if ($scope.provider === 'github') {
1718
$scope.accessLevel = 'member';
1819
} else {
@@ -38,10 +39,15 @@ angular.module('topcoderX').controller('GitAccessDialogController', [
3839
* Set changes to father controller
3940
*/
4041
$scope.setChanges = function () {
41-
$uibModalInstance.close({
42-
accessLevel: $scope.accessLevel,
43-
expiredAt: $scope.expiredAt
44-
});
42+
if ($scope.expiredAt && !isValidDate($scope.expiredAt)) {
43+
$scope.invalidExpiredAt = true
44+
}
45+
else {
46+
$uibModalInstance.close({
47+
accessLevel: $scope.accessLevel,
48+
expiredAt: $scope.expiredAt
49+
});
50+
}
4551
};
4652

4753
/**
@@ -50,5 +56,10 @@ angular.module('topcoderX').controller('GitAccessDialogController', [
5056
$scope.close = function () {
5157
$uibModalInstance.close();
5258
};
59+
60+
// Validates that the input string is a valid date formatted as "yyyy-MM-dd"
61+
function isValidDate(dateString) {
62+
return /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/.test(dateString)
63+
};
5364
},
5465
]);

Diff for: src/front/src/app/git-access-control/git-access-dialog.html

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h4 class="modal-title" id="reg-dialog-label">Configure Access Level and Valid P
2424
<datepicker ng-if="provider === 'gitlab'" date-format="yyyy-MM-dd" date-min-limit="{{dateLimit}}">
2525
<input class="form-control" ng-model="expiredAt" type="text" ng-change="updateExpired(expiredAt)"/>
2626
</datepicker>
27+
<div ng-if="invalidExpiredAt === true">Invalid Expired At. Correct format is yyyy-MM-dd</div>
2728
</div>
2829
</div>
2930
<div class="modal-footer">

Diff for: src/models/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ if (config.DYNAMODB.IS_LOCAL === 'true') {
2424
dynamoose.setDefaults({
2525
create: false,
2626
update: false,
27+
waitForActiveTimeout: config.DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT
2728
});
2829

2930
if (process.env.CREATE_DB) {
3031
dynamoose.setDefaults({
3132
create: true,
3233
update: true,
34+
waitForActiveTimeout: config.DYNAMODB_WAIT_TABLE_FOR_ACTIVE_TIMEOUT
3335
});
3436
}
3537

Diff for: src/services/GitlabService.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,14 @@ async function addGroupMember(groupId, ownerUserToken, normalUserToken, accessLe
200200
}
201201

202202
let body = `user_id=${userId}&access_level=${accessLevel}`;
203-
if (expiredAt) {
204-
body = body + `&expires_at=${expiredAt} `;
203+
if (expiredAt && helper.isValidGitlabExpiresDate(expiredAt)) {
204+
body = body + `&expires_at=${expiredAt}`;
205205
}
206206
// add user to group
207207
await request
208208
.post(`${config.GITLAB_API_BASE_URL}/api/v4/groups/${groupId}/members`)
209209
.set('Authorization', `Bearer ${ownerUserToken}`)
210+
.set('Content-Type', 'application/x-www-form-urlencoded')
210211
.send(body)
211212
.end();
212213
// return gitlab username
@@ -219,7 +220,8 @@ async function addGroupMember(groupId, ownerUserToken, normalUserToken, accessLe
219220
if (err instanceof errors.ApiError) {
220221
throw err;
221222
}
222-
throw helper.convertGitLabError(err, 'Failed to add group member');
223+
throw helper.convertGitLabError(
224+
err, `Failed to add group member userId=${userId} accessLevel=${accessLevel} expiredAt=${expiredAt}`);
223225
}
224226
return {username, id: userId};
225227
}

0 commit comments

Comments
 (0)