Something went wrong. Try again.
@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
Something went wrong. Try again.
5.9 kB · 149 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150<?php
final class PhabricatorAuthProviderConfigEditor extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() { return PhabricatorAuthApplication::class; }
public function getEditorObjectsDescription() { return pht('Auth Providers'); }
public function getTransactionTypes() { $types = parent::getTransactionTypes();
$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LINK; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY;
return $types; }
protected function getCustomTransactionOldValue( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: if ($object->getIsEnabled() === null) { return null; } else { return (int)$object->getIsEnabled(); } case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: return (int)$object->getShouldAllowLogin(); case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: return (int)$object->getShouldAllowRegistration(); case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: return (int)$object->getShouldAllowLink(); case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: return (int)$object->getShouldAllowUnlink(); case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: return (int)$object->getShouldTrustEmails(); case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: return (int)$object->getShouldAutoLogin(); case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: $key = $xaction->getMetadataValue( PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); return $object->getProperty($key); } }
protected function getCustomTransactionNewValue( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) { case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: return $xaction->getNewValue(); } }
protected function applyCustomInternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { $v = $xaction->getNewValue(); switch ($xaction->getTransactionType()) { case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: return $object->setIsEnabled($v); case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: return $object->setShouldAllowLogin($v); case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: return $object->setShouldAllowRegistration($v); case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: return $object->setShouldAllowLink($v); case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: return $object->setShouldAllowUnlink($v); case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: return $object->setShouldTrustEmails($v); case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: return $object->setShouldAutoLogin($v); case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: $key = $xaction->getMetadataValue( PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); return $object->setProperty($key, $v); } }
protected function applyCustomExternalTransaction( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { return; }
protected function mergeTransactions( PhabricatorApplicationTransaction $u, PhabricatorApplicationTransaction $v) {
$type = $u->getTransactionType(); switch ($type) { case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: // For these types, last transaction wins. return $v; }
return parent::mergeTransactions($u, $v); }
protected function validateAllTransactions( PhabricatorLiskDAO $object, array $xactions) {
$errors = parent::validateAllTransactions($object, $xactions);
$locked_config_key = 'auth.lock-config'; $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);
if ($is_locked) { $errors[] = new PhabricatorApplicationTransactionValidationError( null, pht('Config Locked'), pht('Authentication provider configuration is locked, and can not be '. 'changed without being unlocked.'), null); }
return $errors; }
}