Guarantee terms in PhabricatorAuthPasswordEngine are strings
[phabricator/blender.git] / src / applications / auth / editor / PhabricatorAuthProviderConfigEditor.php
blob1e75edfbf01bb223a262325f669d13cce4c4fe68
1 <?php
3 final class PhabricatorAuthProviderConfigEditor
4 extends PhabricatorApplicationTransactionEditor {
6 public function getEditorApplicationClass() {
7 return 'PhabricatorAuthApplication';
10 public function getEditorObjectsDescription() {
11 return pht('Auth Providers');
14 public function getTransactionTypes() {
15 $types = parent::getTransactionTypes();
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;
26 return $types;
29 protected function getCustomTransactionOldValue(
30 PhabricatorLiskDAO $object,
31 PhabricatorApplicationTransaction $xaction) {
33 switch ($xaction->getTransactionType()) {
34 case PhabricatorAuthProviderConfigTransaction::TYPE_ENABLE:
35 if ($object->getIsEnabled() === null) {
36 return null;
37 } else {
38 return (int)$object->getIsEnabled();
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);
59 protected function getCustomTransactionNewValue(
60 PhabricatorLiskDAO $object,
61 PhabricatorApplicationTransaction $xaction) {
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();
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);
102 protected function applyCustomExternalTransaction(
103 PhabricatorLiskDAO $object,
104 PhabricatorApplicationTransaction $xaction) {
105 return;
108 protected function mergeTransactions(
109 PhabricatorApplicationTransaction $u,
110 PhabricatorApplicationTransaction $v) {
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;
125 return parent::mergeTransactions($u, $v);
128 protected function validateAllTransactions(
129 PhabricatorLiskDAO $object,
130 array $xactions) {
132 $errors = parent::validateAllTransactions($object, $xactions);
134 $locked_config_key = 'auth.lock-config';
135 $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);
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);
146 return $errors;