mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-05 12:21:02 +01:00
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
This commit is contained in:
parent
6337fa99a3
commit
82edde8876
8 changed files with 122 additions and 1 deletions
2
resources/sql/autopatches/20150725.badges.mailkey.1.sql
Normal file
2
resources/sql/autopatches/20150725.badges.mailkey.1.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_badges.badges_badge
|
||||||
|
ADD mailKey binary(20) NOT NULL;
|
18
resources/sql/autopatches/20150725.badges.mailkey.2.php
Normal file
18
resources/sql/autopatches/20150725.badges.mailkey.2.php
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -1631,10 +1631,12 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php',
|
'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php',
|
||||||
'PhabricatorBadgesIcon' => 'applications/badges/icon/PhabricatorBadgesIcon.php',
|
'PhabricatorBadgesIcon' => 'applications/badges/icon/PhabricatorBadgesIcon.php',
|
||||||
'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php',
|
'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php',
|
||||||
|
'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php',
|
||||||
'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php',
|
'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php',
|
||||||
'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php',
|
'PhabricatorBadgesQuery' => 'applications/badges/query/PhabricatorBadgesQuery.php',
|
||||||
'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php',
|
'PhabricatorBadgesRecipientsListView' => 'applications/badges/view/PhabricatorBadgesRecipientsListView.php',
|
||||||
'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php',
|
'PhabricatorBadgesRemoveRecipientsController' => 'applications/badges/controller/PhabricatorBadgesRemoveRecipientsController.php',
|
||||||
|
'PhabricatorBadgesReplyHandler' => 'applications/badges/mail/PhabricatorBadgesReplyHandler.php',
|
||||||
'PhabricatorBadgesSchemaSpec' => 'applications/badges/storage/PhabricatorBadgesSchemaSpec.php',
|
'PhabricatorBadgesSchemaSpec' => 'applications/badges/storage/PhabricatorBadgesSchemaSpec.php',
|
||||||
'PhabricatorBadgesSearchEngine' => 'applications/badges/query/PhabricatorBadgesSearchEngine.php',
|
'PhabricatorBadgesSearchEngine' => 'applications/badges/query/PhabricatorBadgesSearchEngine.php',
|
||||||
'PhabricatorBadgesTransaction' => 'applications/badges/storage/PhabricatorBadgesTransaction.php',
|
'PhabricatorBadgesTransaction' => 'applications/badges/storage/PhabricatorBadgesTransaction.php',
|
||||||
|
@ -5402,10 +5404,12 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorBadgesIcon' => 'Phobject',
|
'PhabricatorBadgesIcon' => 'Phobject',
|
||||||
'PhabricatorBadgesListController' => 'PhabricatorBadgesController',
|
'PhabricatorBadgesListController' => 'PhabricatorBadgesController',
|
||||||
|
'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||||
'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorBadgesQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorBadgesRecipientsListView' => 'AphrontTagView',
|
'PhabricatorBadgesRecipientsListView' => 'AphrontTagView',
|
||||||
'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController',
|
'PhabricatorBadgesRemoveRecipientsController' => 'PhabricatorBadgesController',
|
||||||
|
'PhabricatorBadgesReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||||
'PhabricatorBadgesSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'PhabricatorBadgesSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'PhabricatorBadgesSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorBadgesSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
|
|
|
@ -142,6 +142,23 @@ final class PhabricatorBadgesEditor
|
||||||
return $errors;
|
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(
|
protected function shouldPublishFeedStory(
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
array $xactions) {
|
array $xactions) {
|
||||||
|
@ -149,7 +166,7 @@ final class PhabricatorBadgesEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
||||||
return id(new PhabricatorMacroReplyHandler())
|
return id(new PhabricatorBadgesReplyHandler())
|
||||||
->setMailReceiver($object);
|
->setMailReceiver($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
protected $description;
|
protected $description;
|
||||||
protected $icon;
|
protected $icon;
|
||||||
protected $quality;
|
protected $quality;
|
||||||
|
protected $mailKey;
|
||||||
protected $viewPolicy;
|
protected $viewPolicy;
|
||||||
protected $editPolicy;
|
protected $editPolicy;
|
||||||
protected $status;
|
protected $status;
|
||||||
|
@ -87,6 +88,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
'icon' => 'text255',
|
'icon' => 'text255',
|
||||||
'quality' => 'text255',
|
'quality' => 'text255',
|
||||||
'status' => 'text32',
|
'status' => 'text32',
|
||||||
|
'mailKey' => 'bytes20',
|
||||||
),
|
),
|
||||||
self::CONFIG_KEY_SCHEMA => array(
|
self::CONFIG_KEY_SCHEMA => array(
|
||||||
'key_creator' => array(
|
'key_creator' => array(
|
||||||
|
@ -114,6 +116,13 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
||||||
return $this->assertAttached($this->recipientPHIDs);
|
return $this->assertAttached($this->recipientPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
if (!$this->getMailKey()) {
|
||||||
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
||||||
|
}
|
||||||
|
return parent::save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ final class PhabricatorBadgesTransaction
|
||||||
const TYPE_STATUS = 'badges:status';
|
const TYPE_STATUS = 'badges:status';
|
||||||
const TYPE_FLAVOR = 'badges:flavor';
|
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() {
|
public function getApplicationName() {
|
||||||
return 'badges';
|
return 'badges';
|
||||||
}
|
}
|
||||||
|
@ -168,6 +173,28 @@ final class PhabricatorBadgesTransaction
|
||||||
return parent::getTitleForFeed();
|
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() {
|
public function shouldHide() {
|
||||||
$old = $this->getOldValue();
|
$old = $this->getOldValue();
|
||||||
|
|
Loading…
Reference in a new issue