Page MenuHomePhabricator

D13749.id33210.diff
No OneTemporary

D13749.id33210.diff

diff --git a/resources/sql/autopatches/20150725.slowvote.mailkey.1.sql b/resources/sql/autopatches/20150725.slowvote.mailkey.1.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150725.slowvote.mailkey.1.sql
@@ -0,0 +1,2 @@
+ALTER TABLE {$NAMESPACE}_slowvote.slowvote_poll
+ ADD mailKey binary(20) NOT NULL;
diff --git a/resources/sql/autopatches/20150725.slowvote.mailkey.2.php b/resources/sql/autopatches/20150725.slowvote.mailkey.2.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20150725.slowvote.mailkey.2.php
@@ -0,0 +1,18 @@
+<?php
+
+$table = new PhabricatorSlowvotePoll();
+$conn_w = $table->establishConnection('w');
+$iterator = new LiskMigrationIterator($table);
+foreach ($iterator as $slowvote) {
+ $id = $slowvote->getID();
+
+ echo pht('Adding mail key for Slowvote %d...', $id);
+ echo "\n";
+
+ queryfx(
+ $conn_w,
+ 'UPDATE %T SET mailKey = %s WHERE id = %d',
+ $table->getTableName(),
+ Filesystem::readRandomCharacters(20),
+ $id);
+}
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2792,11 +2792,13 @@
'PhabricatorSlowvoteEditController' => 'applications/slowvote/controller/PhabricatorSlowvoteEditController.php',
'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php',
'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php',
+ 'PhabricatorSlowvoteMailReceiver' => 'applications/slowvote/mail/PhabricatorSlowvoteMailReceiver.php',
'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php',
'PhabricatorSlowvotePoll' => 'applications/slowvote/storage/PhabricatorSlowvotePoll.php',
'PhabricatorSlowvotePollController' => 'applications/slowvote/controller/PhabricatorSlowvotePollController.php',
'PhabricatorSlowvotePollPHIDType' => 'applications/slowvote/phid/PhabricatorSlowvotePollPHIDType.php',
'PhabricatorSlowvoteQuery' => 'applications/slowvote/query/PhabricatorSlowvoteQuery.php',
+ 'PhabricatorSlowvoteReplyHandler' => 'applications/slowvote/mail/PhabricatorSlowvoteReplyHandler.php',
'PhabricatorSlowvoteSchemaSpec' => 'applications/slowvote/storage/PhabricatorSlowvoteSchemaSpec.php',
'PhabricatorSlowvoteSearchEngine' => 'applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php',
'PhabricatorSlowvoteTransaction' => 'applications/slowvote/storage/PhabricatorSlowvoteTransaction.php',
@@ -6782,6 +6784,7 @@
'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteController',
+ 'PhabricatorSlowvoteMailReceiver' => 'PhabricatorObjectMailReceiver',
'PhabricatorSlowvoteOption' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvotePoll' => array(
'PhabricatorSlowvoteDAO',
@@ -6797,6 +6800,7 @@
'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvotePollPHIDType' => 'PhabricatorPHIDType',
'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorSlowvoteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhabricatorSlowvoteSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorSlowvoteSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorSlowvoteTransaction' => 'PhabricatorApplicationTransaction',
diff --git a/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
--- a/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
+++ b/src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
@@ -8,7 +8,7 @@
}
public function getEditorObjectsDescription() {
- return pht('Slowvotes');
+ return pht('Slowvote');
}
public function getTransactionTypes() {
@@ -111,4 +111,71 @@
return;
}
+ protected function shouldSendMail(
+ PhabricatorLiskDAO $object,
+ array $xactions) {
+ return true;
+ }
+
+ public function getMailTagsMap() {
+ return array(
+ PhabricatorSlowvoteTransaction::MAILTAG_DETAILS =>
+ pht('Someone changes the poll details.'),
+ PhabricatorSlowvoteTransaction::MAILTAG_RESPONSES =>
+ pht('Someone votes on a poll.'),
+ PhabricatorSlowvoteTransaction::MAILTAG_OTHER =>
+ pht('Other poll activity not listed above occurs.'),
+ );
+ }
+
+ protected function buildMailTemplate(PhabricatorLiskDAO $object) {
+ $monogram = $object->getMonogram();
+ $name = $object->getQuestion();
+
+ return id(new PhabricatorMetaMTAMail())
+ ->setSubject("{$monogram}: {$name}")
+ ->addHeader('Thread-Topic', $monogram);
+ }
+
+ protected function buildMailBody(
+ PhabricatorLiskDAO $object,
+ array $xactions) {
+
+ $body = parent::buildMailBody($object, $xactions);
+ $description = $object->getDescription();
+
+ if (strlen($description)) {
+ $body->addTextSection(
+ pht('SLOWVOTE DESCRIPTION'),
+ $object->getDescription());
+ }
+
+ $body->addLinkSection(
+ pht('SLOWVOTE DETAIL'),
+ PhabricatorEnv::getProductionURI('/'.$object->getMonogram()));
+
+ return $body;
+ }
+
+ protected function getMailTo(PhabricatorLiskDAO $object) {
+ return array(
+ $object->getAuthorPHID(),
+ $this->requireActor()->getPHID(),
+ );
+ }
+ protected function getMailSubjectPrefix() {
+ return '[Slowvote]';
+ }
+
+ protected function buildReplyHandler(PhabricatorLiskDAO $object) {
+ return id(new PhabricatorSlowvoteReplyHandler())
+ ->setMailReceiver($object);
+ }
+
+ protected function shouldPublishFeedStory(
+ PhabricatorLiskDAO $object,
+ array $xactions) {
+ return true;
+ }
+
}
diff --git a/src/applications/slowvote/mail/PhabricatorSlowvoteMailReceiver.php b/src/applications/slowvote/mail/PhabricatorSlowvoteMailReceiver.php
new file mode 100644
--- /dev/null
+++ b/src/applications/slowvote/mail/PhabricatorSlowvoteMailReceiver.php
@@ -0,0 +1,28 @@
+<?php
+
+final class PhabricatorSlowvoteMailReceiver
+ extends PhabricatorObjectMailReceiver {
+
+ public function isEnabled() {
+ return PhabricatorApplication::isClassInstalled(
+ 'PhabricatorSlowvoteApplication');
+ }
+
+ protected function getObjectPattern() {
+ return 'V[1-9]\d*';
+ }
+
+ protected function loadObject($pattern, PhabricatorUser $viewer) {
+ $id = (int)substr($pattern, 4);
+
+ return id(new PhabricatorSlowvoteQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($id))
+ ->executeOne();
+ }
+
+ protected function getTransactionReplyHandler() {
+ return new PhabricatorSlowvoteReplyHandler();
+ }
+
+}
diff --git a/src/applications/slowvote/mail/PhabricatorSlowvoteReplyHandler.php b/src/applications/slowvote/mail/PhabricatorSlowvoteReplyHandler.php
new file mode 100644
--- /dev/null
+++ b/src/applications/slowvote/mail/PhabricatorSlowvoteReplyHandler.php
@@ -0,0 +1,16 @@
+<?php
+
+final class PhabricatorSlowvoteReplyHandler
+ extends PhabricatorApplicationTransactionReplyHandler {
+
+ public function validateMailReceiver($mail_receiver) {
+ if (!($mail_receiver instanceof PhabricatorSlowvotePoll)) {
+ throw new Exception(pht('Mail receiver is not a %s!', 'Slowvote'));
+ }
+ }
+
+ public function getObjectPrefix() {
+ return 'V';
+ }
+
+}
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
--- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
@@ -24,6 +24,7 @@
protected $responseVisibility;
protected $shuffle;
protected $method;
+ protected $mailKey;
protected $viewPolicy;
protected $isClosed = 0;
protected $spacePHID;
@@ -57,6 +58,7 @@
'method' => 'uint32',
'description' => 'text',
'isClosed' => 'bool',
+ 'mailKey' => 'bytes20',
),
self::CONFIG_KEY_SCHEMA => array(
'key_phid' => null,
@@ -106,6 +108,13 @@
return $this;
}
+ public function save() {
+ if (!$this->getMailKey()) {
+ $this->setMailKey(Filesystem::readRandomCharacters(20));
+ }
+ return parent::save();
+ }
+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
--- a/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
@@ -9,6 +9,10 @@
const TYPE_SHUFFLE = 'vote:shuffle';
const TYPE_CLOSE = 'vote:close';
+ const MAILTAG_DETAILS = 'vote:details';
+ const MAILTAG_RESPONSES = 'vote:responses';
+ const MAILTAG_OTHER = 'vote:vote';
+
public function getApplicationName() {
return 'slowvote';
}
@@ -152,5 +156,26 @@
$this->getNewValue());
}
+ public function getMailTags() {
+ $tags = parent::getMailTags();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_QUESTION:
+ case self::TYPE_DESCRIPTION:
+ case self::TYPE_SHUFFLE:
+ case self::TYPE_CLOSE:
+ $tags[] = self::MAILTAG_DETAILS;
+ break;
+ case self::TYPE_RESPONSES:
+ $tags[] = self::MAILTAG_RESPONSES;
+ break;
+ default:
+ $tags[] = self::MAILTAG_OTHER;
+ break;
+ }
+
+ return $tags;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Oct 16 2024, 8:04 PM (4 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6718985
Default Alt Text
D13749.id33210.diff (9 KB)

Event Timeline