Path: blob/master/src/applications/auth/editor/PhabricatorAuthProviderConfigEditor.php
12256 views
<?php12final class PhabricatorAuthProviderConfigEditor3extends PhabricatorApplicationTransactionEditor {45public function getEditorApplicationClass() {6return 'PhabricatorAuthApplication';7}89public function getEditorObjectsDescription() {10return pht('Auth Providers');11}1213public function getTransactionTypes() {14$types = parent::getTransactionTypes();1516$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE;17$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN;18$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION;19$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LINK;20$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK;21$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS;22$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN;23$types[] = PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY;2425return $types;26}2728protected function getCustomTransactionOldValue(29PhabricatorLiskDAO $object,30PhabricatorApplicationTransaction $xaction) {3132switch ($xaction->getTransactionType()) {33case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:34if ($object->getIsEnabled() === null) {35return null;36} else {37return (int)$object->getIsEnabled();38}39case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN:40return (int)$object->getShouldAllowLogin();41case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION:42return (int)$object->getShouldAllowRegistration();43case PhabricatorAuthProviderConfigTransaction::TYPE_LINK:44return (int)$object->getShouldAllowLink();45case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK:46return (int)$object->getShouldAllowUnlink();47case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS:48return (int)$object->getShouldTrustEmails();49case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN:50return (int)$object->getShouldAutoLogin();51case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY:52$key = $xaction->getMetadataValue(53PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY);54return $object->getProperty($key);55}56}5758protected function getCustomTransactionNewValue(59PhabricatorLiskDAO $object,60PhabricatorApplicationTransaction $xaction) {6162switch ($xaction->getTransactionType()) {63case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:64case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN:65case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION:66case PhabricatorAuthProviderConfigTransaction::TYPE_LINK:67case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK:68case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS:69case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN:70case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY:71return $xaction->getNewValue();72}73}7475protected function applyCustomInternalTransaction(76PhabricatorLiskDAO $object,77PhabricatorApplicationTransaction $xaction) {78$v = $xaction->getNewValue();79switch ($xaction->getTransactionType()) {80case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:81return $object->setIsEnabled($v);82case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN:83return $object->setShouldAllowLogin($v);84case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION:85return $object->setShouldAllowRegistration($v);86case PhabricatorAuthProviderConfigTransaction::TYPE_LINK:87return $object->setShouldAllowLink($v);88case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK:89return $object->setShouldAllowUnlink($v);90case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS:91return $object->setShouldTrustEmails($v);92case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN:93return $object->setShouldAutoLogin($v);94case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY:95$key = $xaction->getMetadataValue(96PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY);97return $object->setProperty($key, $v);98}99}100101protected function applyCustomExternalTransaction(102PhabricatorLiskDAO $object,103PhabricatorApplicationTransaction $xaction) {104return;105}106107protected function mergeTransactions(108PhabricatorApplicationTransaction $u,109PhabricatorApplicationTransaction $v) {110111$type = $u->getTransactionType();112switch ($type) {113case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:114case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN:115case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION:116case PhabricatorAuthProviderConfigTransaction::TYPE_LINK:117case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK:118case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS:119case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN:120// For these types, last transaction wins.121return $v;122}123124return parent::mergeTransactions($u, $v);125}126127protected function validateAllTransactions(128PhabricatorLiskDAO $object,129array $xactions) {130131$errors = parent::validateAllTransactions($object, $xactions);132133$locked_config_key = 'auth.lock-config';134$is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);135136if ($is_locked) {137$errors[] = new PhabricatorApplicationTransactionValidationError(138null,139pht('Config Locked'),140pht('Authentication provider configuration is locked, and can not be '.141'changed without being unlocked.'),142null);143}144145return $errors;146}147148}149150151