[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorPeopleLogSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Account Activity'); 8 } 9 10 public function getApplicationClassName() { 11 return 'PhabricatorPeopleApplication'; 12 } 13 14 public function getPageSize(PhabricatorSavedQuery $saved) { 15 return 500; 16 } 17 18 public function buildSavedQueryFromRequest(AphrontRequest $request) { 19 $saved = new PhabricatorSavedQuery(); 20 21 $saved->setParameter( 22 'userPHIDs', 23 $this->readUsersFromRequest($request, 'users')); 24 25 $saved->setParameter( 26 'actorPHIDs', 27 $this->readUsersFromRequest($request, 'actors')); 28 29 $saved->setParameter( 30 'actions', 31 $this->readListFromRequest($request, 'actions')); 32 33 $saved->setParameter( 34 'ip', 35 $request->getStr('ip')); 36 37 $saved->setParameter( 38 'sessions', 39 $this->readListFromRequest($request, 'sessions')); 40 41 return $saved; 42 } 43 44 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 45 $query = id(new PhabricatorPeopleLogQuery()); 46 47 // NOTE: If the viewer isn't an administrator, always restrict the query to 48 // related records. This echoes the policy logic of these logs. This is 49 // mostly a performance optimization, to prevent us from having to pull 50 // large numbers of logs that the user will not be able to see and filter 51 // them in-process. 52 $viewer = $this->requireViewer(); 53 if (!$viewer->getIsAdmin()) { 54 $query->withRelatedPHIDs(array($viewer->getPHID())); 55 } 56 57 $actor_phids = $saved->getParameter('actorPHIDs', array()); 58 if ($actor_phids) { 59 $query->withActorPHIDs($actor_phids); 60 } 61 62 $user_phids = $saved->getParameter('userPHIDs', array()); 63 if ($user_phids) { 64 $query->withUserPHIDs($user_phids); 65 } 66 67 $actions = $saved->getParameter('actions', array()); 68 if ($actions) { 69 $query->withActions($actions); 70 } 71 72 $remote_prefix = $saved->getParameter('ip'); 73 if (strlen($remote_prefix)) { 74 $query->withRemoteAddressprefix($remote_prefix); 75 } 76 77 $sessions = $saved->getParameter('sessions', array()); 78 if ($sessions) { 79 $query->withSessionKeys($sessions); 80 } 81 82 return $query; 83 } 84 85 public function buildSearchForm( 86 AphrontFormView $form, 87 PhabricatorSavedQuery $saved) { 88 89 $actor_phids = $saved->getParameter('actorPHIDs', array()); 90 $user_phids = $saved->getParameter('userPHIDs', array()); 91 92 $all_phids = array_merge( 93 $actor_phids, 94 $user_phids); 95 96 if ($all_phids) { 97 $handles = id(new PhabricatorHandleQuery()) 98 ->setViewer($this->requireViewer()) 99 ->withPHIDs($all_phids) 100 ->execute(); 101 } else { 102 $handles = array(); 103 } 104 105 $actor_handles = array_select_keys($handles, $actor_phids); 106 $user_handles = array_select_keys($handles, $user_phids); 107 108 $actions = $saved->getParameter('actions', array()); 109 $remote_prefix = $saved->getParameter('ip'); 110 $sessions = $saved->getParameter('sessions', array()); 111 112 $actions = array_fuse($actions); 113 $action_control = id(new AphrontFormCheckboxControl()) 114 ->setLabel(pht('Actions')); 115 $action_types = PhabricatorUserLog::getActionTypeMap(); 116 foreach ($action_types as $type => $label) { 117 $action_control->addCheckbox( 118 'actions[]', 119 $type, 120 $label, 121 isset($actions[$label])); 122 } 123 124 $form 125 ->appendChild( 126 id(new AphrontFormTokenizerControl()) 127 ->setDatasource(new PhabricatorPeopleDatasource()) 128 ->setName('actors') 129 ->setLabel(pht('Actors')) 130 ->setValue($actor_handles)) 131 ->appendChild( 132 id(new AphrontFormTokenizerControl()) 133 ->setDatasource(new PhabricatorPeopleDatasource()) 134 ->setName('users') 135 ->setLabel(pht('Users')) 136 ->setValue($user_handles)) 137 ->appendChild($action_control) 138 ->appendChild( 139 id(new AphrontFormTextControl()) 140 ->setLabel(pht('Filter IP')) 141 ->setName('ip') 142 ->setValue($remote_prefix)) 143 ->appendChild( 144 id(new AphrontFormTextControl()) 145 ->setLabel(pht('Sessions')) 146 ->setName('sessions') 147 ->setValue(implode(', ', $sessions))); 148 149 } 150 151 protected function getURI($path) { 152 return '/people/logs/'.$path; 153 } 154 155 public function getBuiltinQueryNames() { 156 $names = array( 157 'all' => pht('All'), 158 ); 159 160 return $names; 161 } 162 163 public function buildSavedQueryFromBuiltin($query_key) { 164 $query = $this->newSavedQuery(); 165 $query->setQueryKey($query_key); 166 167 switch ($query_key) { 168 case 'all': 169 return $query; 170 } 171 172 return parent::buildSavedQueryFromBuiltin($query_key); 173 } 174 175 protected function getRequiredHandlePHIDsForResultList( 176 array $logs, 177 PhabricatorSavedQuery $query) { 178 179 $phids = array(); 180 foreach ($logs as $log) { 181 $phids[$log->getActorPHID()] = true; 182 $phids[$log->getUserPHID()] = true; 183 } 184 185 return array_keys($phids); 186 } 187 188 protected function renderResultList( 189 array $logs, 190 PhabricatorSavedQuery $query, 191 array $handles) { 192 assert_instances_of($logs, 'PhabricatorUserLog'); 193 194 $viewer = $this->requireViewer(); 195 196 $table = id(new PhabricatorUserLogView()) 197 ->setUser($viewer) 198 ->setLogs($logs) 199 ->setHandles($handles); 200 201 if ($viewer->getIsAdmin()) { 202 $table->setSearchBaseURI($this->getApplicationURI('logs/')); 203 } 204 205 return id(new PHUIObjectBoxView()) 206 ->setHeaderText(pht('User Activity Logs')) 207 ->appendChild($table); 208 } 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |