Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php
12256 views
1
<?php
2
3
final class PhabricatorMetaMTAApplicationEmail
4
extends PhabricatorMetaMTADAO
5
implements
6
PhabricatorPolicyInterface,
7
PhabricatorApplicationTransactionInterface,
8
PhabricatorDestructibleInterface,
9
PhabricatorSpacesInterface {
10
11
protected $applicationPHID;
12
protected $address;
13
protected $configData;
14
protected $spacePHID;
15
16
private $application = self::ATTACHABLE;
17
18
const CONFIG_DEFAULT_AUTHOR = 'config:default:author';
19
20
protected function getConfiguration() {
21
return array(
22
self::CONFIG_AUX_PHID => true,
23
self::CONFIG_SERIALIZATION => array(
24
'configData' => self::SERIALIZATION_JSON,
25
),
26
self::CONFIG_COLUMN_SCHEMA => array(
27
'address' => 'sort128',
28
),
29
self::CONFIG_KEY_SCHEMA => array(
30
'key_address' => array(
31
'columns' => array('address'),
32
'unique' => true,
33
),
34
'key_application' => array(
35
'columns' => array('applicationPHID'),
36
),
37
),
38
) + parent::getConfiguration();
39
}
40
41
public function generatePHID() {
42
return PhabricatorPHID::generateNewPHID(
43
PhabricatorMetaMTAApplicationEmailPHIDType::TYPECONST);
44
}
45
46
public static function initializeNewAppEmail(PhabricatorUser $actor) {
47
return id(new PhabricatorMetaMTAApplicationEmail())
48
->setSpacePHID($actor->getDefaultSpacePHID())
49
->setConfigData(array());
50
}
51
52
public function attachApplication(PhabricatorApplication $app) {
53
$this->application = $app;
54
return $this;
55
}
56
57
public function getApplication() {
58
return self::assertAttached($this->application);
59
}
60
61
public function setConfigValue($key, $value) {
62
$this->configData[$key] = $value;
63
return $this;
64
}
65
66
public function getConfigValue($key, $default = null) {
67
return idx($this->configData, $key, $default);
68
}
69
70
public function getDefaultAuthorPHID() {
71
return $this->getConfigValue(self::CONFIG_DEFAULT_AUTHOR);
72
}
73
74
public function getInUseMessage() {
75
$applications = PhabricatorApplication::getAllApplications();
76
$applications = mpull($applications, null, 'getPHID');
77
$application = idx(
78
$applications,
79
$this->getApplicationPHID());
80
if ($application) {
81
$message = pht(
82
'The address %s is configured to be used by the %s Application.',
83
$this->getAddress(),
84
$application->getName());
85
} else {
86
$message = pht(
87
'The address %s is configured to be used by an application.',
88
$this->getAddress());
89
}
90
91
return $message;
92
}
93
94
public function newAddress() {
95
return new PhutilEmailAddress($this->getAddress());
96
}
97
98
/* -( PhabricatorPolicyInterface )----------------------------------------- */
99
100
101
public function getCapabilities() {
102
return array(
103
PhabricatorPolicyCapability::CAN_VIEW,
104
PhabricatorPolicyCapability::CAN_EDIT,
105
);
106
}
107
108
public function getPolicy($capability) {
109
return $this->getApplication()->getPolicy($capability);
110
}
111
112
public function hasAutomaticCapability(
113
$capability,
114
PhabricatorUser $viewer) {
115
116
return $this->getApplication()->hasAutomaticCapability(
117
$capability,
118
$viewer);
119
}
120
121
public function describeAutomaticCapability($capability) {
122
return $this->getApplication()->describeAutomaticCapability($capability);
123
}
124
125
126
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
127
128
129
public function getApplicationTransactionEditor() {
130
return new PhabricatorMetaMTAApplicationEmailEditor();
131
}
132
133
public function getApplicationTransactionTemplate() {
134
return new PhabricatorMetaMTAApplicationEmailTransaction();
135
}
136
137
138
/* -( PhabricatorDestructibleInterface )----------------------------------- */
139
140
141
public function destroyObjectPermanently(
142
PhabricatorDestructionEngine $engine) {
143
$this->delete();
144
}
145
146
147
/* -( PhabricatorSpacesInterface )----------------------------------------- */
148
149
150
public function getSpacePHID() {
151
return $this->spacePHID;
152
}
153
154
}
155
156