@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
1<?php
2
3final class PhabricatorAuthProviderConfigTransaction
4 extends PhabricatorApplicationTransaction {
5
6 const TYPE_ENABLE = 'config:enable';
7 const TYPE_LOGIN = 'config:login';
8 const TYPE_REGISTRATION = 'config:registration';
9 const TYPE_LINK = 'config:link';
10 const TYPE_UNLINK = 'config:unlink';
11 const TYPE_TRUST_EMAILS = 'config:trustEmails';
12 const TYPE_AUTO_LOGIN = 'config:autoLogin';
13 const TYPE_PROPERTY = 'config:property';
14
15 const PROPERTY_KEY = 'auth:property';
16
17 public function getProvider() {
18 return $this->getObject()->getProvider();
19 }
20
21 public function getApplicationName() {
22 return 'auth';
23 }
24
25 public function getApplicationTransactionType() {
26 return PhabricatorAuthAuthProviderPHIDType::TYPECONST;
27 }
28
29 public function getIcon() {
30 $old = $this->getOldValue();
31 $new = $this->getNewValue();
32
33 switch ($this->getTransactionType()) {
34 case self::TYPE_ENABLE:
35 if ($new) {
36 return 'fa-check';
37 } else {
38 return 'fa-ban';
39 }
40 }
41
42 return parent::getIcon();
43 }
44
45 public function getColor() {
46 $old = $this->getOldValue();
47 $new = $this->getNewValue();
48
49 switch ($this->getTransactionType()) {
50 case self::TYPE_ENABLE:
51 if ($new) {
52 return 'green';
53 } else {
54 return 'indigo';
55 }
56 }
57
58 return parent::getColor();
59 }
60
61 public function getTitle() {
62 $author_phid = $this->getAuthorPHID();
63
64 $old = $this->getOldValue();
65 $new = $this->getNewValue();
66
67 switch ($this->getTransactionType()) {
68 case self::TYPE_ENABLE:
69 if ($old === null) {
70 return pht(
71 '%s created this provider.',
72 $this->renderHandleLink($author_phid));
73 } else if ($new) {
74 return pht(
75 '%s enabled this provider.',
76 $this->renderHandleLink($author_phid));
77 } else {
78 return pht(
79 '%s disabled this provider.',
80 $this->renderHandleLink($author_phid));
81 }
82 case self::TYPE_LOGIN:
83 if ($new) {
84 return pht(
85 '%s enabled login.',
86 $this->renderHandleLink($author_phid));
87 } else {
88 return pht(
89 '%s disabled login.',
90 $this->renderHandleLink($author_phid));
91 }
92 case self::TYPE_REGISTRATION:
93 if ($new) {
94 return pht(
95 '%s enabled registration.',
96 $this->renderHandleLink($author_phid));
97 } else {
98 return pht(
99 '%s disabled registration.',
100 $this->renderHandleLink($author_phid));
101 }
102 case self::TYPE_LINK:
103 if ($new) {
104 return pht(
105 '%s enabled account linking.',
106 $this->renderHandleLink($author_phid));
107 } else {
108 return pht(
109 '%s disabled account linking.',
110 $this->renderHandleLink($author_phid));
111 }
112 case self::TYPE_UNLINK:
113 if ($new) {
114 return pht(
115 '%s enabled account unlinking.',
116 $this->renderHandleLink($author_phid));
117 } else {
118 return pht(
119 '%s disabled account unlinking.',
120 $this->renderHandleLink($author_phid));
121 }
122 case self::TYPE_TRUST_EMAILS:
123 if ($new) {
124 return pht(
125 '%s enabled email trust.',
126 $this->renderHandleLink($author_phid));
127 } else {
128 return pht(
129 '%s disabled email trust.',
130 $this->renderHandleLink($author_phid));
131 }
132 case self::TYPE_AUTO_LOGIN:
133 if ($new) {
134 return pht(
135 '%s enabled auto login.',
136 $this->renderHandleLink($author_phid));
137 } else {
138 return pht(
139 '%s disabled auto login.',
140 $this->renderHandleLink($author_phid));
141 }
142 case self::TYPE_PROPERTY:
143 $provider = $this->getProvider();
144 if ($provider) {
145 $title = $provider->renderConfigPropertyTransactionTitle($this);
146 if (phutil_nonempty_stringlike($title)) {
147 return $title;
148 }
149 }
150
151 return pht(
152 '%s edited a property of this provider.',
153 $this->renderHandleLink($author_phid));
154 }
155
156 return parent::getTitle();
157 }
158
159}