diff --git a/gulp/build.js b/gulp/build.js index 6dde37a..39260c6 100644 --- a/gulp/build.js +++ b/gulp/build.js @@ -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']); diff --git a/gulp/ng-config.js b/gulp/ng-config.js deleted file mode 100644 index 3c8257f..0000000 --- a/gulp/ng-config.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -var gulp = require('gulp'); - -var gulpNgConfig = require('gulp-ng-config'); - -var paths = gulp.paths; - -gulp.task('ng-config', function () { - gulp.src('src/front/config.json') - .pipe( - gulpNgConfig('app.constants', { - environment: process.env.BUILD_ENV || 'dev', - })) - .pipe(gulp.dest(paths.src + '/app/')) -}); diff --git a/package.json b/package.json index 1bc9b3c..eb6a07f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/config.js b/src/config.js index b443c31..067905c 100644 --- a/src/config.js +++ b/src/config.js @@ -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 +}; \ No newline at end of file diff --git a/src/front/config.json b/src/front/config.json deleted file mode 100644 index 3dba53e..0000000 --- a/src/front/config.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "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/" - } -} diff --git a/src/front/src/app/app.js b/src/front/src/app/app.js index 8aa9c2e..ab0b3ef 100644 --- a/src/front/src/app/app.js +++ b/src/front/src/app/app.js @@ -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 @@ -52,7 +51,9 @@ angular.module('topcoderX', [ }); }], currentUser: ['AuthService', function (AuthService) { - return AuthService.getCurrentUser(); + return AuthService.getAppConfig().then(function () { + return AuthService.getCurrentUser(); + }); }], } @@ -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', { diff --git a/src/front/src/app/auth/auth.config.js b/src/front/src/app/auth/auth.config.js index 401988e..68380ab 100644 --- a/src/front/src/app/auth/auth.config.js +++ b/src/front/src/app/auth/auth.config.js @@ -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(); } @@ -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 } diff --git a/src/front/src/app/auth/auth.service.js b/src/front/src/app/auth/auth.service.js index cc0f71c..14a6423 100644 --- a/src/front/src/app/auth/auth.service.js +++ b/src/front/src/app/auth/auth.service.js @@ -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'; @@ -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); } /** @@ -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', }); } @@ -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, }); } @@ -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); } /** @@ -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; diff --git a/src/front/src/app/helper.js b/src/front/src/app/helper.js index c491d87..d748d67 100644 --- a/src/front/src/app/helper.js +++ b/src/front/src/app/helper.js @@ -6,27 +6,13 @@ 'use strict'; angular.module('topcoderX') - .factory('Helper', ['$rootScope', '$location', 'TC_LOGIN_URL', 'TC_USER_PROFILE_URL', 'API_URL', 'ADMIN_TOOL_URL', 'ACCOUNTS_CONNECTOR_URL', 'DIRECT_URL_BASE', function ($rootScope, $location, TC_LOGIN_URL, TC_USER_PROFILE_URL, API_URL, ADMIN_TOOL_URL, ACCOUNTS_CONNECTOR_URL, DIRECT_URL_BASE) { + .factory('Helper', ['$rootScope', '$location', function ($rootScope, $location) { var baseUrl = $location.protocol() + '://' + $location.host(); var service = {}; service.baseUrl = baseUrl; - /** - * gets the config based on host env - */ - service.config = function () { - return { - TC_LOGIN_URL: TC_LOGIN_URL, // eslint-disable-line object-shorthand - TC_USER_PROFILE_URL: TC_USER_PROFILE_URL, // eslint-disable-line object-shorthand - API_URL: API_URL, // eslint-disable-line object-shorthand - ADMIN_TOOL_URL: ADMIN_TOOL_URL, // eslint-disable-line object-shorthand - ACCOUNTS_CONNECTOR_URL: ACCOUNTS_CONNECTOR_URL, // eslint-disable-line object-shorthand - DIRECT_URL_BASE: DIRECT_URL_BASE, // eslint-disable-line object-shorthand - }; - }; - service.isAdminUser = function (currentUser) { var userRoles = currentUser.roles.map(function (x) { return x.toUpperCase(); diff --git a/src/front/src/app/members/member.controller.js b/src/front/src/app/members/member.controller.js index cef9d07..b4f1461 100644 --- a/src/front/src/app/members/member.controller.js +++ b/src/front/src/app/members/member.controller.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('topcoderX') - .controller('MemberController', ['$scope', '$stateParams', 'GITHUB_TEAM_URL', 'GITLAB_GROUP_URL', function ($scope, $stateParams, GITHUB_TEAM_URL, GITLAB_GROUP_URL) { + .controller('MemberController', ['$scope', '$rootScope', '$stateParams', function ($scope, $rootScope, $stateParams) { $scope.title = 'Members'; $scope.provider = $stateParams.provider; @@ -10,9 +10,9 @@ angular.module('topcoderX') const params = url.split('_'); const org = params[0]; const team = url.replace(org, '').substring(1); - $scope.link = GITHUB_TEAM_URL + org + '/teams/' + team; + $scope.link = $rootScope.appConfig.GITHUB_TEAM_URL + org + '/teams/' + team; } else { - $scope.link = GITLAB_GROUP_URL + url; + $scope.link = $rootScope.appConfig.GITLAB_GROUP_URL + url; } }; _getUrl($scope.provider, $stateParams.url); diff --git a/src/front/src/app/projects/projects.controller.js b/src/front/src/app/projects/projects.controller.js index b6bc5d2..f8b9e3e 100644 --- a/src/front/src/app/projects/projects.controller.js +++ b/src/front/src/app/projects/projects.controller.js @@ -7,7 +7,7 @@ angular.module('topcoderX') $scope.title = 'Project Management'; //direct base - $scope.directUrlBase = Helper.config().DIRECT_URL_BASE; + $scope.directUrlBase = $rootScope.appConfig.DIRECT_URL_BASE; $scope.isAdminUser = Helper.isAdminUser(currentUser); $scope.filter = { showAll: $scope.isAdminUser, diff --git a/src/front/src/app/settings/settings.controller.js b/src/front/src/app/settings/settings.controller.js index 9041df9..4a5e99d 100644 --- a/src/front/src/app/settings/settings.controller.js +++ b/src/front/src/app/settings/settings.controller.js @@ -1,10 +1,9 @@ 'use strict'; -angular.module('topcoderX').controller('SettingController', ['currentUser', '$scope', 'OWNER_LOGIN_GITHUB_URL', - 'OWNER_LOGIN_GITLAB_URL', 'SettingService', '$rootScope', 'Dialog', 'Alert', 'Helper', '$window', +angular.module('topcoderX').controller('SettingController', ['currentUser', '$scope', + 'SettingService', '$rootScope', 'Dialog', 'Alert', 'Helper', '$window', 'Tutorial', - function (currentUser, $scope, OWNER_LOGIN_GITHUB_URL, - OWNER_LOGIN_GITLAB_URL, SettingService, $rootScope, Dialog, Alert, Helper, $window, Tutorial) { + function (currentUser, $scope, SettingService, $rootScope, Dialog, Alert, Helper, $window, Tutorial) { $scope.settings = {}; $scope.isLoaded = false; @@ -21,8 +20,8 @@ angular.module('topcoderX').controller('SettingController', ['currentUser', '$sc _getSetting(); $scope.loginUrl = { - github: Helper.baseUrl + OWNER_LOGIN_GITHUB_URL, - gitlab: Helper.baseUrl + OWNER_LOGIN_GITLAB_URL, + github: Helper.baseUrl + $rootScope.appConfig.OWNER_LOGIN_GITHUB_URL, + gitlab: Helper.baseUrl + $rootScope.appConfig.OWNER_LOGIN_GITLAB_URL, } $scope.$on('dialog.finished', function (event, args) { diff --git a/src/front/src/components/common/navigation.controller.js b/src/front/src/components/common/navigation.controller.js index eb27160..5a1636a 100644 --- a/src/front/src/components/common/navigation.controller.js +++ b/src/front/src/components/common/navigation.controller.js @@ -1,8 +1,8 @@ 'use strict'; angular.module('topcoderX') // eslint-disable-line angular/no-services - .controller('NavController', ['$scope', '$log', '$state', '$cookies', '$http', '$rootScope', 'TC_USER_PROFILE_URL', - function ($scope, $log, $state, $cookies, $http, $rootScope, TC_USER_PROFILE_URL) { + .controller('NavController', ['$scope', '$log', '$state', '$cookies', '$http', '$rootScope', + function ($scope, $log, $state, $cookies, $http, $rootScope) { $scope.$state = $state; $scope.menuList = false; $scope.user = {}; @@ -10,7 +10,7 @@ angular.module('topcoderX') // eslint-disable-line angular/no-services const token = $cookies.get('tcjwt'); const req = { - url: TC_USER_PROFILE_URL, + url: $rootScope.appConfig.TC_USER_PROFILE_URL, method: 'Get', headers: { Authorization: 'Bearer ' + token, diff --git a/src/routes.js b/src/routes.js index 00d91b5..bf8f35c 100644 --- a/src/routes.js +++ b/src/routes.js @@ -224,6 +224,8 @@ module.exports = { get: { controller: 'AppConfigController', method: 'getAppConfig', + allowNormalUser: true, + allowAnonymous: true }, }, }; diff --git a/src/services/AppConfigService.js b/src/services/AppConfigService.js index ba371ca..6259be1 100644 --- a/src/services/AppConfigService.js +++ b/src/services/AppConfigService.js @@ -16,11 +16,7 @@ const helper = require('../common/helper'); * @returns {Object} the configuration details */ async function getAppConfig() { - return { - helpLink: config.HELP_LINK, - copilotRole: config.COPILOT_ROLE, - administratorRoles: config.ADMINISTRATOR_ROLES, - }; + return config.frontendConfigs; } module.exports = {