@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
at upstream/main 149 lines 5.9 kB view raw
1<?php 2 3final class PhabricatorAuthProviderConfigEditor 4 extends PhabricatorApplicationTransactionEditor { 5 6 public function getEditorApplicationClass() { 7 return PhabricatorAuthApplication::class; 8 } 9 10 public function getEditorObjectsDescription() { 11 return pht('Auth Providers'); 12 } 13 14 public function getTransactionTypes() { 15 $types = parent::getTransactionTypes(); 16 17 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE; 18 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN; 19 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION; 20 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LINK; 21 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK; 22 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS; 23 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN; 24 $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY; 25 26 return $types; 27 } 28 29 protected function getCustomTransactionOldValue( 30 PhabricatorLiskDAO $object, 31 PhabricatorApplicationTransaction $xaction) { 32 33 switch ($xaction->getTransactionType()) { 34 case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: 35 if ($object->getIsEnabled() === null) { 36 return null; 37 } else { 38 return (int)$object->getIsEnabled(); 39 } 40 case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: 41 return (int)$object->getShouldAllowLogin(); 42 case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: 43 return (int)$object->getShouldAllowRegistration(); 44 case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: 45 return (int)$object->getShouldAllowLink(); 46 case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: 47 return (int)$object->getShouldAllowUnlink(); 48 case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: 49 return (int)$object->getShouldTrustEmails(); 50 case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: 51 return (int)$object->getShouldAutoLogin(); 52 case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: 53 $key = $xaction->getMetadataValue( 54 PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); 55 return $object->getProperty($key); 56 } 57 } 58 59 protected function getCustomTransactionNewValue( 60 PhabricatorLiskDAO $object, 61 PhabricatorApplicationTransaction $xaction) { 62 63 switch ($xaction->getTransactionType()) { 64 case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: 65 case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: 66 case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: 67 case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: 68 case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: 69 case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: 70 case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: 71 case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: 72 return $xaction->getNewValue(); 73 } 74 } 75 76 protected function applyCustomInternalTransaction( 77 PhabricatorLiskDAO $object, 78 PhabricatorApplicationTransaction $xaction) { 79 $v = $xaction->getNewValue(); 80 switch ($xaction->getTransactionType()) { 81 case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: 82 return $object->setIsEnabled($v); 83 case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: 84 return $object->setShouldAllowLogin($v); 85 case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: 86 return $object->setShouldAllowRegistration($v); 87 case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: 88 return $object->setShouldAllowLink($v); 89 case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: 90 return $object->setShouldAllowUnlink($v); 91 case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: 92 return $object->setShouldTrustEmails($v); 93 case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: 94 return $object->setShouldAutoLogin($v); 95 case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: 96 $key = $xaction->getMetadataValue( 97 PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); 98 return $object->setProperty($key, $v); 99 } 100 } 101 102 protected function applyCustomExternalTransaction( 103 PhabricatorLiskDAO $object, 104 PhabricatorApplicationTransaction $xaction) { 105 return; 106 } 107 108 protected function mergeTransactions( 109 PhabricatorApplicationTransaction $u, 110 PhabricatorApplicationTransaction $v) { 111 112 $type = $u->getTransactionType(); 113 switch ($type) { 114 case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE: 115 case PhabricatorAuthProviderConfigTransaction::TYPE_LOGIN: 116 case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: 117 case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: 118 case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: 119 case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: 120 case PhabricatorAuthProviderConfigTransaction::TYPE_AUTO_LOGIN: 121 // For these types, last transaction wins. 122 return $v; 123 } 124 125 return parent::mergeTransactions($u, $v); 126 } 127 128 protected function validateAllTransactions( 129 PhabricatorLiskDAO $object, 130 array $xactions) { 131 132 $errors = parent::validateAllTransactions($object, $xactions); 133 134 $locked_config_key = 'auth.lock-config'; 135 $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key); 136 137 if ($is_locked) { 138 $errors[] = new PhabricatorApplicationTransactionValidationError( 139 null, 140 pht('Config Locked'), 141 pht('Authentication provider configuration is locked, and can not be '. 142 'changed without being unlocked.'), 143 null); 144 } 145 146 return $errors; 147 } 148 149}