Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/storage/PhabricatorCalendarExport.php
12253 views
1
<?php
2
3
final class PhabricatorCalendarExport extends PhabricatorCalendarDAO
4
implements
5
PhabricatorPolicyInterface,
6
PhabricatorApplicationTransactionInterface,
7
PhabricatorDestructibleInterface {
8
9
protected $name;
10
protected $authorPHID;
11
protected $policyMode;
12
protected $queryKey;
13
protected $secretKey;
14
protected $isDisabled = 0;
15
16
const MODE_PUBLIC = 'public';
17
const MODE_PRIVILEGED = 'privileged';
18
19
public static function initializeNewCalendarExport(PhabricatorUser $actor) {
20
return id(new self())
21
->setAuthorPHID($actor->getPHID())
22
->setPolicyMode(self::MODE_PRIVILEGED)
23
->setIsDisabled(0);
24
}
25
26
protected function getConfiguration() {
27
return array(
28
self::CONFIG_AUX_PHID => true,
29
self::CONFIG_COLUMN_SCHEMA => array(
30
'name' => 'text',
31
'policyMode' => 'text64',
32
'queryKey' => 'text64',
33
'secretKey' => 'bytes20',
34
'isDisabled' => 'bool',
35
),
36
self::CONFIG_KEY_SCHEMA => array(
37
'key_author' => array(
38
'columns' => array('authorPHID'),
39
),
40
'key_secret' => array(
41
'columns' => array('secretKey'),
42
'unique' => true,
43
),
44
),
45
) + parent::getConfiguration();
46
}
47
48
public function getPHIDType() {
49
return PhabricatorCalendarExportPHIDType::TYPECONST;
50
}
51
52
public function save() {
53
if (!$this->getSecretKey()) {
54
$this->setSecretKey(Filesystem::readRandomCharacters(20));
55
}
56
57
return parent::save();
58
}
59
60
public function getURI() {
61
$id = $this->getID();
62
return "/calendar/export/{$id}/";
63
}
64
65
private static function getPolicyModeMap() {
66
return array(
67
self::MODE_PUBLIC => array(
68
'icon' => 'fa-globe',
69
'name' => pht('Public'),
70
'color' => 'bluegrey',
71
'summary' => pht(
72
'Export only public data.'),
73
'description' => pht(
74
'Only publicly available data is exported.'),
75
),
76
self::MODE_PRIVILEGED => array(
77
'icon' => 'fa-unlock-alt',
78
'name' => pht('Privileged'),
79
'color' => 'red',
80
'summary' => pht(
81
'Export private data.'),
82
'description' => pht(
83
'Anyone who knows the URI for this export can view all event '.
84
'details as though they were logged in with your account.'),
85
),
86
);
87
}
88
89
private static function getPolicyModeSpec($const) {
90
return idx(self::getPolicyModeMap(), $const, array());
91
}
92
93
public static function getPolicyModeName($const) {
94
$spec = self::getPolicyModeSpec($const);
95
return idx($spec, 'name', $const);
96
}
97
98
public static function getPolicyModeIcon($const) {
99
$spec = self::getPolicyModeSpec($const);
100
return idx($spec, 'icon', $const);
101
}
102
103
public static function getPolicyModeColor($const) {
104
$spec = self::getPolicyModeSpec($const);
105
return idx($spec, 'color', $const);
106
}
107
108
public static function getPolicyModeSummary($const) {
109
$spec = self::getPolicyModeSpec($const);
110
return idx($spec, 'summary', $const);
111
}
112
113
public static function getPolicyModeDescription($const) {
114
$spec = self::getPolicyModeSpec($const);
115
return idx($spec, 'description', $const);
116
}
117
118
public static function getPolicyModes() {
119
return array_keys(self::getPolicyModeMap());
120
}
121
122
public static function getAvailablePolicyModes() {
123
$modes = array();
124
125
if (PhabricatorEnv::getEnvConfig('policy.allow-public')) {
126
$modes[] = self::MODE_PUBLIC;
127
}
128
129
$modes[] = self::MODE_PRIVILEGED;
130
131
return $modes;
132
}
133
134
public function getICSFilename() {
135
return PhabricatorSlug::normalizeProjectSlug($this->getName()).'.ics';
136
}
137
138
public function getICSURI() {
139
$secret_key = $this->getSecretKey();
140
$ics_name = $this->getICSFilename();
141
return "/calendar/export/ics/{$secret_key}/{$ics_name}";
142
}
143
144
/* -( PhabricatorPolicyInterface )----------------------------------------- */
145
146
147
public function getCapabilities() {
148
return array(
149
PhabricatorPolicyCapability::CAN_VIEW,
150
PhabricatorPolicyCapability::CAN_EDIT,
151
);
152
}
153
154
public function getPolicy($capability) {
155
return $this->getAuthorPHID();
156
}
157
158
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
159
return false;
160
}
161
162
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
163
164
165
public function getApplicationTransactionEditor() {
166
return new PhabricatorCalendarExportEditor();
167
}
168
169
public function getApplicationTransactionTemplate() {
170
return new PhabricatorCalendarExportTransaction();
171
}
172
173
174
/* -( PhabricatorDestructibleInterface )----------------------------------- */
175
176
177
public function destroyObjectPermanently(
178
PhabricatorDestructionEngine $engine) {
179
$this->delete();
180
}
181
182
}
183
184