Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13982435
D13749.id33256.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D13749.id33256.diff
View Options
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,17 @@
return $this;
}
+ public function getMonogram() {
+ return 'V'.$this->getID();
+ }
+
+ 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';
}
@@ -93,6 +97,82 @@
return parent::getTitle();
}
+ public function getTitleForFeed() {
+ $author_phid = $this->getAuthorPHID();
+ $object_phid = $this->getObjectPHID();
+
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ $type = $this->getTransactionType();
+ switch ($type) {
+ case self::TYPE_QUESTION:
+ if ($old === null) {
+ return pht(
+ '%s created %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+
+ } else {
+ return pht(
+ '%s renamed %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
+ case self::TYPE_DESCRIPTION:
+ if ($old === null) {
+ return pht(
+ '%s set the description of %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+
+ } else {
+ return pht(
+ '%s edited the description of %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
+ case self::TYPE_RESPONSES:
+ // TODO: This could be more detailed
+ return pht(
+ '%s changed who can see the responses of %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+
+ case self::TYPE_SHUFFLE:
+ if ($new) {
+ return pht(
+ '%s made %s responses appear in a random order.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+
+ } else {
+ return pht(
+ '%s made %s responses appear in a fixed order.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ case self::TYPE_CLOSE:
+ if ($new) {
+ return pht(
+ '%s closed %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+
+ } else {
+ return pht(
+ '%s reopened %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ }
+ break;
+ }
+
+ return parent::getTitleForFeed();
+ }
+
public function getIcon() {
$old = $this->getOldValue();
$new = $this->getNewValue();
@@ -152,5 +232,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
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 20, 11:18 PM (4 w, 11 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6718983
Default Alt Text
D13749.id33256.diff (12 KB)
Attached To
Mode
D13749: Add mail/feed to Slowvote
Attached
Detach File
Event Timeline
Log In to Comment