Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15458248
D13712.id33138.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D13712.id33138.diff
View Options
diff --git a/resources/sql/autopatches/20150725.badges.mailkey.1.sql b/resources/sql/autopatches/20150725.badges.mailkey.1.sql
new file mode 100644
--- /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
--- /dev/null
+++ b/resources/sql/autopatches/20150725.badges.mailkey.2.php
@@ -0,0 +1,18 @@
+<?php
+
+$table = new PhabricatorBadgesBadge();
+$conn_w = $table->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
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1631,10 +1631,12 @@
'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 @@
'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
--- a/src/applications/badges/editor/PhabricatorBadgesEditor.php
+++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php
@@ -142,6 +142,23 @@
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 @@
}
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
--- /dev/null
+++ b/src/applications/badges/mail/PhabricatorBadgesMailReceiver.php
@@ -0,0 +1,28 @@
+<?php
+
+final class PhabricatorBadgesMailReceiver
+ extends PhabricatorObjectMailReceiver {
+
+ public function isEnabled() {
+ return PhabricatorApplication::isClassInstalled(
+ 'PhabricatorBadgesApplication');
+ }
+
+ protected function getObjectPattern() {
+ return 'BDGE[1-9]\d*';
+ }
+
+ protected function loadObject($pattern, PhabricatorUser $viewer) {
+ $id = (int)substr($pattern, 4);
+
+ return id(new PhabricatorBadgesQuery())
+ ->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
--- /dev/null
+++ b/src/applications/badges/mail/PhabricatorBadgesReplyHandler.php
@@ -0,0 +1,16 @@
+<?php
+
+final class PhabricatorBadgesReplyHandler
+ extends PhabricatorApplicationTransactionReplyHandler {
+
+ public function validateMailReceiver($mail_receiver) {
+ if (!($mail_receiver instanceof PhabricatorBadgesBadge)) {
+ throw new Exception(pht('Mail receiver is not a %s!', 'Badges'));
+ }
+ }
+
+ public function getObjectPrefix() {
+ return 'BDGE';
+ }
+
+}
diff --git a/src/applications/badges/storage/PhabricatorBadgesBadge.php b/src/applications/badges/storage/PhabricatorBadgesBadge.php
--- a/src/applications/badges/storage/PhabricatorBadgesBadge.php
+++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php
@@ -13,6 +13,7 @@
protected $description;
protected $icon;
protected $quality;
+ protected $mailKey;
protected $viewPolicy;
protected $editPolicy;
protected $status;
@@ -87,6 +88,7 @@
'icon' => 'text255',
'quality' => 'text255',
'status' => 'text32',
+ 'mailKey' => 'bytes20',
),
self::CONFIG_KEY_SCHEMA => array(
'key_creator' => array(
@@ -114,6 +116,13 @@
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
--- a/src/applications/badges/storage/PhabricatorBadgesTransaction.php
+++ b/src/applications/badges/storage/PhabricatorBadgesTransaction.php
@@ -10,6 +10,11 @@
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 @@
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();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 31, 10:09 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7695865
Default Alt Text
D13712.id33138.diff (8 KB)
Attached To
Mode
D13712: Add MAILTAGs to Badges
Attached
Detach File
Event Timeline
Log In to Comment