Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/editor/LegalpadDocumentEditor.php
13452 views
1
<?php
2
3
final class LegalpadDocumentEditor
4
extends PhabricatorApplicationTransactionEditor {
5
6
public function getEditorApplicationClass() {
7
return 'PhabricatorLegalpadApplication';
8
}
9
10
public function getEditorObjectsDescription() {
11
return pht('Legalpad Documents');
12
}
13
14
public function getTransactionTypes() {
15
$types = parent::getTransactionTypes();
16
17
$types[] = PhabricatorTransactions::TYPE_COMMENT;
18
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
19
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
20
21
return $types;
22
}
23
24
public function getCreateObjectTitle($author, $object) {
25
return pht('%s created this document.', $author);
26
}
27
28
public function getCreateObjectTitleForFeed($author, $object) {
29
return pht('%s created %s.', $author, $object);
30
}
31
32
protected function applyFinalEffects(
33
PhabricatorLiskDAO $object,
34
array $xactions) {
35
36
$is_contribution = false;
37
38
foreach ($xactions as $xaction) {
39
switch ($xaction->getTransactionType()) {
40
case LegalpadDocumentTitleTransaction::TRANSACTIONTYPE:
41
case LegalpadDocumentTextTransaction::TRANSACTIONTYPE:
42
$is_contribution = true;
43
break;
44
}
45
}
46
47
if ($is_contribution) {
48
$text = $object->getDocumentBody()->getText();
49
$title = $object->getDocumentBody()->getTitle();
50
$object->setVersions($object->getVersions() + 1);
51
52
$body = new LegalpadDocumentBody();
53
$body->setCreatorPHID($this->getActingAsPHID());
54
$body->setText($text);
55
$body->setTitle($title);
56
$body->setVersion($object->getVersions());
57
$body->setDocumentPHID($object->getPHID());
58
$body->save();
59
60
$object->setDocumentBodyPHID($body->getPHID());
61
62
$type = PhabricatorContributedToObjectEdgeType::EDGECONST;
63
id(new PhabricatorEdgeEditor())
64
->addEdge($this->getActingAsPHID(), $type, $object->getPHID())
65
->save();
66
67
$type = PhabricatorObjectHasContributorEdgeType::EDGECONST;
68
$contributors = PhabricatorEdgeQuery::loadDestinationPHIDs(
69
$object->getPHID(),
70
$type);
71
$object->setRecentContributorPHIDs(array_slice($contributors, 0, 3));
72
$object->setContributorCount(count($contributors));
73
74
$object->save();
75
}
76
77
return $xactions;
78
}
79
80
protected function validateAllTransactions(PhabricatorLiskDAO $object,
81
array $xactions) {
82
$errors = array();
83
84
$is_required = (bool)$object->getRequireSignature();
85
$document_type = $object->getSignatureType();
86
$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
87
88
foreach ($xactions as $xaction) {
89
switch ($xaction->getTransactionType()) {
90
case LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE:
91
$is_required = (bool)$xaction->getNewValue();
92
break;
93
case LegalpadDocumentSignatureTypeTransaction::TRANSACTIONTYPE:
94
$document_type = $xaction->getNewValue();
95
break;
96
}
97
}
98
99
if ($is_required && ($document_type != $individual)) {
100
$errors[] = new PhabricatorApplicationTransactionValidationError(
101
LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE,
102
pht('Invalid'),
103
pht('Only documents with signature type "individual" may '.
104
'require signing to log in.'),
105
null);
106
}
107
108
return $errors;
109
}
110
111
112
/* -( Sending Mail )------------------------------------------------------- */
113
114
protected function shouldSendMail(
115
PhabricatorLiskDAO $object,
116
array $xactions) {
117
return true;
118
}
119
120
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
121
return id(new LegalpadReplyHandler())
122
->setMailReceiver($object);
123
}
124
125
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
126
$id = $object->getID();
127
$title = $object->getDocumentBody()->getTitle();
128
129
return id(new PhabricatorMetaMTAMail())
130
->setSubject("L{$id}: {$title}");
131
}
132
133
protected function getMailTo(PhabricatorLiskDAO $object) {
134
return array(
135
$object->getCreatorPHID(),
136
$this->requireActor()->getPHID(),
137
);
138
}
139
140
protected function shouldImplyCC(
141
PhabricatorLiskDAO $object,
142
PhabricatorApplicationTransaction $xaction) {
143
144
switch ($xaction->getTransactionType()) {
145
case LegalpadDocumentTextTransaction::TRANSACTIONTYPE:
146
case LegalpadDocumentTitleTransaction::TRANSACTIONTYPE:
147
case LegalpadDocumentPreambleTransaction::TRANSACTIONTYPE:
148
case LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE:
149
return true;
150
}
151
152
return parent::shouldImplyCC($object, $xaction);
153
}
154
155
protected function buildMailBody(
156
PhabricatorLiskDAO $object,
157
array $xactions) {
158
159
$body = parent::buildMailBody($object, $xactions);
160
161
$body->addLinkSection(
162
pht('DOCUMENT DETAIL'),
163
PhabricatorEnv::getProductionURI('/legalpad/view/'.$object->getID().'/'));
164
165
return $body;
166
}
167
168
protected function getMailSubjectPrefix() {
169
return pht('[Legalpad]');
170
}
171
172
173
protected function shouldPublishFeedStory(
174
PhabricatorLiskDAO $object,
175
array $xactions) {
176
return false;
177
}
178
179
protected function supportsSearch() {
180
return false;
181
}
182
183
}
184
185