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

Issue 219 #224

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gulp/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ gulp.task('lint', () => {
.pipe(eslint.failAfterError());
});

gulp.task('build', ['ng-config', 'lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']);
gulp.task('build', ['lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']);
gulp.task('build:watch', ['watch:build']);
16 changes: 0 additions & 16 deletions gulp/ng-config.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
"gulp-load-plugins": "^2.0.1",
"gulp-minify-html": "~1.0.6",
"gulp-ng-annotate": "~1.0.0",
"gulp-ng-config": "^1.5.1",
"gulp-protractor": "^4.1.1",
"gulp-rename": "~1.2.0",
"gulp-replace": "~0.5.0",
Expand Down
105 changes: 105 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,108 @@ module.exports = {
},
},
};

const frontendConfigs = {
"local":{
"JWT_V3_NAME":"v3jwt",
"JWT_V2_NAME":"tcjwt",
"COOKIES_SECURE":false,
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
"TC_USER_PROFILE_URL": "http://api.topcoder-dev.com/v2/user/profile",
"API_URL": "https://127.0.0.1:8443",
"ADMIN_TOOL_URL": "http://localhost:8080/api/v2",
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
"DIRECT_URL_BASE": "https://www.topcoder-dev/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"

},
"heroku":{
"JWT_V3_NAME":"v3jwt",
"JWT_V2_NAME":"tcjwt",
"COOKIES_SECURE":false,
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
"API_URL": "https://api.topcoder-dev.com",
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"dev":{
"JWT_V3_NAME":"v3jwt",
"JWT_V2_NAME":"tcjwt",
"COOKIES_SECURE":false,
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
"API_URL": "https://api.topcoder-dev.com",
"ADMIN_TOOL_URL": "https://api.topcoder-dev.com/v2",
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-dev.com/connector.html",
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"qa":{
"JWT_V3_NAME":"v3jwt",
"JWT_V2_NAME":"tcjwt",
"COOKIES_SECURE":false,
"TC_LOGIN_URL": "https://accounts.topcoder-dev.com/member",
"TC_USER_PROFILE_URL": "https://api.topcoder-dev.com/v2/user/profile",
"API_URL": "https://api.topcoder-qa.com",
"ADMIN_TOOL_URL": "https://api.topcoder-qa.com/v2",
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder-qa.com/connector.html",
"DIRECT_URL_BASE": "https://www.topcoder-dev.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
},
"prod":{
"JWT_V3_NAME":"v3jwt",
"JWT_V2_NAME":"tcjwt",
"COOKIES_SECURE":false,
"TC_LOGIN_URL": "https://accounts.topcoder.com/member",
"TC_USER_PROFILE_URL": "https://api.topcoder.com/v2/user/profile",
"API_URL": "https://api.topcoder.com",
"ADMIN_TOOL_URL": "https://api.topcoder.com/v2",
"ACCOUNTS_CONNECTOR_URL": "https://accounts.topcoder.com/connector.html",
"DIRECT_URL_BASE": "https://www.topcoder.com/direct/projectOverview?formData.projectId=",
"OWNER_LOGIN_GITHUB_URL":"/api/v1/github/owneruser/login",
"OWNER_LOGIN_GITLAB_URL":"/api/v1/gitlab/owneruser/login",
"TOPCODER_URL": "https://topcoder-dev.com",
"GITHUB_TEAM_URL": "https://github.com/orgs/",
"GITLAB_GROUP_URL": "https://gitlab.com/groups/"
}
};

const activeEnv = module.exports.TOPCODER_ENV;
module.exports.frontendConfigs = {
helpLink: module.exports.HELP_LINK,
copilotRole: module.exports.COPILOT_ROLE,
administratorRoles: module.exports.ADMINISTRATOR_ROLES,
JWT_V3_NAME: process.env.JWT_V3_NAME || frontendConfigs[activeEnv].JWT_V3_NAME,
JWT_V2_NAME: process.env.JWT_V2_NAME || frontendConfigs[activeEnv].JWT_V2_NAME,
COOKIES_SECURE: process.env.COOKIES_SECURE || frontendConfigs[activeEnv].COOKIES_SECURE,
TC_LOGIN_URL: process.env.TC_LOGIN_URL || frontendConfigs[activeEnv].TC_LOGIN_URL,
TC_USER_PROFILE_URL: process.env.TC_USER_PROFILE_URL || frontendConfigs[activeEnv].TC_USER_PROFILE_URL,
API_URL: process.env.API_URL || frontendConfigs[activeEnv].API_URL,
ADMIN_TOOL_URL: process.env.ADMIN_TOOL_URL || frontendConfigs[activeEnv].ADMIN_TOOL_URL,
ACCOUNTS_CONNECTOR_URL: process.env.ACCOUNTS_CONNECTOR_URL || frontendConfigs[activeEnv].ACCOUNTS_CONNECTOR_URL,
DIRECT_URL_BASE: process.env.DIRECT_URL_BASE || frontendConfigs[activeEnv].DIRECT_URL_BASE,
OWNER_LOGIN_GITHUB_URL: process.env.OWNER_LOGIN_GITHUB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITHUB_URL,
OWNER_LOGIN_GITLAB_URL: process.env.OWNER_LOGIN_GITLAB_URL || frontendConfigs[activeEnv].OWNER_LOGIN_GITLAB_URL,
TOPCODER_URL: process.env.TOPCODER_URL || frontendConfigs[activeEnv].TOPCODER_URL,
GITHUB_TEAM_URL: process.env.GITHUB_TEAM_URL || frontendConfigs[activeEnv].GITHUB_TEAM_URL,
GITLAB_GROUP_URL: process.env.GITLAB_GROUP_URL || frontendConfigs[activeEnv].GITLAB_GROUP_URL
};
83 changes: 0 additions & 83 deletions src/front/config.json

This file was deleted.

14 changes: 7 additions & 7 deletions src/front/src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ angular.module('topcoderX', [
'ngResource',
'ui.router',
'ui.bootstrap',
'app.constants',
'angular-clipboard',
'angular-jwt'])
// In the run phase of your Angular application
Expand Down Expand Up @@ -52,7 +51,9 @@ angular.module('topcoderX', [
});
}],
currentUser: ['AuthService', function (AuthService) {
return AuthService.getCurrentUser();
return AuthService.getAppConfig().then(function () {
return AuthService.getCurrentUser();
});
}],

}
Expand All @@ -63,11 +64,10 @@ angular.module('topcoderX', [
templateUrl: 'components/common/content.html',
resolve: {
currentUser: ['AuthService', function (AuthService) {
return AuthService.getCurrentUser();
}],
AppConfig: ['AuthService', function (AuthService) {
return AuthService.getAppConfig();
}],
return AuthService.getAppConfig().then(function () {
return AuthService.getCurrentUser();
});
}]
},
})
.state('app.main', {
Expand Down
5 changes: 3 additions & 2 deletions src/front/src/app/auth/auth.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ angular.module('topcoderX')
jwtInterceptorProvider.tokenGetter = [
'AuthService', '$http', 'Helper', '$rootScope', 'config',
function (AuthService, $http, Helper, $rootScope, config) {
if (!$rootScope.appConfig) return;
// token V2 for API V2
if (config.url.indexOf(Helper.config().ADMIN_TOOL_URL) > -1) {
if (config.url.indexOf($rootScope.appConfig.ADMIN_TOOL_URL) > -1) {
if (AuthService.getTokenV2()) {
return AuthService.getTokenV2();
}
Expand All @@ -45,7 +46,7 @@ angular.module('topcoderX')
if (refreshingToken === null) {
refreshingToken = $http({
method: 'GET',
url: Helper.config().API_URL + "/v3/authorizations/1",
url: $rootScope.appConfig.API_URL + "/v3/authorizations/1",
headers: {
'Authorization': "Bearer " + currentToken
}
Expand Down
44 changes: 23 additions & 21 deletions src/front/src/app/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

angular.module('topcoderX')
.factory('AuthService', [
'$q', '$log', 'jwtHelper', '$cookies', '$window', '$state', '$rootScope', '$http',
'COOKIES_SECURE', 'JWT_V3_NAME', 'JWT_V2_NAME', 'Helper',
function ($q, $log, jwtHelper, $cookies, $window, $state, $rootScope, $http,
COOKIES_SECURE, JWT_V3_NAME, JWT_V2_NAME, Helper) {
'$q', '$log', 'jwtHelper', '$cookies', '$window', '$state', '$rootScope', '$http', 'Helper',
function ($q, $log, jwtHelper, $cookies, $window, $state, $rootScope, $http, Helper) {
// these constants are for AuthService internal usage only
// they don't depend on the environment thus don't have to be placed in global config

var GET_FRESH_TOKEN_REQUEST = 'GET_FRESH_TOKEN_REQUEST';
var GET_FRESH_TOKEN_SUCCESS = 'GET_FRESH_TOKEN_SUCCESS';
var GET_FRESH_TOKEN_FAILURE = 'GET_FRESH_TOKEN_FAILURE';
Expand Down Expand Up @@ -153,14 +152,14 @@ angular.module('topcoderX')
AuthService.logginOut = null;
// remove only token V3, which we set from the script manually
// token V2 will be removed automatically during logout server request
$cookies.remove(JWT_V3_NAME, { path: '/' });
$cookies.remove($rootScope.appConfig.JWT_V3_NAME, { path: '/' });
});

return AuthService.logginOut;
}

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

/**
Expand All @@ -170,7 +169,7 @@ angular.module('topcoderX')
AuthService.init = function () {
// add hidden iframe which is used to get API v3 token
configureConnector({
connectorUrl: Helper.config().ACCOUNTS_CONNECTOR_URL,
connectorUrl: $rootScope.appConfig ? $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL : null,
frameId: 'tc-accounts-iframe',
});
}
Expand Down Expand Up @@ -219,15 +218,15 @@ angular.module('topcoderX')
* @return {String} token v3
*/
AuthService.getTokenV3 = function () {
return $cookies.get(JWT_V3_NAME);
return $cookies.get($rootScope.appConfig.JWT_V3_NAME);
}

/**
* Save token V3 to cookies
*/
AuthService.setTokenV3 = function (token) {
return $cookies.put(JWT_V3_NAME, token, {
secure: COOKIES_SECURE,
return $cookies.put($rootScope.appConfig.JWT_V3_NAME, token, {
secure: $rootScope.appConfig.COOKIES_SECURE,
});
}

Expand All @@ -246,7 +245,7 @@ angular.module('topcoderX')
* @return {String} token v2
*/
AuthService.getTokenV2 = function () {
return $cookies.get(JWT_V2_NAME);
return $cookies.get($rootScope.appConfig.JWT_V2_NAME);
}

/**
Expand Down Expand Up @@ -282,17 +281,20 @@ angular.module('topcoderX')
* gets the application configurations
*/
AuthService.getAppConfig = function () {
var tctV3 = AuthService.getTokenV3();

if (!tctV3) {
return null;
if ($rootScope.appConfig) {
return $q.resolve($rootScope.appConfig);
}
return $http.get(Helper.baseUrl + '/api/v1/appConfig').then(function (res) {
$rootScope.appConfig = res.data;
return $q.resolve(res.data);
}).catch(function (err) {
return $q.reject(err);
});
return $http.get(Helper.baseUrl + '/api/v1/appConfig')
.then(function (res) {
$rootScope.appConfig = res.data;
if (connectorIFrame && !connectorIFrame.src) {
connectorIFrame.src = $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL;
url = $rootScope.appConfig.ACCOUNTS_CONNECTOR_URL;
}
return $q.resolve(res.data);
}).catch(function (err) {
return $q.reject(err);
});
};

return AuthService;
Expand Down
Loading