mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-03 20:22:46 +01:00
8a2863e3f7
Summary: Depends on D18970. Ref T13049. Currently, the policy for viewing remote addresses is: - In activity logs: administrators. - In push and pull logs: users who can edit the corresponding repository. This sort of makes sense, but is also sort of weird. Particularly, I think it's kind of hard to understand and predict, and hard to guess that this is the behavior we implement. The actual implementation is complex, too. Instead, just use the rule "administrators can see remote addresses" consistently across all applications. This should generally be more strict than the old rule, because administrators could usually have seen everyone's address in the activity logs anyway. It's also simpler and more expected, and I don't really know of any legit use cases for the "repository editor" rule. Test Plan: Viewed pull/push/activity logs as non-admin. Saw remote addresses as an admin, and none as a non-admin. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13049 Differential Revision: https://secure.phabricator.com/D18971
186 lines
4.9 KiB
PHP
186 lines
4.9 KiB
PHP
<?php
|
|
|
|
final class DiffusionPullLogSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function getResultTypeDescription() {
|
|
return pht('Pull Logs');
|
|
}
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorDiffusionApplication';
|
|
}
|
|
|
|
public function newQuery() {
|
|
return new PhabricatorRepositoryPullEventQuery();
|
|
}
|
|
|
|
protected function buildQueryFromParameters(array $map) {
|
|
$query = $this->newQuery();
|
|
|
|
if ($map['repositoryPHIDs']) {
|
|
$query->withRepositoryPHIDs($map['repositoryPHIDs']);
|
|
}
|
|
|
|
if ($map['pullerPHIDs']) {
|
|
$query->withPullerPHIDs($map['pullerPHIDs']);
|
|
}
|
|
|
|
if ($map['createdStart'] || $map['createdEnd']) {
|
|
$query->withEpochBetween(
|
|
$map['createdStart'],
|
|
$map['createdEnd']);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
protected function buildCustomSearchFields() {
|
|
return array(
|
|
id(new PhabricatorSearchDatasourceField())
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
->setKey('repositoryPHIDs')
|
|
->setAliases(array('repository', 'repositories', 'repositoryPHID'))
|
|
->setLabel(pht('Repositories'))
|
|
->setDescription(
|
|
pht('Search for pull logs for specific repositories.')),
|
|
id(new PhabricatorUsersSearchField())
|
|
->setKey('pullerPHIDs')
|
|
->setAliases(array('puller', 'pullers', 'pullerPHID'))
|
|
->setLabel(pht('Pullers'))
|
|
->setDescription(
|
|
pht('Search for pull logs by specific users.')),
|
|
id(new PhabricatorSearchDateField())
|
|
->setLabel(pht('Created After'))
|
|
->setKey('createdStart'),
|
|
id(new PhabricatorSearchDateField())
|
|
->setLabel(pht('Created Before'))
|
|
->setKey('createdEnd'),
|
|
);
|
|
}
|
|
|
|
protected function newExportFields() {
|
|
$viewer = $this->requireViewer();
|
|
|
|
$fields = array(
|
|
id(new PhabricatorPHIDExportField())
|
|
->setKey('repositoryPHID')
|
|
->setLabel(pht('Repository PHID')),
|
|
id(new PhabricatorStringExportField())
|
|
->setKey('repository')
|
|
->setLabel(pht('Repository')),
|
|
id(new PhabricatorPHIDExportField())
|
|
->setKey('pullerPHID')
|
|
->setLabel(pht('Puller PHID')),
|
|
id(new PhabricatorStringExportField())
|
|
->setKey('puller')
|
|
->setLabel(pht('Puller')),
|
|
id(new PhabricatorStringExportField())
|
|
->setKey('protocol')
|
|
->setLabel(pht('Protocol')),
|
|
id(new PhabricatorStringExportField())
|
|
->setKey('result')
|
|
->setLabel(pht('Result')),
|
|
id(new PhabricatorIntExportField())
|
|
->setKey('code')
|
|
->setLabel(pht('Code')),
|
|
id(new PhabricatorEpochExportField())
|
|
->setKey('date')
|
|
->setLabel(pht('Date')),
|
|
);
|
|
|
|
if ($viewer->getIsAdmin()) {
|
|
$fields[] = id(new PhabricatorStringExportField())
|
|
->setKey('remoteAddress')
|
|
->setLabel(pht('Remote Address'));
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
protected function newExportData(array $events) {
|
|
$viewer = $this->requireViewer();
|
|
|
|
$phids = array();
|
|
foreach ($events as $event) {
|
|
if ($event->getPullerPHID()) {
|
|
$phids[] = $event->getPullerPHID();
|
|
}
|
|
}
|
|
$handles = $viewer->loadHandles($phids);
|
|
|
|
$export = array();
|
|
foreach ($events as $event) {
|
|
$repository = $event->getRepository();
|
|
if ($repository) {
|
|
$repository_phid = $repository->getPHID();
|
|
$repository_name = $repository->getDisplayName();
|
|
} else {
|
|
$repository_phid = null;
|
|
$repository_name = null;
|
|
}
|
|
|
|
$puller_phid = $event->getPullerPHID();
|
|
if ($puller_phid) {
|
|
$puller_name = $handles[$puller_phid]->getName();
|
|
} else {
|
|
$puller_name = null;
|
|
}
|
|
|
|
$map = array(
|
|
'repositoryPHID' => $repository_phid,
|
|
'repository' => $repository_name,
|
|
'pullerPHID' => $puller_phid,
|
|
'puller' => $puller_name,
|
|
'protocol' => $event->getRemoteProtocol(),
|
|
'result' => $event->getResultType(),
|
|
'code' => $event->getResultCode(),
|
|
'date' => $event->getEpoch(),
|
|
);
|
|
|
|
if ($viewer->getIsAdmin()) {
|
|
$map['remoteAddress'] = $event->getRemoteAddress();
|
|
}
|
|
|
|
$export[] = $map;
|
|
}
|
|
|
|
return $export;
|
|
}
|
|
|
|
protected function getURI($path) {
|
|
return '/diffusion/pulllog/'.$path;
|
|
}
|
|
|
|
protected function getBuiltinQueryNames() {
|
|
return array(
|
|
'all' => pht('All Pull Logs'),
|
|
);
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
switch ($query_key) {
|
|
case 'all':
|
|
return $query;
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
protected function renderResultList(
|
|
array $logs,
|
|
PhabricatorSavedQuery $query,
|
|
array $handles) {
|
|
|
|
$table = id(new DiffusionPullLogListView())
|
|
->setViewer($this->requireViewer())
|
|
->setLogs($logs);
|
|
|
|
return id(new PhabricatorApplicationSearchResultView())
|
|
->setTable($table);
|
|
}
|
|
|
|
}
|