Skip to content

Commit be8d124

Browse files
committed
Issues-652: fixed Client Manager role
1 parent 7aec19f commit be8d124

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,10 +1782,13 @@ private static function isTopcoderAdmin($topcoderRoles = false) {
17821782
* @param false $topcoderRoles
17831783
* @return bool true, if the list of Topcoder roles includes 'Client Manager'
17841784
*/
1785-
private static function isTopcoderClientManager($topcoderRoles = false) {
1785+
public static function isTopcoderClientManager() {
1786+
if(!Gdn::session()->isValid()) {
1787+
return false;
1788+
}
1789+
$topcoderRoles = Gdn::controller()->data("ChallengeCurrentUserProjectRoles");
17861790
if($topcoderRoles) {
1787-
$roleNames = array_column($topcoderRoles, 'roleName');
1788-
$lowerRoleNames = array_map('strtolower', $roleNames);
1791+
$lowerRoleNames = array_map('strtolower', $topcoderRoles);
17891792
return count(array_intersect($lowerRoleNames, ["client manager"])) > 0;
17901793
}
17911794

@@ -1824,7 +1827,6 @@ private static function loadTopcoderUserDetails($vanillaUser) {
18241827
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
18251828
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
18261829
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
1827-
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
18281830
$topcoderRating = self::loadTopcoderRating($username); //loaded by handle
18291831
if($topcoderRating) {
18301832
$cachedUser['Rating'] = $topcoderRating;
@@ -1914,7 +1916,7 @@ private function setTopcoderProjectData($sender, $challengeID) {
19141916
// if($sender->GroupModel) {
19151917
// $sender->GroupModel->setCurrentUserTopcoderProjectRoles($currentProjectRoles);
19161918
// }
1917-
self::log('setTopcoderProjectData', ['ChallengeID' => $challengeID, 'currentUser' => $currentProjectRoles,
1919+
self::log('setTopcoderProjectData', ['ChallengeID' => $challengeID, 'CurrentUserProjectRoles' => $currentProjectRoles,
19181920
'Topcoder Resources' => $resources , 'Topcoder RoleResources'
19191921
=> $roleResources, 'challenge' =>$challenge]);
19201922
}
@@ -2011,7 +2013,7 @@ public function gdn_dispatcher_beforeDispatch_handler($sender, $args) {
20112013
'Request(Method)'=> Gdn::request()->getMethod(),
20122014
'Permissions' => Gdn::session()->getPermissionsArray(),
20132015
);
2014-
logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data ));
2016+
// logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data ));
20152017
// self::log('gdn_dispatcher_beforeDispatch_handler', $data);
20162018
}
20172019

@@ -2090,7 +2092,6 @@ private static function loadTopcoderUserDetailsByHandle($topcoderHandle) {
20902092
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
20912093
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
20922094
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
2093-
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
20942095
$topcoderRating = self::loadTopcoderRating($topcoderHandle); //loaded by handle
20952096
if($topcoderRating) {
20962097
$cachedUser['Rating'] = $topcoderRating;
@@ -2490,7 +2491,7 @@ function userPhoto($user, $options = []) {
24902491
}
24912492

24922493
$isTopcoderAdmin = val('IsAdmin', $topcoderProfile);
2493-
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
2494+
$isTopcoderClientManager = TopcoderPlugin::isTopcoderClientManager();
24942495
$photoUrl = isset($photoUrl) && !empty(trim($photoUrl)) ? $photoUrl: UserModel::getDefaultAvatarUrl();
24952496
$isUnlickableUser = TopcoderPlugin::isUnclickableUser($name);
24962497
$href = (val('NoLink', $options)) || $isUnlickableUser ||
@@ -2586,7 +2587,7 @@ function userAnchor($user, $cssClass = null, $options = null) {
25862587
$topcoderProfile = TopcoderPlugin::getTopcoderUser($userID);
25872588

25882589
// Go to Topcoder user profile link instead of Vanilla profile link
2589-
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
2590+
$isTopcoderClientManager = TopcoderPlugin::isTopcoderClientManager();
25902591
$isUnlickableUser = ( $isTopcoderClientManager && getIncomingValue('embed_type') == 'mfe') || TopcoderPlugin::isUnclickableUser($name);
25912592
$userUrl = $isUnlickableUser? '#' : topcoderUserUrl($user, $px);
25922593

@@ -2906,9 +2907,7 @@ function hideInMFE() {
29062907
}
29072908
//FIX Issues-652: Client Manager - no navigation when embedded
29082909
$isMFE = getIncomingValue('embed_type') == 'mfe';
2909-
$user = Gdn::userModel()->getID(Gdn::session()->UserID, DATASET_TYPE_ARRAY);
2910-
$topcoderProfile = TopcoderPlugin::getTopcoderUser($user);
2911-
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
2910+
$isTopcoderClientManager = TopcoderPlugin::isTopcoderClientManager();
29122911

29132912
if ($isMFE && $isTopcoderClientManager) {
29142913
return true;

0 commit comments

Comments
 (0)