1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-02 03:32:42 +01:00

Show edit transactions for AuthProviders

Summary: Ref T1536. When auth providers are edited, show the edit history.

Test Plan: {F46400}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, chad

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6203
This commit is contained in:
epriestley 2013-06-17 10:53:29 -07:00
parent c6374e25d5
commit 07423211e9
5 changed files with 158 additions and 13 deletions

View file

@ -15,7 +15,6 @@ final class PhabricatorAuthEditController
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $request->getUser(); $viewer = $request->getUser();
$provider = null;
if ($this->configID) { if ($this->configID) {
$config = id(new PhabricatorAuthProviderConfigQuery()) $config = id(new PhabricatorAuthProviderConfigQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -30,6 +29,11 @@ final class PhabricatorAuthEditController
return new Aphront404Response(); return new Aphront404Response();
} }
$provider = $config->getProvider();
if (!$provider) {
return new Aphront404Response();
}
$is_new = false; $is_new = false;
} else { } else {
$providers = PhabricatorAuthProvider::getAllBaseProviders(); $providers = PhabricatorAuthProvider::getAllBaseProviders();
@ -88,17 +92,17 @@ final class PhabricatorAuthEditController
$xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) $xactions[] = id(new PhabricatorAuthProviderConfigTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION) PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION)
->setNewValue($request->getInt('allowRegistration')); ->setNewValue($request->getInt('allowRegistration', 0));
$xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) $xactions[] = id(new PhabricatorAuthProviderConfigTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorAuthProviderConfigTransaction::TYPE_LINK) PhabricatorAuthProviderConfigTransaction::TYPE_LINK)
->setNewValue($request->getInt('allowLink')); ->setNewValue($request->getInt('allowLink', 0));
$xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) $xactions[] = id(new PhabricatorAuthProviderConfigTransaction())
->setTransactionType( ->setTransactionType(
PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK) PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK)
->setNewValue($request->getInt('allowUnlink')); ->setNewValue($request->getInt('allowUnlink', 0));
if (!$errors) { if (!$errors) {
$editor = id(new PhabricatorAuthProviderConfigEditor()) $editor = id(new PhabricatorAuthProviderConfigEditor())
@ -199,8 +203,14 @@ final class PhabricatorAuthEditController
$xaction_view = null; $xaction_view = null;
if (!$is_new) { if (!$is_new) {
$xactions = id(new PhabricatorAuthProviderConfigTransactionQuery()); $xactions = id(new PhabricatorAuthProviderConfigTransactionQuery())
// TOOD: ... ->withObjectPHIDs(array($config->getPHID()))
->setViewer($viewer)
->execute();
$xaction_view = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setTransactions($xactions);
} }
return $this->buildApplicationPage( return $this->buildApplicationPage(
@ -208,7 +218,7 @@ final class PhabricatorAuthEditController
$crumbs, $crumbs,
$errors, $errors,
$form, $form,
$xaction_view $xaction_view,
), ),
array( array(
'title' => $title, 'title' => $title,

View file

@ -21,13 +21,17 @@ final class PhabricatorAuthProviderConfigEditor
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:
return $object->getIsEnabled(); if ($object->getIsEnabled() === null) {
return null;
} else {
return (int)$object->getIsEnabled();
}
case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION:
return $object->getShouldAllowRegistration(); return (int)$object->getShouldAllowRegistration();
case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: case PhabricatorAuthProviderConfigTransaction::TYPE_LINK:
return $object->getShouldAllowLink(); return (int)$object->getShouldAllowLink();
case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK:
return $object->getShouldAllowUnlink(); return (int)$object->getShouldAllowUnlink();
case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY:
// TODO // TODO
throw new Exception("TODO"); throw new Exception("TODO");
@ -51,7 +55,6 @@ final class PhabricatorAuthProviderConfigEditor
protected function applyCustomInternalTransaction( protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object, PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) { PhabricatorApplicationTransaction $xaction) {
$v = $xaction->getNewValue(); $v = $xaction->getNewValue();
switch ($xaction->getTransactionType()) { switch ($xaction->getTransactionType()) {
case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:

View file

@ -2,6 +2,21 @@
abstract class PhabricatorAuthProvider { abstract class PhabricatorAuthProvider {
private $providerConfig;
public function attachProviderConfig(PhabricatorAuthProviderConfig $config) {
$this->providerConfig = $config;
return $this;
}
public function getProviderConfig() {
if ($this->config === null) {
throw new Exception(
"Call attachProviderConfig() before getProviderConfig()!");
}
return $this->config;
}
public function getNameForCreate() { public function getNameForCreate() {
return $this->getProviderName(); return $this->getProviderName();
} }

View file

@ -7,7 +7,7 @@ final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO
protected $providerType; protected $providerType;
protected $providerDomain; protected $providerDomain;
protected $isEnabled = 0; protected $isEnabled;
protected $shouldAllowLogin = 0; protected $shouldAllowLogin = 0;
protected $shouldAllowRegistration = 0; protected $shouldAllowRegistration = 0;
protected $shouldAllowLink = 0; protected $shouldAllowLink = 0;
@ -15,6 +15,8 @@ final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO
protected $properties = array(); protected $properties = array();
private $provider;
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_AUTH); PhabricatorPHIDConstants::PHID_TYPE_AUTH);
@ -38,6 +40,23 @@ final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO
return $this; return $this;
} }
public function getProvider() {
if (!$this->provider) {
$base = PhabricatorAuthProvider::getAllBaseProviders();
$found = null;
foreach ($base as $provider) {
if (get_class($provider) == $this->providerClass) {
$found = $provider;
break;
}
}
if ($found) {
$this->provider = id(clone $found)->attachProviderConfig($this);
}
}
return $this->provider;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -25,5 +25,103 @@ final class PhabricatorAuthProviderConfigTransaction
return pht('authentication provider'); return pht('authentication provider');
} }
public function getIcon() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_ENABLE:
if ($new) {
return 'new';
} else {
return 'delete';
}
}
return parent::getIcon();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_ENABLE:
if ($new) {
return 'green';
} else {
return 'red';
}
}
return parent::getColor();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_ENABLE:
if ($old === null) {
return pht(
'%s created this provider.',
$this->renderHandleLink($author_phid));
} else if ($new) {
return pht(
'%s enabled this provider.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s disabled this provider.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_REGISTRATION:
if ($new) {
return pht(
'%s enabled registration.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s disabled registration.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_LINK:
if ($new) {
return pht(
'%s enabled accont linking.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s disabled account linking.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_UNLINK:
if ($new) {
return pht(
'%s enabled account unlinking.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s disabled account unlinking.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_PROPERTY:
// TODO
return pht(
'%s edited a property of this provider.',
$this->renderHandleLink($author_phid));
break;
}
return parent::getTitle();
}
} }