Skip to content

Commit f10cee6

Browse files
authored
Merge pull request #66 from topcoder-platform/issues-466
Issues-466:Topcoder admins should be shown in orange
2 parents 626368f + 27fb903 commit f10cee6

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,22 +1559,32 @@ public static function hasTopcoderAdminRole($user) {
15591559

15601560

15611561
/**
1562-
* Get a photo url from Topcoder Member Profile
1563-
* @param $name vanilla user name
1564-
* @return null|string photo url
1562+
* Check if the list of Topcoder roles includes Topcoder admin roles
1563+
* @param false $topcoderRoles
1564+
* @return bool true, if the list of Topcoder roles includes at least one Topcoder admin role
15651565
*/
1566-
//TODO: remove , not found usages
1567-
/*
1568-
public static function getTopcoderPhotoUrl($name) {
1569-
$topcoderProfile = self::getTopcoderProfile($name);
1570-
if($topcoderProfile !== null) {
1571-
return $topcoderProfile->photoURL;
1566+
private static function isTopcoderAdmin($topcoderRoles = false) {
1567+
if($topcoderRoles) {
1568+
$roleNames = array_column($topcoderRoles, 'roleName');
1569+
$lowerRoleNames = array_map('strtolower', $roleNames);
1570+
return count(array_intersect($lowerRoleNames, ["connect manager", "admin", "administrator"])) > 0;
15721571
}
1573-
return null;
1572+
1573+
return false;
1574+
}
1575+
1576+
/**
1577+
* Get Topcoder Role names
1578+
* @param false $topcoderRoles
1579+
* @return array|false|null
1580+
*/
1581+
private static function getTopcoderRoleNames($topcoderRoles = false) {
1582+
return $topcoderRoles ? array_column($topcoderRoles, 'roleName') : [];
15741583
}
1575-
*/
1584+
15761585
/**
15771586
* Load Topcoder User Details from Topcoder API.
1587+
* User is registered in Vanilla
15781588
* Data is cached if a cache is enabled
15791589
* @param $vanillaUser
15801590
* @return array|void
@@ -1593,13 +1603,8 @@ private static function loadTopcoderUserDetails($vanillaUser) {
15931603
$cachedUser['TopcoderUserID'] = $topcoderProfile->userId;
15941604
$cachedUser['PhotoUrl'] = $topcoderProfile->photoURL;
15951605
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
1596-
if($topcoderRoles) {
1597-
$roleNames = array_column($topcoderRoles, 'roleName');
1598-
$lowerRoleNames = array_map('strtolower', $roleNames);
1599-
$cachedUser['Roles'] = $roleNames;
1600-
$cachedUser['IsAdmin'] = in_array("admin", $lowerRoleNames) || in_array("administrator", $lowerRoleNames);
1601-
}
1602-
1606+
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
1607+
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
16031608
$topcoderRating = self::loadTopcoderRating($username); //loaded by handle
16041609
if($topcoderRating) {
16051610
$cachedUser['Rating'] = $topcoderRating;
@@ -1815,7 +1820,8 @@ private static function getTopcoderUserFromTopcoderCache($topcoderHandle) {
18151820
}
18161821

18171822
/**
1818-
* Load Topcoder User Details from Topcoder API.
1823+
* Load Topcoder User Details by Topcoder handle from Topcoder API and add data in Topcoder User cache.
1824+
* Topcoder handles are used in mentions but Topcoder Users may not register in Vanilla.
18191825
* Data is cached if a cache is enabled
18201826
* @param $topcoderHandle
18211827
* @return array|void
@@ -1831,13 +1837,8 @@ private static function loadTopcoderUserDetailsByHandle($topcoderHandle) {
18311837
$cachedUser['TopcoderUserID'] = $topcoderProfile->userId;
18321838
$cachedUser['PhotoUrl'] = $topcoderProfile->photoURL;
18331839
$topcoderRoles = self::loadTopcoderRoles($topcoderProfile->userId);
1834-
if($topcoderRoles) {
1835-
$roleNames = array_column($topcoderRoles, 'roleName');
1836-
$lowerRoleNames = array_map('strtolower', $roleNames);
1837-
$cachedUser['Roles'] = $roleNames;
1838-
$cachedUser['IsAdmin'] = count(array_intersect($lowerRoleNames, ["connect manager", "admin", "administrator"])) > 0;
1839-
}
1840-
1840+
$cachedUser['Roles'] = self::getTopcoderRoleNames($topcoderRoles);
1841+
$cachedUser['IsAdmin'] = self::isTopcoderAdmin($topcoderRoles);
18411842
$topcoderRating = self::loadTopcoderRating($topcoderHandle); //loaded by handle
18421843
if($topcoderRating) {
18431844
$cachedUser['Rating'] = $topcoderRating;

0 commit comments

Comments
 (0)