Skip to content

Issues-652: Client Manger - no navigation when embedded #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2022
Merged
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
56 changes: 52 additions & 4 deletions Topcoder/class.topcoder.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,14 @@ function gdn_dispatcher_beforeControllerMethod_handler($sender, $args){
}
}


public function base_beforeBuildBreadcrumbs_handler($sender, $args) {
if(Gdn::session()->isValid()) {
$showFullBreadcrumbs = & $args['ShowFullBreadcrumbs'];
//FIX Issues-652: Client Manager - no navigation when embedded
$showFullBreadcrumbs = !hideInMFE();
}
}
/**
* Add scripts. Add script to hide iPhone browser bar on pageload.
*/
Expand Down Expand Up @@ -1769,6 +1777,21 @@ private static function isTopcoderAdmin($topcoderRoles = false) {
return false;
}

/**
* Check if the list of Topcoder roles includes 'Client Manager' role
* @param false $topcoderRoles
* @return bool true, if the list of Topcoder roles includes 'Client Manager'
*/
private static function isTopcoderClientManager($topcoderRoles = false) {
if($topcoderRoles) {
$roleNames = array_column($topcoderRoles, 'roleName');
$lowerRoleNames = array_map('strtolower', $roleNames);
return count(array_intersect($lowerRoleNames, ["client manager"])) > 0;
}

return false;
}

/**
* Get Topcoder Role names
* @param false $topcoderRoles
Expand Down Expand Up @@ -1801,6 +1824,7 @@ private static function loadTopcoderUserDetails($vanillaUser) {
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
$topcoderRating = self::loadTopcoderRating($username); //loaded by handle
if($topcoderRating) {
$cachedUser['Rating'] = $topcoderRating;
Expand Down Expand Up @@ -2066,6 +2090,7 @@ private static function loadTopcoderUserDetailsByHandle($topcoderHandle) {
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
$cachedUser['IsClientManager'] = self::isTopcoderClientManager($topcoderRoles);
$topcoderRating = self::loadTopcoderRating($topcoderHandle); //loaded by handle
if($topcoderRating) {
$cachedUser['Rating'] = $topcoderRating;
Expand Down Expand Up @@ -2465,9 +2490,11 @@ function userPhoto($user, $options = []) {
}

$isTopcoderAdmin = val('IsAdmin', $topcoderProfile);
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);
$photoUrl = isset($photoUrl) && !empty(trim($photoUrl)) ? $photoUrl: UserModel::getDefaultAvatarUrl();
$isUnlickableUser = TopcoderPlugin::isUnclickableUser($name);
$href = (val('NoLink', $options)) || $isUnlickableUser || getIncomingValue('embed_type') == 'mfe' ? '' : ' href="'.url($userLink).'"';
$href = (val('NoLink', $options)) || $isUnlickableUser ||
($isTopcoderClientManager && getIncomingValue('embed_type') == 'mfe') ? '' : ' href="'.url($userLink).'"';

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

$topcoderProfile = TopcoderPlugin::getTopcoderUser($userID);

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

$topcoderProfile = TopcoderPlugin::getTopcoderUser($userID);

$topcoderRating = val('Rating',$topcoderProfile, false);
if($topcoderRating != false || $topcoderRating == null) {
$coderStyles = TopcoderPlugin::getRatingCssClass($topcoderRating);
Expand Down Expand Up @@ -2867,4 +2897,22 @@ function watchingSorts($extraClasses = '') {
'Sort'
);
}
}
}

if (!function_exists('hideInMFE')) {
function hideInMFE() {
if (!Gdn::session()->isValid()) {
return false;
}
//FIX Issues-652: Client Manager - no navigation when embedded
$isMFE = getIncomingValue('embed_type') == 'mfe';
$user = Gdn::userModel()->getID(Gdn::session()->UserID, DATASET_TYPE_ARRAY);
$topcoderProfile = TopcoderPlugin::getTopcoderUser($user);
$isTopcoderClientManager = val('IsClientManager', $topcoderProfile);

if ($isMFE && $isTopcoderClientManager) {
return true;
}
return false;
}
}