1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-22 04:31:13 +01:00

Add PhabricatorAuthProviderConfigQuery

Summary: Ref T1536. See D6196. Code not called yet.

Test Plan: Static checks only.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6197
This commit is contained in:
epriestley 2013-06-17 10:49:18 -07:00
parent 5f29ccaaca
commit f0ddfe6565
4 changed files with 130 additions and 2 deletions

View file

@ -822,7 +822,9 @@ phutil_register_library_map(array(
'PhabricatorAuthLoginController' => 'applications/auth/controller/PhabricatorAuthLoginController.php',
'PhabricatorAuthProvider' => 'applications/auth/provider/PhabricatorAuthProvider.php',
'PhabricatorAuthProviderConfig' => 'applications/auth/storage/PhabricatorAuthProviderConfig.php',
'PhabricatorAuthProviderConfigQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigQuery.php',
'PhabricatorAuthProviderConfigTransaction' => 'applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php',
'PhabricatorAuthProviderConfigTransactionQuery' => 'applications/auth/query/PhabricatorAuthProviderConfigTransactionQuery.php',
'PhabricatorAuthProviderLDAP' => 'applications/auth/provider/PhabricatorAuthProviderLDAP.php',
'PhabricatorAuthProviderOAuth' => 'applications/auth/provider/PhabricatorAuthProviderOAuth.php',
'PhabricatorAuthProviderOAuthDisqus' => 'applications/auth/provider/PhabricatorAuthProviderOAuthDisqus.php',
@ -2688,8 +2690,14 @@ phutil_register_library_map(array(
'PhabricatorAuthDAO' => 'PhabricatorLiskDAO',
'PhabricatorAuthLinkController' => 'PhabricatorAuthController',
'PhabricatorAuthLoginController' => 'PhabricatorAuthController',
'PhabricatorAuthProviderConfig' => 'PhabricatorAuthDAO',
'PhabricatorAuthProviderConfig' =>
array(
0 => 'PhabricatorAuthDAO',
1 => 'PhabricatorPolicyInterface',
),
'PhabricatorAuthProviderConfigQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorAuthProviderConfigTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorAuthProviderConfigTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorAuthProviderLDAP' => 'PhabricatorAuthProvider',
'PhabricatorAuthProviderOAuth' => 'PhabricatorAuthProvider',
'PhabricatorAuthProviderOAuthDisqus' => 'PhabricatorAuthProviderOAuth',

View file

@ -0,0 +1,86 @@
<?php
final class PhabricatorAuthProviderConfigQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
const STATUS_ALL = 'status:all';
const STATUS_ENABLED = 'status:enabled';
private $status = self::STATUS_ALL;
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withStatus($status) {
$this->status = $status;
return $this;
}
public static function getStatusOptions() {
return array(
self::STATUS_ALL => pht('All Providers'),
self::STATUS_ENABLED => pht('Enabled Providers'),
);
}
protected function loadPage() {
$table = new PhabricatorAuthProviderConfig();
$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);
}
protected 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);
}
$status = $this->status;
switch ($status) {
case self::STATUS_ALL:
break;
case self::STATUS_ENABLED:
$where[] = qsprintf(
$conn_r,
'isEnabled = 1');
break;
default:
throw new Exception("Unknown status '{$status}'!");
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
}

View file

@ -0,0 +1,10 @@
<?php
final class PhabricatorAuthProviderConfigTransactionQuery
extends PhabricatorApplicationTransactionQuery {
protected function getTemplateApplicationTransaction() {
return new PhabricatorAuthProviderConfigTransaction();
}
}

View file

@ -1,6 +1,7 @@
<?php
final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO {
final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO
implements PhabricatorPolicyInterface {
protected $phid;
protected $providerClass;
@ -38,4 +39,27 @@ final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO {
}
/* -( 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 $viewer) {
return false;
}
}