From 5b3ccfd95fb92dd5bf4993929045ac8cbb35c3f4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 15 May 2014 19:17:09 -0700 Subject: [PATCH] Move people list rendering into SearchEngine Summary: Ref T4986. One note: - We have a separate "browse directory" capability, to provide some soft privacy for users of public installs. Respect that policy within the SearchEngine. - Also restore some other icons I missed earlier. Test Plan: - Viewed people list. - Build people panel. - Verified people panel was just me without browse capability. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9137 --- .../PhabricatorPeopleListController.php | 79 +--------------- .../query/PhabricatorPeopleSearchEngine.php | 93 +++++++++++++++++++ 2 files changed, 95 insertions(+), 77 deletions(-) diff --git a/src/applications/people/controller/PhabricatorPeopleListController.php b/src/applications/people/controller/PhabricatorPeopleListController.php index da3f2dd9dc..d1b8598f6c 100644 --- a/src/applications/people/controller/PhabricatorPeopleListController.php +++ b/src/applications/people/controller/PhabricatorPeopleListController.php @@ -1,7 +1,7 @@ delegateToController($controller); } - public function renderResultsList( - array $users, - PhabricatorSavedQuery $query) { - - assert_instances_of($users, 'PhabricatorUser'); - - $request = $this->getRequest(); - $viewer = $request->getUser(); - - $list = new PHUIObjectItemListView(); - - $is_approval = ($query->getQueryKey() == 'approval'); - - foreach ($users as $user) { - $primary_email = $user->loadPrimaryEmail(); - if ($primary_email && $primary_email->getIsVerified()) { - $email = pht('Verified'); - } else { - $email = pht('Unverified'); - } - - $item = new PHUIObjectItemView(); - $item->setHeader($user->getFullName()) - ->setHref('/p/'.$user->getUsername().'/') - ->addAttribute(hsprintf('%s %s', - phabricator_date($user->getDateCreated(), $viewer), - phabricator_time($user->getDateCreated(), $viewer))) - ->addAttribute($email) - ->setImageURI($user->getProfileImageURI()); - - if ($is_approval && $primary_email) { - $item->addAttribute($primary_email->getAddress()); - } - - if ($user->getIsDisabled()) { - $item->addIcon('disable', pht('Disabled')); - } - - if (!$is_approval) { - if (!$user->getIsApproved()) { - $item->addIcon('perflab-grey', pht('Needs Approval')); - } - } - - if ($user->getIsAdmin()) { - $item->addIcon('highlight', pht('Admin')); - } - - if ($user->getIsSystemAgent()) { - $item->addIcon('computer', pht('Bot/Script')); - } - - if ($viewer->getIsAdmin()) { - $user_id = $user->getID(); - if ($is_approval) { - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('fa-ban') - ->setName(pht('Disable')) - ->setWorkflow(true) - ->setHref($this->getApplicationURI('disapprove/'.$user_id.'/'))); - $item->addAction( - id(new PHUIListItemView()) - ->setIcon('fa-thumbs-o-up') - ->setName(pht('Approve')) - ->setWorkflow(true) - ->setHref($this->getApplicationURI('approve/'.$user_id.'/'))); - } - } - - $list->addItem($item); - } - - return $list; - } } diff --git a/src/applications/people/query/PhabricatorPeopleSearchEngine.php b/src/applications/people/query/PhabricatorPeopleSearchEngine.php index 9b5ea5337d..7d16b4fb73 100644 --- a/src/applications/people/query/PhabricatorPeopleSearchEngine.php +++ b/src/applications/people/query/PhabricatorPeopleSearchEngine.php @@ -3,6 +3,10 @@ final class PhabricatorPeopleSearchEngine extends PhabricatorApplicationSearchEngine { + public function getApplicationClassName() { + return 'PhabricatorApplicationPeople'; + } + public function getCustomFieldObject() { return new PhabricatorUser(); } @@ -29,6 +33,20 @@ final class PhabricatorPeopleSearchEngine ->needPrimaryEmail(true) ->needProfileImage(true); + $viewer = $this->requireViewer(); + + // If the viewer can't browse the user directory, restrict the query to + // just the user's own profile. This is a little bit silly, but serves to + // restrict users from creating a dashboard panel which essentially just + // contains a user directory anyway. + $can_browse = PhabricatorPolicyFilter::hasCapability( + $viewer, + $this->getApplication(), + PeopleCapabilityBrowseUserDirectory::CAPABILITY); + if (!$can_browse) { + $query->withPHIDs(array($viewer->getPHID())); + } + $usernames = $saved->getParameter('usernames', array()); if ($usernames) { $query->withUsernames($usernames); @@ -170,4 +188,79 @@ final class PhabricatorPeopleSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + protected function renderResultList( + array $users, + PhabricatorSavedQuery $query, + array $handles) { + + assert_instances_of($users, 'PhabricatorUser'); + + $request = $this->getRequest(); + $viewer = $this->requireViewer(); + + $list = new PHUIObjectItemListView(); + + $is_approval = ($query->getQueryKey() == 'approval'); + + foreach ($users as $user) { + $primary_email = $user->loadPrimaryEmail(); + if ($primary_email && $primary_email->getIsVerified()) { + $email = pht('Verified'); + } else { + $email = pht('Unverified'); + } + + $item = new PHUIObjectItemView(); + $item->setHeader($user->getFullName()) + ->setHref('/p/'.$user->getUsername().'/') + ->addAttribute(phabricator_datetime($user->getDateCreated(), $viewer)) + ->addAttribute($email) + ->setImageURI($user->getProfileImageURI()); + + if ($is_approval && $primary_email) { + $item->addAttribute($primary_email->getAddress()); + } + + if ($user->getIsDisabled()) { + $item->addIcon('fa-ban', pht('Disabled')); + } + + if (!$is_approval) { + if (!$user->getIsApproved()) { + $item->addIcon('fa-clock-o', pht('Needs Approval')); + } + } + + if ($user->getIsAdmin()) { + $item->addIcon('fa-star', pht('Admin')); + } + + if ($user->getIsSystemAgent()) { + $item->addIcon('fa-desktop', pht('Bot/Script')); + } + + if ($viewer->getIsAdmin()) { + $user_id = $user->getID(); + if ($is_approval) { + $item->addAction( + id(new PHUIListItemView()) + ->setIcon('fa-ban') + ->setName(pht('Disable')) + ->setWorkflow(true) + ->setHref($this->getApplicationURI('disapprove/'.$user_id.'/'))); + $item->addAction( + id(new PHUIListItemView()) + ->setIcon('fa-thumbs-o-up') + ->setName(pht('Approve')) + ->setWorkflow(true) + ->setHref($this->getApplicationURI('approve/'.$user_id.'/'))); + } + } + + $list->addItem($item); + } + + return $list; + } + }