Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMailProperties.php
12256 views
1
<?php
2
3
final class PhabricatorMetaMTAMailProperties
4
extends PhabricatorMetaMTADAO
5
implements PhabricatorPolicyInterface {
6
7
protected $objectPHID;
8
protected $mailProperties = array();
9
10
protected function getConfiguration() {
11
return array(
12
self::CONFIG_SERIALIZATION => array(
13
'mailProperties' => self::SERIALIZATION_JSON,
14
),
15
self::CONFIG_COLUMN_SCHEMA => array(),
16
self::CONFIG_KEY_SCHEMA => array(
17
'key_object' => array(
18
'columns' => array('objectPHID'),
19
'unique' => true,
20
),
21
),
22
) + parent::getConfiguration();
23
}
24
25
public function getMailProperty($key, $default = null) {
26
return idx($this->mailProperties, $key, $default);
27
}
28
29
public function setMailProperty($key, $value) {
30
$this->mailProperties[$key] = $value;
31
return $this;
32
}
33
34
public static function loadMailKey($object) {
35
// If this is an older object with an onboard "mailKey" property, just
36
// use it.
37
// TODO: We should eventually get rid of these and get rid of this
38
// piece of code.
39
if ($object->hasProperty('mailKey')) {
40
return $object->getMailKey();
41
}
42
43
$viewer = PhabricatorUser::getOmnipotentUser();
44
$object_phid = $object->getPHID();
45
46
$properties = id(new PhabricatorMetaMTAMailPropertiesQuery())
47
->setViewer($viewer)
48
->withObjectPHIDs(array($object_phid))
49
->executeOne();
50
if (!$properties) {
51
$properties = id(new self())
52
->setObjectPHID($object_phid);
53
}
54
55
$mail_key = $properties->getMailProperty('mailKey');
56
if ($mail_key !== null) {
57
return $mail_key;
58
}
59
60
$mail_key = Filesystem::readRandomCharacters(20);
61
$properties->setMailProperty('mailKey', $mail_key);
62
63
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
64
$properties->save();
65
unset($unguarded);
66
67
return $mail_key;
68
}
69
70
71
/* -( PhabricatorPolicyInterface )----------------------------------------- */
72
73
74
public function getCapabilities() {
75
return array(
76
PhabricatorPolicyCapability::CAN_VIEW,
77
);
78
}
79
80
public function getPolicy($capability) {
81
switch ($capability) {
82
case PhabricatorPolicyCapability::CAN_VIEW:
83
return PhabricatorPolicies::POLICY_NOONE;
84
}
85
}
86
87
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
88
return false;
89
}
90
91
}
92
93