Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/query/PhabricatorPeopleSearchEngine.php
Show All 14 Lines | public function getCustomFieldObject() { | ||||
return new PhabricatorUser(); | return new PhabricatorUser(); | ||||
} | } | ||||
public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function buildSavedQueryFromRequest(AphrontRequest $request) { | ||||
$saved = new PhabricatorSavedQuery(); | $saved = new PhabricatorSavedQuery(); | ||||
$saved->setParameter('usernames', $request->getStrList('usernames')); | $saved->setParameter('usernames', $request->getStrList('usernames')); | ||||
$saved->setParameter('nameLike', $request->getStr('nameLike')); | $saved->setParameter('nameLike', $request->getStr('nameLike')); | ||||
$saved->setParameter('isAdmin', $request->getStr('isAdmin')); | |||||
$saved->setParameter('isDisabled', $request->getStr('isDisabled')); | $saved->setParameter( | ||||
$saved->setParameter('isSystemAgent', $request->getStr('isSystemAgent')); | 'isAdmin', | ||||
$saved->setParameter('needsApproval', $request->getStr('needsApproval')); | $this->readBoolFromRequest($request, 'isAdmin')); | ||||
$saved->setParameter( | |||||
'isDisabled', | |||||
$this->readBoolFromRequest($request, 'isDisabled')); | |||||
$saved->setParameter( | |||||
'isSystemAgent', | |||||
$this->readBoolFromRequest($request, 'isSystemAgent')); | |||||
$saved->setParameter( | |||||
'needsApproval', | |||||
$this->readBoolFromRequest($request, 'needsApproval')); | |||||
$saved->setParameter('createdStart', $request->getStr('createdStart')); | $saved->setParameter('createdStart', $request->getStr('createdStart')); | ||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd')); | $saved->setParameter('createdEnd', $request->getStr('createdEnd')); | ||||
$this->readCustomFieldsFromRequest($request, $saved); | $this->readCustomFieldsFromRequest($request, $saved); | ||||
return $saved; | return $saved; | ||||
} | } | ||||
Show All 25 Lines | public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | ||||
if ($like) { | if ($like) { | ||||
$query->withNameLike($like); | $query->withNameLike($like); | ||||
} | } | ||||
$is_admin = $saved->getParameter('isAdmin'); | $is_admin = $saved->getParameter('isAdmin'); | ||||
$is_disabled = $saved->getParameter('isDisabled'); | $is_disabled = $saved->getParameter('isDisabled'); | ||||
$is_system_agent = $saved->getParameter('isSystemAgent'); | $is_system_agent = $saved->getParameter('isSystemAgent'); | ||||
$needs_approval = $saved->getParameter('needsApproval'); | $needs_approval = $saved->getParameter('needsApproval'); | ||||
$no_disabled = $saved->getParameter('noDisabled'); | |||||
if ($is_admin) { | if ($is_admin !== null) { | ||||
$query->withIsAdmin(true); | $query->withIsAdmin($is_admin); | ||||
} | } | ||||
if ($is_disabled) { | if ($is_disabled !== null) { | ||||
$query->withIsDisabled(true); | $query->withIsDisabled($is_disabled); | ||||
} else if ($no_disabled) { | |||||
$query->withIsDisabled(false); | |||||
} | } | ||||
if ($is_system_agent) { | if ($is_system_agent !== null) { | ||||
$query->withIsSystemAgent(true); | $query->withIsSystemAgent($is_system_agent); | ||||
} | } | ||||
if ($needs_approval) { | if ($needs_approval !== null) { | ||||
$query->withIsApproved(false); | $query->withIsApproved(!$needs_approval); | ||||
} | } | ||||
$start = $this->parseDateTime($saved->getParameter('createdStart')); | $start = $this->parseDateTime($saved->getParameter('createdStart')); | ||||
$end = $this->parseDateTime($saved->getParameter('createdEnd')); | $end = $this->parseDateTime($saved->getParameter('createdEnd')); | ||||
if ($start) { | if ($start) { | ||||
$query->withDateCreatedAfter($start); | $query->withDateCreatedAfter($start); | ||||
} | } | ||||
Show All 9 Lines | final class PhabricatorPeopleSearchEngine | ||||
public function buildSearchForm( | public function buildSearchForm( | ||||
AphrontFormView $form, | AphrontFormView $form, | ||||
PhabricatorSavedQuery $saved) { | PhabricatorSavedQuery $saved) { | ||||
$usernames = $saved->getParameter('usernames', array()); | $usernames = $saved->getParameter('usernames', array()); | ||||
$like = $saved->getParameter('nameLike'); | $like = $saved->getParameter('nameLike'); | ||||
$is_admin = $saved->getParameter('isAdmin'); | $is_admin = $this->getBoolFromQuery($saved, 'isAdmin'); | ||||
$is_disabled = $saved->getParameter('isDisabled'); | $is_disabled = $this->getBoolFromQuery($saved, 'isDisabled'); | ||||
$is_system_agent = $saved->getParameter('isSystemAgent'); | $is_system_agent = $this->getBoolFromQuery($saved, 'isSystemAgent'); | ||||
$needs_approval = $saved->getParameter('needsApproval'); | $needs_approval = $this->getBoolFromQuery($saved, 'needsApproval'); | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('usernames') | ->setName('usernames') | ||||
->setLabel(pht('Usernames')) | ->setLabel(pht('Usernames')) | ||||
->setValue(implode(', ', $usernames))) | ->setValue(implode(', ', $usernames))) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('nameLike') | ->setName('nameLike') | ||||
->setLabel(pht('Name Contains')) | ->setLabel(pht('Name Contains')) | ||||
->setValue($like)) | ->setValue($like)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormCheckboxControl()) | id(new AphrontFormSelectControl()) | ||||
->setLabel('Role') | ->setName('isAdmin') | ||||
->addCheckbox( | ->setLabel(pht('Administrators')) | ||||
'isAdmin', | ->setValue($is_admin) | ||||
1, | ->setOptions( | ||||
pht('Show only administrators.'), | array( | ||||
$is_admin) | '' => pht('(Show All)'), | ||||
->addCheckbox( | 'true' => pht('Show Only Administrators'), | ||||
'isDisabled', | 'false' => pht('Hide Administrators'), | ||||
1, | ))) | ||||
pht('Show only disabled users.'), | ->appendChild( | ||||
$is_disabled) | id(new AphrontFormSelectControl()) | ||||
->addCheckbox( | ->setName('isDisabled') | ||||
'isSystemAgent', | ->setLabel(pht('Disabled')) | ||||
1, | ->setValue($is_disabled) | ||||
pht('Show only bots.'), | ->setOptions( | ||||
$is_system_agent) | array( | ||||
->addCheckbox( | '' => pht('(Show All)'), | ||||
'needsApproval', | 'true' => pht('Show Only Disabled Users'), | ||||
1, | 'false' => pht('Hide Disabled Users'), | ||||
pht('Show only users who need approval.'), | ))) | ||||
$needs_approval)); | ->appendChild( | ||||
id(new AphrontFormSelectControl()) | |||||
->setName('isSystemAgent') | |||||
->setLabel(pht('Bots')) | |||||
->setValue($is_system_agent) | |||||
->setOptions( | |||||
array( | |||||
'' => pht('(Show All)'), | |||||
'true' => pht('Show Only Bots'), | |||||
'false' => pht('Hide Bots'), | |||||
))) | |||||
->appendChild( | |||||
id(new AphrontFormSelectControl()) | |||||
->setName('needsApproval') | |||||
->setLabel(pht('Needs Approval')) | |||||
->setValue($needs_approval) | |||||
->setOptions( | |||||
array( | |||||
'' => pht('(Show All)'), | |||||
'true' => pht('Show Only Unapproved Users'), | |||||
'false' => pht('Hide Unapproved Users'), | |||||
))); | |||||
$this->appendCustomFieldsToForm($form, $saved); | $this->appendCustomFieldsToForm($form, $saved); | ||||
$this->buildDateRange( | $this->buildDateRange( | ||||
$form, | $form, | ||||
$saved, | $saved, | ||||
'createdStart', | 'createdStart', | ||||
pht('Joined After'), | pht('Joined After'), | ||||
'createdEnd', | 'createdEnd', | ||||
pht('Joined Before')); | pht('Joined Before')); | ||||
} | } | ||||
protected function getURI($path) { | protected function getURI($path) { | ||||
return '/people/'.$path; | return '/people/'.$path; | ||||
} | } | ||||
protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
$names = array( | $names = array( | ||||
'active' => pht('Active'), | |||||
'all' => pht('All'), | 'all' => pht('All'), | ||||
); | ); | ||||
$viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
if ($viewer->getIsAdmin()) { | if ($viewer->getIsAdmin()) { | ||||
$names['approval'] = pht('Approval Queue'); | $names['approval'] = pht('Approval Queue'); | ||||
} | } | ||||
return $names; | return $names; | ||||
} | } | ||||
public function buildSavedQueryFromBuiltin($query_key) { | public function buildSavedQueryFromBuiltin($query_key) { | ||||
$query = $this->newSavedQuery(); | $query = $this->newSavedQuery(); | ||||
$query->setQueryKey($query_key); | $query->setQueryKey($query_key); | ||||
switch ($query_key) { | switch ($query_key) { | ||||
case 'all': | case 'all': | ||||
return $query; | return $query; | ||||
case 'active': | |||||
return $query | |||||
->setParameter('isDisabled', false); | |||||
case 'approval': | case 'approval': | ||||
return $query | return $query | ||||
->setParameter('needsApproval', true) | ->setParameter('needsApproval', true) | ||||
->setParameter('noDisabled', true); | ->setParameter('isDisabled', true); | ||||
} | } | ||||
return parent::buildSavedQueryFromBuiltin($query_key); | return parent::buildSavedQueryFromBuiltin($query_key); | ||||
} | } | ||||
protected function renderResultList( | protected function renderResultList( | ||||
array $users, | array $users, | ||||
PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
Show All 37 Lines | foreach ($users as $user) { | ||||
} | } | ||||
} | } | ||||
if ($user->getIsAdmin()) { | if ($user->getIsAdmin()) { | ||||
$item->addIcon('fa-star', pht('Admin')); | $item->addIcon('fa-star', pht('Admin')); | ||||
} | } | ||||
if ($user->getIsSystemAgent()) { | if ($user->getIsSystemAgent()) { | ||||
$item->addIcon('fa-desktop', pht('Bot/Script')); | $item->addIcon('fa-desktop', pht('Bot')); | ||||
} | } | ||||
if ($viewer->getIsAdmin()) { | if ($viewer->getIsAdmin()) { | ||||
$user_id = $user->getID(); | $user_id = $user->getID(); | ||||
if ($is_approval) { | if ($is_approval) { | ||||
$item->addAction( | $item->addAction( | ||||
id(new PHUIListItemView()) | id(new PHUIListItemView()) | ||||
->setIcon('fa-ban') | ->setIcon('fa-ban') | ||||
Show All 19 Lines |