|
6 | 6 | 'use strict';
|
7 | 7 |
|
8 | 8 | angular.module('topcoderX')
|
9 |
| - .factory('Helper', ['$location', function ($location) { |
10 |
| - var baseUrl = $location.protocol() + '://' + $location.host(); |
| 9 | + .factory('Helper', ['$rootScope', '$location', function ($rootScope, $location) { |
| 10 | + var baseUrl = $location.protocol() + '://' + $location.host(); |
11 | 11 |
|
12 |
| - var service = {}; |
| 12 | + var service = {}; |
13 | 13 |
|
14 |
| - service.baseUrl = baseUrl; |
| 14 | + service.baseUrl = baseUrl; |
15 | 15 |
|
16 |
| - /** |
17 |
| - * gets the config based on host env |
18 |
| - */ |
19 |
| - service.config = function () { |
20 |
| - var tcDomain = baseUrl.indexOf('topcoder.com') > -1 ? 'topcoder.com' : 'topcoder-dev.com'; |
21 |
| - return { |
22 |
| - TC_LOGIN_URL: 'https://accounts.' + tcDomain + '/member', |
23 |
| - TC_USER_PROFILE_URL: 'http://api.' + tcDomain + '/v2/user/profile', |
24 |
| - API_URL: 'https://api.' + tcDomain + '', |
25 |
| - ADMIN_TOOL_URL: 'https://api.' + tcDomain + '/v2', |
26 |
| - ACCOUNTS_CONNECTOR_URL: 'https://accounts.' + tcDomain + '/connector.html', |
27 |
| - DIRECT_URL_BASE: 'https://www.' + tcDomain + '/direct/projectOverview?formData.projectId=' |
28 |
| - } |
29 |
| - } |
30 |
| - return service; |
| 16 | + /** |
| 17 | + * gets the config based on host env |
| 18 | + */ |
| 19 | + service.config = function () { |
| 20 | + var tcDomain = baseUrl.indexOf('topcoder.com') > -1 ? 'topcoder.com' : 'topcoder-dev.com'; |
| 21 | + return { |
| 22 | + TC_LOGIN_URL: 'https://accounts.' + tcDomain + '/member', |
| 23 | + TC_USER_PROFILE_URL: 'http://api.' + tcDomain + '/v2/user/profile', |
| 24 | + API_URL: 'https://api.' + tcDomain + '', |
| 25 | + ADMIN_TOOL_URL: 'https://api.' + tcDomain + '/v2', |
| 26 | + ACCOUNTS_CONNECTOR_URL: 'https://accounts.' + tcDomain + '/connector.html', |
| 27 | + DIRECT_URL_BASE: 'https://www.' + tcDomain + '/direct/projectOverview?formData.projectId=' |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + service.isAdminUser = function (currentUser) { |
| 32 | + var userRoles = currentUser.roles.map(function (x) { |
| 33 | + return x.toUpperCase(); |
| 34 | + }); |
| 35 | + var administratorRoles = $rootScope.appConfig.administratorRoles.map(function (x) { |
| 36 | + return x.toUpperCase(); |
| 37 | + }); |
| 38 | + var t; |
| 39 | + if (administratorRoles.length > userRoles.length) { |
| 40 | + t = administratorRoles; |
| 41 | + administratorRoles = userRoles; |
| 42 | + userRoles = t; // indexOf to loop over shorter |
| 43 | + } |
| 44 | + var matchedRoles = userRoles.filter(function (e) { |
| 45 | + return administratorRoles.indexOf(e.toUpperCase()) > -1; |
| 46 | + }); |
| 47 | + return matchedRoles.length > 0; |
| 48 | + }; |
| 49 | + return service; |
| 50 | + }]); |
31 | 51 |
|
32 |
| - }]); |
|
0 commit comments