mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-11 03:44:48 +01:00
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
This commit is contained in:
parent
e6f6a58f93
commit
5b3ccfd95f
2 changed files with 95 additions and 77 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPeopleListController extends PhabricatorPeopleController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
final class PhabricatorPeopleListController
|
||||
extends PhabricatorPeopleController {
|
||||
|
||||
private $key;
|
||||
|
||||
|
@ -32,79 +32,4 @@ final class PhabricatorPeopleListController extends PhabricatorPeopleController
|
|||
return $this->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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue