Skip to content

Commit 7aec19f

Browse files
committed
Issues-652: Client Manger - no navigation when embedded
1 parent df89179 commit 7aec19f

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){
943943
}
944944
}
945945

946+
947+
public function base_beforeBuildBreadcrumbs_handler($sender, $args) {
948+
if(Gdn::session()->isValid()) {
949+
$showFullBreadcrumbs = & $args['ShowFullBreadcrumbs'];
950+
//FIX Issues-652: Client Manager - no navigation when embedded
951+
$showFullBreadcrumbs = !hideInMFE();
952+
}
953+
}
946954
/**
947955
* Add scripts. Add script to hide iPhone browser bar on pageload.
948956
*/
@@ -1769,6 +1777,21 @@ private static function isTopcoderAdmin($topcoderRoles = false) {
17691777
return false;
17701778
}
17711779

1780+
/**
1781+
* Check if the list of Topcoder roles includes 'Client Manager' role
1782+
* @param false $topcoderRoles
1783+
* @return bool true, if the list of Topcoder roles includes 'Client Manager'
1784+
*/
1785+
private static function isTopcoderClientManager($topcoderRoles = false) {
1786+
if($topcoderRoles) {
1787+
$roleNames = array_column($topcoderRoles, 'roleName');
1788+
$lowerRoleNames = array_map('strtolower', $roleNames);
1789+
return count(array_intersect($lowerRoleNames, ["client manager"])) > 0;
1790+
}
1791+
1792+
return false;
1793+
}
1794+
17721795
/**
17731796
* Get Topcoder Role names
17741797
* @param false $topcoderRoles
@@ -1801,6 +1824,7 @@ private static function loadTopcoderUserDetails($vanillaUser) {
18011824
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
18021825
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
18031826
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
1827+
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
18041828
$topcoderRating = self::loadTopcoderRating($username); //loaded by handle
18051829
if($topcoderRating) {
18061830
$cachedUser['Rating'] = $topcoderRating;
@@ -2066,6 +2090,7 @@ private static function loadTopcoderUserDetailsByHandle($topcoderHandle) {
20662090
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
20672091
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
20682092
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
2093+
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
20692094
$topcoderRating = self::loadTopcoderRating($topcoderHandle); //loaded by handle
20702095
if($topcoderRating) {
20712096
$cachedUser['Rating'] = $topcoderRating;
@@ -2465,9 +2490,11 @@ function userPhoto($user, $options = []) {
24652490
}
24662491

24672492
$isTopcoderAdmin = val('IsAdmin', $topcoderProfile);
2493+
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
24682494
$photoUrl = isset($photoUrl) && !empty(trim($photoUrl)) ? $photoUrl: UserModel::getDefaultAvatarUrl();
24692495
$isUnlickableUser = TopcoderPlugin::isUnclickableUser($name);
2470-
$href = (val('NoLink', $options)) || $isUnlickableUser || getIncomingValue('embed_type') == 'mfe' ? '' : ' href="'.url($userLink).'"';
2496+
$href = (val('NoLink', $options)) || $isUnlickableUser ||
2497+
($isTopcoderClientManager && getIncomingValue('embed_type') == 'mfe') ? '' : ' href="'.url($userLink).'"';
24712498

24722499
Gdn::controller()->EventArguments['User'] = $user;
24732500
Gdn::controller()->EventArguments['Title'] =& $title;
@@ -2556,11 +2583,14 @@ function userAnchor($user, $cssClass = null, $options = null) {
25562583
$attributes['title'] = $options['title'];
25572584
}
25582585

2586+
$topcoderProfile = TopcoderPlugin::getTopcoderUser($userID);
2587+
25592588
// Go to Topcoder user profile link instead of Vanilla profile link
2560-
$isUnlickableUser = getIncomingValue('embed_type') == 'mfe' || TopcoderPlugin::isUnclickableUser($name);
2589+
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
2590+
$isUnlickableUser = ( $isTopcoderClientManager && getIncomingValue('embed_type') == 'mfe') || TopcoderPlugin::isUnclickableUser($name);
25612591
$userUrl = $isUnlickableUser? '#' : topcoderUserUrl($user, $px);
25622592

2563-
$topcoderProfile = TopcoderPlugin::getTopcoderUser($userID);
2593+
25642594
$topcoderRating = val('Rating',$topcoderProfile, false);
25652595
if($topcoderRating != false || $topcoderRating == null) {
25662596
$coderStyles = TopcoderPlugin::getRatingCssClass($topcoderRating);
@@ -2867,4 +2897,22 @@ function watchingSorts($extraClasses = '') {
28672897
'Sort'
28682898
);
28692899
}
2870-
}
2900+
}
2901+
2902+
if (!function_exists('hideInMFE')) {
2903+
function hideInMFE() {
2904+
if (!Gdn::session()->isValid()) {
2905+
return false;
2906+
}
2907+
//FIX Issues-652: Client Manager - no navigation when embedded
2908+
$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);
2912+
2913+
if ($isMFE && $isTopcoderClientManager) {
2914+
return true;
2915+
}
2916+
return false;
2917+
}
2918+
}

0 commit comments

Comments
 (0)