mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Make Repositories partially policy-aware
Summary: Small step toward repository hosting. No user-visible changes. Test Plan: Looked at repositories in Diffusion. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D4227
This commit is contained in:
parent
fcc5366eff
commit
db89e23761
4 changed files with 124 additions and 6 deletions
|
@ -1064,6 +1064,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
|
||||
'PhabricatorRepositoryPullLocalDaemonTestCase' => 'applications/repository/daemon/__tests__/PhabricatorRepositoryPullLocalDaemonTestCase.php',
|
||||
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
||||
'PhabricatorRepositoryShortcut' => 'applications/repository/storage/PhabricatorRepositoryShortcut.php',
|
||||
'PhabricatorRepositorySvnCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositorySvnCommitChangeParserWorker.php',
|
||||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositorySvnCommitMessageParserWorker.php',
|
||||
|
@ -2295,7 +2296,11 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRemarkupRulePaste' => 'PhabricatorRemarkupRuleObjectName',
|
||||
'PhabricatorRemarkupRulePhriction' => 'PhutilRemarkupRule',
|
||||
'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule',
|
||||
'PhabricatorRepository' => 'PhabricatorRepositoryDAO',
|
||||
'PhabricatorRepository' =>
|
||||
array(
|
||||
0 => 'PhabricatorRepositoryDAO',
|
||||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorRepositoryArcanistProject' => 'PhabricatorRepositoryDAO',
|
||||
'PhabricatorRepositoryArcanistProjectDeleteController' => 'PhabricatorRepositoryController',
|
||||
'PhabricatorRepositoryArcanistProjectEditController' => 'PhabricatorRepositoryController',
|
||||
|
@ -2325,6 +2330,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
|
||||
'PhabricatorRepositoryPullLocalDaemonTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorRepositoryShortcut' => 'PhabricatorRepositoryDAO',
|
||||
'PhabricatorRepositorySvnCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
|
||||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||
|
|
|
@ -42,9 +42,10 @@ final class DiffusionHomeController extends DiffusionController {
|
|||
$shortcut_panel = null;
|
||||
}
|
||||
|
||||
$repository = new PhabricatorRepository();
|
||||
$repositories = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($user)
|
||||
->execute();
|
||||
|
||||
$repositories = $repository->loadAll();
|
||||
foreach ($repositories as $key => $repo) {
|
||||
if (!$repo->isTracked()) {
|
||||
unset($repositories[$key]);
|
||||
|
@ -56,11 +57,11 @@ final class DiffusionHomeController extends DiffusionController {
|
|||
$commits = array();
|
||||
if ($repository_ids) {
|
||||
$summaries = queryfx_all(
|
||||
$repository->establishConnection('r'),
|
||||
id(new PhabricatorRepository())->establishConnection('r'),
|
||||
'SELECT * FROM %T WHERE repositoryID IN (%Ld)',
|
||||
PhabricatorRepository::TABLE_SUMMARY,
|
||||
$repository_ids);
|
||||
$summaries = ipull($summaries, null, 'repositoryID');
|
||||
$summaries = ipull($summaries, null, 'repositoryID');
|
||||
|
||||
$commit_ids = array_filter(ipull($summaries, 'lastCommitID'));
|
||||
if ($commit_ids) {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRepositoryQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $callsigns;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withCallsigns(array $callsigns) {
|
||||
$this->callsigns = $callsigns;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadPage() {
|
||||
$table = new PhabricatorRepository();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q %Q %Q',
|
||||
$table->getTableName(),
|
||||
$this->buildWhereClause($conn_r),
|
||||
$this->buildOrderClause($conn_r),
|
||||
$this->buildLimitClause($conn_r));
|
||||
|
||||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->callsigns) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'callsign IN (%Ls)',
|
||||
$this->callsigns);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,8 @@
|
|||
/**
|
||||
* @task uri Repository URI Management
|
||||
*/
|
||||
final class PhabricatorRepository extends PhabricatorRepositoryDAO {
|
||||
final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
const TABLE_PATH = 'repository_path';
|
||||
const TABLE_PATHCHANGE = 'repository_pathchange';
|
||||
|
@ -602,4 +603,45 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO {
|
|||
$this->saveTransaction();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isGit() {
|
||||
$vcs = $this->getVersionControlSystem();
|
||||
return ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
|
||||
}
|
||||
|
||||
public function isSVN() {
|
||||
$vcs = $this->getVersionControlSystem();
|
||||
return ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_SVN);
|
||||
}
|
||||
|
||||
public function isHg() {
|
||||
$vcs = $this->getVersionControlSystem();
|
||||
return ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
||||
public function getCapabilities() {
|
||||
return array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
);
|
||||
}
|
||||
|
||||
public function getPolicy($capability) {
|
||||
switch ($capability) {
|
||||
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||
return PhabricatorPolicies::POLICY_USER;
|
||||
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||
return PhabricatorPolicies::POLICY_ADMIN;
|
||||
}
|
||||
}
|
||||
|
||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue