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

Commit 682180b

Browse files
authored
Merge pull request #224 from afrisalyp/issue-219
Issue 219
2 parents 015a407 + f9b6b0d commit 682180b

15 files changed

+155
-164
lines changed

gulp/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ gulp.task('lint', () => {
113113
.pipe(eslint.failAfterError());
114114
});
115115

116-
gulp.task('build', ['ng-config', 'lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']);
116+
gulp.task('build', ['lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']);
117117
gulp.task('build:watch', ['watch:build']);

gulp/ng-config.js

-16
This file was deleted.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
"gulp-load-plugins": "^2.0.1",
122122
"gulp-minify-html": "~1.0.6",
123123
"gulp-ng-annotate": "~1.0.0",
124-
"gulp-ng-config": "^1.5.1",
125124
"gulp-protractor": "^4.1.1",
126125
"gulp-rename": "~1.2.0",
127126
"gulp-replace": "~0.5.0",

src/config.js

+105
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,108 @@ module.exports = {
6868
},
6969
},
7070
};
71+
72+
const frontendConfigs = {
73+
"local":{
74+
"JWT_V3_NAME":"v3jwt",
75+
"JWT_V2_NAME":"tcjwt",
76+
"COOKIES_SECURE":false,
77+
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
78+
"TC_USER_PROFILE_URL": "http://api.topcoder-dev.com/v2/user/profile",
79+
"API_URL": "https://127.0.0.1:8443",
80+
"ADMIN_TOOL_URL": "http://localhost:8080/api/v2",
81+
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
82+
"DIRECT_URL_BASE": "https://www.topcoder-dev/direct/projectOverview?formData.projectId=",
83+
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
84+
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
85+
"TOPCODER_URL": "https://topcoder-dev.com",
86+
"GITHUB_TEAM_URL": "https://github.com/orgs/",
87+
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
88+
89+
},
90+
"heroku":{
91+
"JWT_V3_NAME":"v3jwt",
92+
"JWT_V2_NAME":"tcjwt",
93+
"COOKIES_SECURE":false,
94+
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
95+
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
96+
"API_URL": "https://api.topcoder-dev.com",
97+
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
98+
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
99+
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
100+
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
101+
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
102+
"TOPCODER_URL": "https://topcoder-dev.com",
103+
"GITHUB_TEAM_URL": "https://github.com/orgs/",
104+
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
105+
},
106+
"dev":{
107+
"JWT_V3_NAME":"v3jwt",
108+
"JWT_V2_NAME":"tcjwt",
109+
"COOKIES_SECURE":false,
110+
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
111+
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
112+
"API_URL": "https://api.topcoder-dev.com",
113+
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
114+
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
115+
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
116+
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
117+
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
118+
"TOPCODER_URL": "https://topcoder-dev.com",
119+
"GITHUB_TEAM_URL": "https://github.com/orgs/",
120+
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
121+
},
122+
"qa":{
123+
"JWT_V3_NAME":"v3jwt",
124+
"JWT_V2_NAME":"tcjwt",
125+
"COOKIES_SECURE":false,
126+
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
127+
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
128+
"API_URL": "https://api.topcoder-qa.com",
129+
"ADMIN_TOOL_URL": "https://api.topcoder-qa.com/v2",
130+
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-qa.com/connector.html",
131+
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
132+
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
133+
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
134+
"TOPCODER_URL": "https://topcoder-dev.com",
135+
"GITHUB_TEAM_URL": "https://github.com/orgs/",
136+
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
137+
},
138+
"prod":{
139+
"JWT_V3_NAME":"v3jwt",
140+
"JWT_V2_NAME":"tcjwt",
141+
"COOKIES_SECURE":false,
142+
"TC_LOGIN_URL": "https://accounts.topcoder.com/member",
143+
"TC_USER_PROFILE_URL": "https://api.topcoder.com/v2/user/profile",
144+
"API_URL": "https://api.topcoder.com",
145+
"ADMIN_TOOL_URL": "https://api.topcoder.com/v2",
146+
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder.com/connector.html",
147+
"DIRECT_URL_BASE": "https://www.topcoder.com/direct/projectOverview?formData.projectId=",
148+
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
149+
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
150+
"TOPCODER_URL": "https://topcoder-dev.com",
151+
"GITHUB_TEAM_URL": "https://github.com/orgs/",
152+
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
153+
}
154+
};
155+
156+
const activeEnv = module.exports.TOPCODER_ENV;
157+
module.exports.frontendConfigs = {
158+
helpLink: module.exports.HELP_LINK,
159+
copilotRole: module.exports.COPILOT_ROLE,
160+
administratorRoles: module.exports.ADMINISTRATOR_ROLES,
161+
JWT_V3_NAME: process.env.JWT_V3_NAME || frontendConfigs[activeEnv].JWT_V3_NAME,
162+
JWT_V2_NAME: process.env.JWT_V2_NAME || frontendConfigs[activeEnv].JWT_V2_NAME,
163+
COOKIES_SECURE: process.env.COOKIES_SECURE || frontendConfigs[activeEnv].COOKIES_SECURE,
164+
TC_LOGIN_URL: process.env.TC_LOGIN_URL || frontendConfigs[activeEnv].TC_LOGIN_URL,
165+
TC_USER_PROFILE_URL: process.env.TC_USER_PROFILE_URL || frontendConfigs[activeEnv].TC_USER_PROFILE_URL,
166+
API_URL: process.env.API_URL || frontendConfigs[activeEnv].API_URL,
167+
ADMIN_TOOL_URL: process.env.ADMIN_TOOL_URL || frontendConfigs[activeEnv].ADMIN_TOOL_URL,
168+
ACCOUNTS_CONNECTOR_URL: process.env.ACCOUNTS_CONNECTOR_URL || frontendConfigs[activeEnv].ACCOUNTS_CONNECTOR_URL,
169+
DIRECT_URL_BASE: process.env.DIRECT_URL_BASE || frontendConfigs[activeEnv].DIRECT_URL_BASE,
170+
OWNER_LOGIN_GITHUB_URL: process.env.OWNER_LOGIN_GITHUB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITHUB_URL,
171+
OWNER_LOGIN_GITLAB_URL: process.env.OWNER_LOGIN_GITLAB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITLAB_URL,
172+
TOPCODER_URL: process.env.TOPCODER_URL || frontendConfigs[activeEnv].TOPCODER_URL,
173+
GITHUB_TEAM_URL: process.env.GITHUB_TEAM_URL || frontendConfigs[activeEnv].GITHUB_TEAM_URL,
174+
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || frontendConfigs[activeEnv].GITLAB_GROUP_URL
175+
};

src/front/config.json

-83
This file was deleted.

src/front/src/app/app.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ angular.module('topcoderX', [
1111
'ngResource',
1212
'ui.router',
1313
'ui.bootstrap',
14-
'app.constants',
1514
'angular-clipboard',
1615
'angular-jwt'])
1716
// In the run phase of your Angular application
@@ -52,7 +51,9 @@ angular.module('topcoderX', [
5251
});
5352
}],
5453
currentUser: ['AuthService', function (AuthService) {
55-
return AuthService.getCurrentUser();
54+
return AuthService.getAppConfig().then(function () {
55+
return AuthService.getCurrentUser();
56+
});
5657
}],
5758

5859
}
@@ -63,11 +64,10 @@ angular.module('topcoderX', [
6364
templateUrl: 'components/common/content.html',
6465
resolve: {
6566
currentUser: ['AuthService', function (AuthService) {
66-
return AuthService.getCurrentUser();
67-
}],
68-
AppConfig: ['AuthService', function (AuthService) {
69-
return AuthService.getAppConfig();
70-
}],
67+
return AuthService.getAppConfig().then(function () {
68+
return AuthService.getCurrentUser();
69+
});
70+
}]
7171
},
7272
})
7373
.state('app.main', {

src/front/src/app/auth/auth.config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ angular.module('topcoderX')
3131
jwtInterceptorProvider.tokenGetter = [
3232
'AuthService', '$http', 'Helper', '$rootScope', 'config',
3333
function (AuthService, $http, Helper, $rootScope, config) {
34+
if (!$rootScope.appConfig) return;
3435
// token V2 for API V2
35-
if (config.url.indexOf(Helper.config().ADMIN_TOOL_URL) > -1) {
36+
if (config.url.indexOf($rootScope.appConfig.ADMIN_TOOL_URL) > -1) {
3637
if (AuthService.getTokenV2()) {
3738
return AuthService.getTokenV2();
3839
}
@@ -45,7 +46,7 @@ angular.module('topcoderX')
4546
if (refreshingToken === null) {
4647
refreshingToken = $http({
4748
method: 'GET',
48-
url: Helper.config().API_URL + "/v3/authorizations/1",
49+
url: $rootScope.appConfig.API_URL + "/v3/authorizations/1",
4950
headers: {
5051
'Authorization': "Bearer " + currentToken
5152
}

src/front/src/app/auth/auth.service.js

+23-21
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
angular.module('topcoderX')
44
.factory('AuthService', [
5-
'$q', '$log', 'jwtHelper', '$cookies', '$window', '$state', '$rootScope', '$http',
6-
'COOKIES_SECURE', 'JWT_V3_NAME', 'JWT_V2_NAME', 'Helper',
7-
function ($q, $log, jwtHelper, $cookies, $window, $state, $rootScope, $http,
8-
COOKIES_SECURE, JWT_V3_NAME, JWT_V2_NAME, Helper) {
5+
'$q', '$log', 'jwtHelper', '$cookies', '$window', '$state', '$rootScope', '$http', 'Helper',
6+
function ($q, $log, jwtHelper, $cookies, $window, $state, $rootScope, $http, Helper) {
97
// these constants are for AuthService internal usage only
108
// they don't depend on the environment thus don't have to be placed in global config
9+
1110
var GET_FRESH_TOKEN_REQUEST = 'GET_FRESH_TOKEN_REQUEST';
1211
var GET_FRESH_TOKEN_SUCCESS = 'GET_FRESH_TOKEN_SUCCESS';
1312
var GET_FRESH_TOKEN_FAILURE = 'GET_FRESH_TOKEN_FAILURE';
@@ -153,14 +152,14 @@ angular.module('topcoderX')
153152
AuthService.logginOut = null;
154153
// remove only token V3, which we set from the script manually
155154
// token V2 will be removed automatically during logout server request
156-
$cookies.remove(JWT_V3_NAME, { path: '/' });
155+
$cookies.remove($rootScope.appConfig.JWT_V3_NAME, { path: '/' });
157156
});
158157

159158
return AuthService.logginOut;
160159
}
161160

162161
AuthService.login = function () {
163-
$window.location.href = Helper.config().TC_LOGIN_URL + '?retUrl=' + encodeURIComponent($window.location.href);
162+
$window.location.href = $rootScope.appConfig.TC_LOGIN_URL + '?retUrl=' + encodeURIComponent($window.location.href);
164163
}
165164

166165
/**
@@ -170,7 +169,7 @@ angular.module('topcoderX')
170169
AuthService.init = function () {
171170
// add hidden iframe which is used to get API v3 token
172171
configureConnector({
173-
connectorUrl: Helper.config().ACCOUNTS_CONNECTOR_URL,
172+
connectorUrl: $rootScope.appConfig ? $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL : null,
174173
frameId: 'tc-accounts-iframe',
175174
});
176175
}
@@ -219,15 +218,15 @@ angular.module('topcoderX')
219218
* @return {String} token v3
220219
*/
221220
AuthService.getTokenV3 = function () {
222-
return $cookies.get(JWT_V3_NAME);
221+
return $cookies.get($rootScope.appConfig.JWT_V3_NAME);
223222
}
224223

225224
/**
226225
* Save token V3 to cookies
227226
*/
228227
AuthService.setTokenV3 = function (token) {
229-
return $cookies.put(JWT_V3_NAME, token, {
230-
secure: COOKIES_SECURE,
228+
return $cookies.put($rootScope.appConfig.JWT_V3_NAME, token, {
229+
secure: $rootScope.appConfig.COOKIES_SECURE,
231230
});
232231
}
233232

@@ -246,7 +245,7 @@ angular.module('topcoderX')
246245
* @return {String} token v2
247246
*/
248247
AuthService.getTokenV2 = function () {
249-
return $cookies.get(JWT_V2_NAME);
248+
return $cookies.get($rootScope.appConfig.JWT_V2_NAME);
250249
}
251250

252251
/**
@@ -282,17 +281,20 @@ angular.module('topcoderX')
282281
* gets the application configurations
283282
*/
284283
AuthService.getAppConfig = function () {
285-
var tctV3 = AuthService.getTokenV3();
286-
287-
if (!tctV3) {
288-
return null;
284+
if ($rootScope.appConfig) {
285+
return $q.resolve($rootScope.appConfig);
289286
}
290-
return $http.get(Helper.baseUrl + '/api/v1/appConfig').then(function (res) {
291-
$rootScope.appConfig = res.data;
292-
return $q.resolve(res.data);
293-
}).catch(function (err) {
294-
return $q.reject(err);
295-
});
287+
return $http.get(Helper.baseUrl + '/api/v1/appConfig')
288+
.then(function (res) {
289+
$rootScope.appConfig = res.data;
290+
if (connectorIFrame && !connectorIFrame.src) {
291+
connectorIFrame.src = $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL;
292+
url = $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL;
293+
}
294+
return $q.resolve(res.data);
295+
}).catch(function (err) {
296+
return $q.reject(err);
297+
});
296298
};
297299

298300
return AuthService;

0 commit comments

Comments
 (0)