From 82edde8876ee5959c9aa77ffcc10fe7a94ff131f Mon Sep 17 00:00:00 2001 From: Chad Little Date: Sat, 25 Jul 2015 13:34:43 -0700 Subject: [PATCH] Add MAILTAGs to Badges Summary: Still doesn't mail yet, but the settings now show up. Test Plan: View email settings, see Badges options. Reviewers: eadler, epriestley Reviewed By: eadler, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D13712 --- .../autopatches/20150725.badges.mailkey.1.sql | 2 ++ .../autopatches/20150725.badges.mailkey.2.php | 18 ++++++++++++ src/__phutil_library_map__.php | 4 +++ .../badges/editor/PhabricatorBadgesEditor.php | 19 ++++++++++++- .../mail/PhabricatorBadgesMailReceiver.php | 28 +++++++++++++++++++ .../mail/PhabricatorBadgesReplyHandler.php | 16 +++++++++++ .../badges/storage/PhabricatorBadgesBadge.php | 9 ++++++ .../storage/PhabricatorBadgesTransaction.php | 27 ++++++++++++++++++ 8 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 resources/sql/autopatches/20150725.badges.mailkey.1.sql create mode 100644 resources/sql/autopatches/20150725.badges.mailkey.2.php create mode 100644 src/applications/badges/mail/PhabricatorBadgesMailReceiver.php create mode 100644 src/applications/badges/mail/PhabricatorBadgesReplyHandler.php diff --git a/resources/sql/autopatches/20150725.badges.mailkey.1.sql b/resources/sql/autopatches/20150725.badges.mailkey.1.sql new file mode 100644 index 0000000000..5219a759b3 --- /dev/null +++ b/resources/sql/autopatches/20150725.badges.mailkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_badges.badges_badge + ADD mailKey binary(20) NOT NULL; diff --git a/resources/sql/autopatches/20150725.badges.mailkey.2.php b/resources/sql/autopatches/20150725.badges.mailkey.2.php new file mode 100644 index 0000000000..8231492478 --- /dev/null +++ b/resources/sql/autopatches/20150725.badges.mailkey.2.php @@ -0,0 +1,18 @@ +establishConnection('w'); +$iterator = new LiskMigrationIterator($table); +foreach ($iterator as $badge) { + $id = $badge->getID(); + + echo pht('Adding mail key for badge %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 index 64bad75915..7fed06cd35 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1631,10 +1631,12 @@ phutil_register_library_map(array( 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 'PhabricatorBadgesIcon' => 'applications/badges/icon/PhabricatorBadgesIcon.php', 'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php', + 'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php', 'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php', 'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php', 'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php', 'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php', + 'PhabricatorBadgesReplyHandler' => 'applications/badges/mail/PhabricatorBadgesReplyHandler.php', 'PhabricatorBadgesSchemaSpec' => 'applications/badges/storage/PhabricatorBadgesSchemaSpec.php', 'PhabricatorBadgesSearchEngine' => 'applications/badges/query/PhabricatorBadgesSearchEngine.php', 'PhabricatorBadgesTransaction' => 'applications/badges/storage/PhabricatorBadgesTransaction.php', @@ -5402,10 +5404,12 @@ phutil_register_library_map(array( 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorBadgesIcon' => 'Phobject', 'PhabricatorBadgesListController' => 'PhabricatorBadgesController', + 'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType', 'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorBadgesRecipientsListView' => 'AphrontTagView', 'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController', + 'PhabricatorBadgesReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhabricatorBadgesSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorBadgesSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/badges/editor/PhabricatorBadgesEditor.php b/src/applications/badges/editor/PhabricatorBadgesEditor.php index d060c6df7a..539f071b49 100644 --- a/src/applications/badges/editor/PhabricatorBadgesEditor.php +++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php @@ -142,6 +142,23 @@ final class PhabricatorBadgesEditor return $errors; } + protected function shouldSendMail( + PhabricatorLiskDAO $object, + array $xactions) { + return true; + } + + public function getMailTagsMap() { + return array( + PhabricatorBadgesTransaction::MAILTAG_DETAILS => + pht('Someone changes the badge\'s details.'), + PhabricatorBadgesTransaction::MAILTAG_COMMENT => + pht('Someone comments on a badge.'), + PhabricatorBadgesTransaction::MAILTAG_OTHER => + pht('Other badge activity not listed above occurs.'), + ); + } + protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { @@ -149,7 +166,7 @@ final class PhabricatorBadgesEditor } protected function buildReplyHandler(PhabricatorLiskDAO $object) { - return id(new PhabricatorMacroReplyHandler()) + return id(new PhabricatorBadgesReplyHandler()) ->setMailReceiver($object); } diff --git a/src/applications/badges/mail/PhabricatorBadgesMailReceiver.php b/src/applications/badges/mail/PhabricatorBadgesMailReceiver.php new file mode 100644 index 0000000000..4e72c8422d --- /dev/null +++ b/src/applications/badges/mail/PhabricatorBadgesMailReceiver.php @@ -0,0 +1,28 @@ +setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + } + + protected function getTransactionReplyHandler() { + return new PhabricatorBadgesReplyHandler(); + } + +} diff --git a/src/applications/badges/mail/PhabricatorBadgesReplyHandler.php b/src/applications/badges/mail/PhabricatorBadgesReplyHandler.php new file mode 100644 index 0000000000..af03dd7e2a --- /dev/null +++ b/src/applications/badges/mail/PhabricatorBadgesReplyHandler.php @@ -0,0 +1,16 @@ + 'text255', 'quality' => 'text255', 'status' => 'text32', + 'mailKey' => 'bytes20', ), self::CONFIG_KEY_SCHEMA => array( 'key_creator' => array( @@ -114,6 +116,13 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO return $this->assertAttached($this->recipientPHIDs); } + public function save() { + if (!$this->getMailKey()) { + $this->setMailKey(Filesystem::readRandomCharacters(20)); + } + return parent::save(); + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/badges/storage/PhabricatorBadgesTransaction.php b/src/applications/badges/storage/PhabricatorBadgesTransaction.php index e7ab4eab6a..c50297f768 100644 --- a/src/applications/badges/storage/PhabricatorBadgesTransaction.php +++ b/src/applications/badges/storage/PhabricatorBadgesTransaction.php @@ -10,6 +10,11 @@ final class PhabricatorBadgesTransaction const TYPE_STATUS = 'badges:status'; const TYPE_FLAVOR = 'badges:flavor'; + const MAILTAG_NAME = 'badges:name'; + const MAILTAG_DETAILS = 'badges:details'; + const MAILTAG_COMMENT = 'badges:comment'; + const MAILTAG_OTHER = 'badges:other'; + public function getApplicationName() { return 'badges'; } @@ -168,6 +173,28 @@ final class PhabricatorBadgesTransaction return parent::getTitleForFeed(); } + public function getMailTags() { + $tags = parent::getMailTags(); + + switch ($this->getTransactionType()) { + case PhabricatorTransactions::TYPE_COMMENT: + $tags[] = self::MAILTAG_COMMENT; + break; + case self::TYPE_NAME: + case self::TYPE_DESCRIPTION: + case self::TYPE_FLAVOR: + case self::TYPE_ICON: + case self::TYPE_STATUS: + case self::TYPE_QUALITY: + $tags[] = self::MAILTAG_DETAILS; + break; + default: + $tags[] = self::MAILTAG_OTHER; + break; + } + return $tags; + } + public function shouldHide() { $old = $this->getOldValue();