Skip to content

Issues-652: fixed Client Manager role #109

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 17, 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
23 changes: 11 additions & 12 deletions Topcoder/class.topcoder.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1782,10 +1782,13 @@ private static function isTopcoderAdmin($topcoderRoles = false) {
* @param false $topcoderRoles
* @return bool true, if the list of Topcoder roles includes 'Client Manager'
*/
private static function isTopcoderClientManager($topcoderRoles = false) {
public static function isTopcoderClientManager() {
if(!Gdn::session()->isValid()) {
return false;
}
$topcoderRoles = Gdn::controller()->data("ChallengeCurrentUserProjectRoles");
if($topcoderRoles) {
$roleNames = array_column($topcoderRoles, 'roleName');
$lowerRoleNames = array_map('strtolower', $roleNames);
$lowerRoleNames = array_map('strtolower', $topcoderRoles);
return count(array_intersect($lowerRoleNames, ["client manager"])) > 0;
}

Expand Down Expand Up @@ -1824,7 +1827,6 @@ 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 @@ -1914,7 +1916,7 @@ private function setTopcoderProjectData($sender, $challengeID) {
// if($sender->GroupModel) {
// $sender->GroupModel->setCurrentUserTopcoderProjectRoles($currentProjectRoles);
// }
self::log('setTopcoderProjectData', ['ChallengeID' => $challengeID, 'currentUser' => $currentProjectRoles,
self::log('setTopcoderProjectData', ['ChallengeID' => $challengeID, 'CurrentUserProjectRoles' => $currentProjectRoles,
'Topcoder Resources' => $resources , 'Topcoder RoleResources'
=> $roleResources, 'challenge' =>$challenge]);
}
Expand Down Expand Up @@ -2011,7 +2013,7 @@ public function gdn_dispatcher_beforeDispatch_handler($sender, $args) {
'Request(Method)'=> Gdn::request()->getMethod(),
'Permissions' => Gdn::session()->getPermissionsArray(),
);
logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data ));
// logMessage(__FILE__, __LINE__, 'TopcoderPlugin', "Data", json_encode($data ));
// self::log('gdn_dispatcher_beforeDispatch_handler', $data);
}

Expand Down Expand Up @@ -2090,7 +2092,6 @@ 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 @@ -2490,7 +2491,7 @@ function userPhoto($user, $options = []) {
}

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

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

Expand Down Expand Up @@ -2906,9 +2907,7 @@ function hideInMFE() {
}
//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);
$isTopcoderClientManager = TopcoderPlugin::isTopcoderClientManager();

if ($isMFE && $isTopcoderClientManager) {
return true;
Expand Down