@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade user account activity logs to modern construction

Summary: Depends on D18965. Ref T13049. Move this Query and SearchEngine to be a little more modern, to prepare for Export support.

Test Plan:
- Used all the query fields, viewed activity logs via People and Settings.
- I'm not sure the "Session" query is used/useful and may remove it before I'm done here, but I just left it in place for now.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

Differential Revision: https://secure.phabricator.com/D18966

+70 -144
+15 -24
src/applications/people/query/PhabricatorPeopleLogQuery.php
··· 40 40 return $this; 41 41 } 42 42 43 - protected function loadPage() { 44 - $table = new PhabricatorUserLog(); 45 - $conn_r = $table->establishConnection('r'); 46 - 47 - $data = queryfx_all( 48 - $conn_r, 49 - 'SELECT * FROM %T %Q %Q %Q', 50 - $table->getTableName(), 51 - $this->buildWhereClause($conn_r), 52 - $this->buildOrderClause($conn_r), 53 - $this->buildLimitClause($conn_r)); 43 + public function newResultObject() { 44 + return new PhabricatorUserLog(); 45 + } 54 46 55 - return $table->loadAllFromArray($data); 47 + protected function loadPage() { 48 + return $this->loadStandardPage($this->newResultObject()); 56 49 } 57 50 58 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 59 - $where = array(); 51 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 52 + $where = parent::buildWhereClauseParts($conn); 60 53 61 54 if ($this->actorPHIDs !== null) { 62 55 $where[] = qsprintf( 63 - $conn_r, 56 + $conn, 64 57 'actorPHID IN (%Ls)', 65 58 $this->actorPHIDs); 66 59 } 67 60 68 61 if ($this->userPHIDs !== null) { 69 62 $where[] = qsprintf( 70 - $conn_r, 63 + $conn, 71 64 'userPHID IN (%Ls)', 72 65 $this->userPHIDs); 73 66 } 74 67 75 68 if ($this->relatedPHIDs !== null) { 76 69 $where[] = qsprintf( 77 - $conn_r, 78 - 'actorPHID IN (%Ls) OR userPHID IN (%Ls)', 70 + $conn, 71 + '(actorPHID IN (%Ls) OR userPHID IN (%Ls))', 79 72 $this->relatedPHIDs, 80 73 $this->relatedPHIDs); 81 74 } 82 75 83 76 if ($this->sessionKeys !== null) { 84 77 $where[] = qsprintf( 85 - $conn_r, 78 + $conn, 86 79 'session IN (%Ls)', 87 80 $this->sessionKeys); 88 81 } 89 82 90 83 if ($this->actions !== null) { 91 84 $where[] = qsprintf( 92 - $conn_r, 85 + $conn, 93 86 'action IN (%Ls)', 94 87 $this->actions); 95 88 } 96 89 97 90 if ($this->remoteAddressPrefix !== null) { 98 91 $where[] = qsprintf( 99 - $conn_r, 92 + $conn, 100 93 'remoteAddr LIKE %>', 101 94 $this->remoteAddressPrefix); 102 95 } 103 96 104 - $where[] = $this->buildPagingClause($conn_r); 105 - 106 - return $this->formatWhereClause($where); 97 + return $where; 107 98 } 108 99 109 100 public function getQueryApplicationClass() {
+47 -110
src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
··· 15 15 return 500; 16 16 } 17 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()); 18 + public function newQuery() { 19 + $query = new PhabricatorPeopleLogQuery(); 46 20 47 21 // NOTE: If the viewer isn't an administrator, always restrict the query to 48 22 // related records. This echoes the policy logic of these logs. This is ··· 54 28 $query->withRelatedPHIDs(array($viewer->getPHID())); 55 29 } 56 30 57 - $actor_phids = $saved->getParameter('actorPHIDs', array()); 58 - if ($actor_phids) { 59 - $query->withActorPHIDs($actor_phids); 31 + return $query; 32 + } 33 + 34 + protected function buildQueryFromParameters(array $map) { 35 + $query = $this->newQuery(); 36 + 37 + if ($map['userPHIDs']) { 38 + $query->withUserPHIDs($map['userPHIDs']); 60 39 } 61 40 62 - $user_phids = $saved->getParameter('userPHIDs', array()); 63 - if ($user_phids) { 64 - $query->withUserPHIDs($user_phids); 41 + if ($map['actorPHIDs']) { 42 + $query->withActorPHIDs($map['actorPHIDs']); 65 43 } 66 44 67 - $actions = $saved->getParameter('actions', array()); 68 - if ($actions) { 69 - $query->withActions($actions); 45 + if ($map['actions']) { 46 + $query->withActions($map['actions']); 70 47 } 71 48 72 - $remote_prefix = $saved->getParameter('ip'); 73 - if (strlen($remote_prefix)) { 74 - $query->withRemoteAddressprefix($remote_prefix); 49 + if (strlen($map['ip'])) { 50 + $query->withRemoteAddressPrefix($map['ip']); 75 51 } 76 52 77 - $sessions = $saved->getParameter('sessions', array()); 78 - if ($sessions) { 79 - $query->withSessionKeys($sessions); 53 + if ($map['sessions']) { 54 + $query->withSessionKeys($map['sessions']); 80 55 } 81 56 82 57 return $query; 83 58 } 84 59 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 - $actions = $saved->getParameter('actions', array()); 93 - $remote_prefix = $saved->getParameter('ip'); 94 - $sessions = $saved->getParameter('sessions', array()); 95 - 96 - $actions = array_fuse($actions); 97 - $action_control = id(new AphrontFormCheckboxControl()) 98 - ->setLabel(pht('Actions')); 99 - $action_types = PhabricatorUserLog::getActionTypeMap(); 100 - foreach ($action_types as $type => $label) { 101 - $action_control->addCheckbox( 102 - 'actions[]', 103 - $type, 104 - $label, 105 - isset($actions[$label])); 106 - } 107 - 108 - $form 109 - ->appendControl( 110 - id(new AphrontFormTokenizerControl()) 111 - ->setDatasource(new PhabricatorPeopleDatasource()) 112 - ->setName('actors') 113 - ->setLabel(pht('Actors')) 114 - ->setValue($actor_phids)) 115 - ->appendControl( 116 - id(new AphrontFormTokenizerControl()) 117 - ->setDatasource(new PhabricatorPeopleDatasource()) 118 - ->setName('users') 119 - ->setLabel(pht('Users')) 120 - ->setValue($user_phids)) 121 - ->appendChild($action_control) 122 - ->appendChild( 123 - id(new AphrontFormTextControl()) 124 - ->setLabel(pht('Filter IP')) 125 - ->setName('ip') 126 - ->setValue($remote_prefix)) 127 - ->appendChild( 128 - id(new AphrontFormTextControl()) 129 - ->setLabel(pht('Sessions')) 130 - ->setName('sessions') 131 - ->setValue(implode(', ', $sessions))); 132 - 60 + protected function buildCustomSearchFields() { 61 + return array( 62 + id(new PhabricatorUsersSearchField()) 63 + ->setKey('userPHIDs') 64 + ->setAliases(array('users', 'user', 'userPHID')) 65 + ->setLabel(pht('Users')) 66 + ->setDescription(pht('Search for activity affecting specific users.')), 67 + id(new PhabricatorUsersSearchField()) 68 + ->setKey('actorPHIDs') 69 + ->setAliases(array('actors', 'actor', 'actorPHID')) 70 + ->setLabel(pht('Actors')) 71 + ->setDescription(pht('Search for activity by specific users.')), 72 + id(new PhabricatorSearchCheckboxesField()) 73 + ->setKey('actions') 74 + ->setLabel(pht('Actions')) 75 + ->setDescription(pht('Search for particular types of activity.')) 76 + ->setOptions(PhabricatorUserLog::getActionTypeMap()), 77 + id(new PhabricatorSearchTextField()) 78 + ->setKey('ip') 79 + ->setLabel(pht('Filter IP')) 80 + ->setDescription(pht('Search for actions by remote address.')), 81 + id(new PhabricatorSearchStringListField()) 82 + ->setKey('sessions') 83 + ->setLabel(pht('Sessions')) 84 + ->setDescription(pht('Search for activity in particular sessions.')), 85 + ); 133 86 } 134 87 135 88 protected function getURI($path) { ··· 156 109 return parent::buildSavedQueryFromBuiltin($query_key); 157 110 } 158 111 159 - protected function getRequiredHandlePHIDsForResultList( 160 - array $logs, 161 - PhabricatorSavedQuery $query) { 162 - 163 - $phids = array(); 164 - foreach ($logs as $log) { 165 - $phids[$log->getActorPHID()] = true; 166 - $phids[$log->getUserPHID()] = true; 167 - } 168 - 169 - return array_keys($phids); 170 - } 171 - 172 112 protected function renderResultList( 173 113 array $logs, 174 114 PhabricatorSavedQuery $query, ··· 179 119 180 120 $table = id(new PhabricatorUserLogView()) 181 121 ->setUser($viewer) 182 - ->setLogs($logs) 183 - ->setHandles($handles); 122 + ->setLogs($logs); 184 123 185 124 if ($viewer->getIsAdmin()) { 186 125 $table->setSearchBaseURI($this->getApplicationURI('logs/')); 187 126 } 188 127 189 - $result = new PhabricatorApplicationSearchResultView(); 190 - $result->setTable($table); 191 - 192 - return $result; 128 + return id(new PhabricatorApplicationSearchResultView()) 129 + ->setTable($table); 193 130 } 194 131 }
+7 -8
src/applications/people/view/PhabricatorUserLogView.php
··· 3 3 final class PhabricatorUserLogView extends AphrontView { 4 4 5 5 private $logs; 6 - private $handles; 7 6 private $searchBaseURI; 8 7 9 8 public function setSearchBaseURI($search_base_uri) { ··· 17 16 return $this; 18 17 } 19 18 20 - public function setHandles(array $handles) { 21 - assert_instances_of($handles, 'PhabricatorObjectHandle'); 22 - $this->handles = $handles; 23 - return $this; 24 - } 25 - 26 19 public function render() { 27 20 $logs = $this->logs; 28 - $handles = $this->handles; 29 21 $viewer = $this->getUser(); 22 + 23 + $phids = array(); 24 + foreach ($logs as $log) { 25 + $phids[] = $log->getActorPHID(); 26 + $phids[] = $log->getUserPHID(); 27 + } 28 + $handles = $viewer->loadHandles($phids); 30 29 31 30 $action_map = PhabricatorUserLog::getActionTypeMap(); 32 31 $base_uri = $this->searchBaseURI;
+1 -2
src/applications/settings/panel/PhabricatorActivitySettingsPanel.php
··· 43 43 44 44 $table = id(new PhabricatorUserLogView()) 45 45 ->setUser($viewer) 46 - ->setLogs($logs) 47 - ->setHandles($handles); 46 + ->setLogs($logs); 48 47 49 48 $panel = $this->newBox(pht('Account Activity Logs'), $table); 50 49