@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.

Allow filtering Conduit logs by caller type

Summary:
Similar to People search, allow filtering Conduit API logs by the type of caller (bot, non-bot, any). See use cases in T16331.

Closes T16331.

Test Plan:
* Make Conduit API calls from an average user account, a bot account, and anonymously.
* Go to http://phorge.localhost/conduit/log/query/advanced/
* Use the "Caller Type" dropdown to filter the list of calls. Combine with other criteria.

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16331

Differential Revision: https://we.phorge.it/D26481

+52 -6
+37 -6
src/applications/conduit/query/PhabricatorConduitLogQuery.php
··· 10 10 private $callerPHIDs; 11 11 private $methods; 12 12 private $methodStatuses; 13 + private $isSystemAgent; 13 14 private $epochMin; 14 15 private $epochMax; 15 16 ··· 30 31 31 32 public function withMethodStatuses(array $statuses) { 32 33 $this->methodStatuses = $statuses; 34 + return $this; 35 + } 36 + 37 + public function withIsSystemAgent($system_agent) { 38 + $this->isSystemAgent = $system_agent; 33 39 return $this; 34 40 } 35 41 ··· 49 55 if ($this->ids !== null) { 50 56 $where[] = qsprintf( 51 57 $conn, 52 - 'id IN (%Ld)', 58 + 'conduitlog.id IN (%Ld)', 53 59 $this->ids); 54 60 } 55 61 56 62 if ($this->callerPHIDs !== null) { 57 63 $where[] = qsprintf( 58 64 $conn, 59 - 'callerPHID IN (%Ls)', 65 + 'conduitlog.callerPHID IN (%Ls)', 60 66 $this->callerPHIDs); 61 67 } 62 68 63 69 if ($this->methods !== null) { 64 70 $where[] = qsprintf( 65 71 $conn, 66 - 'method IN (%Ls)', 72 + 'conduitlog.method IN (%Ls)', 67 73 $this->methods); 68 74 } 69 75 ··· 88 94 89 95 $where[] = qsprintf( 90 96 $conn, 91 - 'method IN (%Ls)', 97 + 'conduitlog.method IN (%Ls)', 92 98 $method_names); 93 99 } 94 100 101 + if ($this->isSystemAgent !== null) { 102 + $where[] = qsprintf( 103 + $conn, 104 + 'u.isSystemAgent = %d', 105 + (int)$this->isSystemAgent); 106 + } 107 + 95 108 if ($this->epochMin !== null) { 96 109 $where[] = qsprintf( 97 110 $conn, 98 - 'dateCreated >= %d', 111 + 'conduitlog.dateCreated >= %d', 99 112 $this->epochMin); 100 113 } 101 114 102 115 if ($this->epochMax !== null) { 103 116 $where[] = qsprintf( 104 117 $conn, 105 - 'dateCreated <= %d', 118 + 'conduitlog.dateCreated <= %d', 106 119 $this->epochMax); 107 120 } 108 121 109 122 return $where; 123 + } 124 + 125 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 126 + $joins = parent::buildJoinClauseParts($conn); 127 + 128 + if ($this->isSystemAgent !== null) { 129 + $user_table = new PhabricatorUser(); 130 + $joins[] = qsprintf( 131 + $conn, 132 + 'JOIN %R u ON u.phid = conduitlog.callerPHID', 133 + $user_table); 134 + } 135 + 136 + return $joins; 137 + } 138 + 139 + protected function getPrimaryTableAlias() { 140 + return 'conduitlog'; 110 141 } 111 142 112 143 public function getQueryApplicationClass() {
+15
src/applications/conduit/query/PhabricatorConduitLogSearchEngine.php
··· 26 26 $query->withCallerPHIDs($map['callerPHIDs']); 27 27 } 28 28 29 + if ($map['isBot'] !== null) { 30 + $query->withIsSystemAgent($map['isBot']); 31 + } 32 + 29 33 if ($map['methods']) { 30 34 $query->withMethods($map['methods']); 31 35 } ··· 50 54 ->setLabel(pht('Callers')) 51 55 ->setAliases(array('caller', 'callers')) 52 56 ->setDescription(pht('Find calls by specific users.')), 57 + id(new PhabricatorSearchThreeStateField()) 58 + ->setLabel(pht('Caller Type')) 59 + ->setKey('isBot') 60 + ->setAliases(array('isSystemAgent')) 61 + ->setOptions( 62 + pht('(Show All)'), 63 + pht('Show Only Bots'), 64 + pht('Hide Bots')) 65 + ->setDescription( 66 + pht( 67 + 'Pass true to find only bots, or false to omit bots.')), 53 68 id(new PhabricatorSearchStringListField()) 54 69 ->setKey('methods') 55 70 ->setLabel(pht('Methods'))