mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Support feed and email in Fund
Summary: Ref T5835. Make fund stories publish to feed and send email. Test Plan: Made edits, etc., saw them in feed and outbound email. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5835 Differential Revision: https://secure.phabricator.com/D10677
This commit is contained in:
parent
44415c5473
commit
1112419a97
6 changed files with 138 additions and 1 deletions
2
resources/sql/autopatches/20141010.fundmailkey.sql
Normal file
2
resources/sql/autopatches/20141010.fundmailkey.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_fund.fund_initiative
|
||||
ADD mailKey BINARY(20) NOT NULL;
|
|
@ -688,6 +688,7 @@ phutil_register_library_map(array(
|
|||
'FundInitiativePHIDType' => 'applications/fund/phid/FundInitiativePHIDType.php',
|
||||
'FundInitiativeQuery' => 'applications/fund/query/FundInitiativeQuery.php',
|
||||
'FundInitiativeRemarkupRule' => 'applications/fund/remarkup/FundInitiativeRemarkupRule.php',
|
||||
'FundInitiativeReplyHandler' => 'applications/fund/mail/FundInitiativeReplyHandler.php',
|
||||
'FundInitiativeSearchEngine' => 'applications/fund/query/FundInitiativeSearchEngine.php',
|
||||
'FundInitiativeTransaction' => 'applications/fund/storage/FundInitiativeTransaction.php',
|
||||
'FundInitiativeTransactionQuery' => 'applications/fund/query/FundInitiativeTransactionQuery.php',
|
||||
|
@ -3579,6 +3580,7 @@ phutil_register_library_map(array(
|
|||
'FundInitiativePHIDType' => 'PhabricatorPHIDType',
|
||||
'FundInitiativeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'FundInitiativeRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||
'FundInitiativeReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'FundInitiativeSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'FundInitiativeTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'FundInitiativeTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
|
|
|
@ -231,5 +231,52 @@ final class FundInitiativeEditor
|
|||
return $errors;
|
||||
}
|
||||
|
||||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMailTagsMap() {
|
||||
return array(
|
||||
FundInitiativeTransaction::MAILTAG_BACKER =>
|
||||
pht('Someone backs an initiative.'),
|
||||
FundInitiativeTransaction::MAILTAG_STATUS =>
|
||||
pht("An initiative's status changes."),
|
||||
FundInitiativeTransaction::MAILTAG_OTHER =>
|
||||
pht('Other initiative activity not listed above occurs.'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
|
||||
$monogram = $object->getMonogram();
|
||||
$name = $object->getName();
|
||||
|
||||
return id(new PhabricatorMetaMTAMail())
|
||||
->setSubject("{$monogram}: {$name}")
|
||||
->addHeader('Thread-Topic', $monogram);
|
||||
}
|
||||
|
||||
|
||||
protected function getMailTo(PhabricatorLiskDAO $object) {
|
||||
return array($object->getOwnerPHID());
|
||||
}
|
||||
|
||||
protected function getMailSubjectPrefix() {
|
||||
return 'Fund';
|
||||
}
|
||||
|
||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
||||
return id(new FundInitiativeReplyHandler())
|
||||
->setMailReceiver($object);
|
||||
}
|
||||
|
||||
protected function shouldPublishFeedStory(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
38
src/applications/fund/mail/FundInitiativeReplyHandler.php
Normal file
38
src/applications/fund/mail/FundInitiativeReplyHandler.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
final class FundInitiativeReplyHandler extends PhabricatorMailReplyHandler {
|
||||
|
||||
public function validateMailReceiver($mail_receiver) {
|
||||
if (!($mail_receiver instanceof FundInitiative)) {
|
||||
throw new Exception('Mail receiver is not a FundInitiative!');
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrivateReplyHandlerEmailAddress(
|
||||
PhabricatorObjectHandle $handle) {
|
||||
return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'I');
|
||||
}
|
||||
|
||||
public function getPublicReplyHandlerEmailAddress() {
|
||||
return $this->getDefaultPublicReplyHandlerEmailAddress('I');
|
||||
}
|
||||
|
||||
public function getReplyHandlerDomain() {
|
||||
return PhabricatorEnv::getEnvConfig('metamta.reply-handler-domain');
|
||||
}
|
||||
|
||||
public function getReplyHandlerInstructions() {
|
||||
if ($this->supportsReplies()) {
|
||||
// TODO: Implement.
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
// TODO: Implement.
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ final class FundInitiative extends FundDAO
|
|||
protected $editPolicy;
|
||||
protected $status;
|
||||
protected $totalAsCurrency;
|
||||
protected $mailKey;
|
||||
|
||||
private $projectPHIDs = self::ATTACHABLE;
|
||||
|
||||
|
@ -59,6 +60,7 @@ final class FundInitiative extends FundDAO
|
|||
'status' => 'text32',
|
||||
'merchantPHID' => 'phid?',
|
||||
'totalAsCurrency' => 'text64',
|
||||
'mailKey' => 'bytes20',
|
||||
),
|
||||
self::CONFIG_APPLICATION_SERIALIZERS => array(
|
||||
'totalAsCurrency' => new PhortuneCurrencySerializer(),
|
||||
|
@ -95,6 +97,13 @@ final class FundInitiative extends FundDAO
|
|||
return ($this->getStatus() == self::STATUS_CLOSED);
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if (!$this->mailKey) {
|
||||
$this->mailKey = Filesystem::readRandomCharacters(20);
|
||||
}
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ final class FundInitiativeTransaction
|
|||
const TYPE_REFUND = 'fund:refund';
|
||||
const TYPE_MERCHANT = 'fund:merchant';
|
||||
|
||||
const MAILTAG_BACKER = 'fund.backer';
|
||||
const MAILTAG_STATUS = 'fund.status';
|
||||
const MAILTAG_OTHER = 'fund.other';
|
||||
|
||||
const PROPERTY_AMOUNT = 'fund.amount';
|
||||
const PROPERTY_BACKER = 'fund.backer';
|
||||
|
||||
|
@ -172,15 +176,50 @@ final class FundInitiativeTransaction
|
|||
}
|
||||
break;
|
||||
case FundInitiativeTransaction::TYPE_BACKER:
|
||||
$amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
|
||||
$amount = PhortuneCurrency::newFromString($amount);
|
||||
return pht(
|
||||
'%s backed %s.',
|
||||
'%s backed %s with %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid),
|
||||
$amount->formatForDisplay());
|
||||
case FundInitiativeTransaction::TYPE_REFUND:
|
||||
$amount = $this->getMetadataValue(self::PROPERTY_AMOUNT);
|
||||
$amount = PhortuneCurrency::newFromString($amount);
|
||||
|
||||
$backer_phid = $this->getMetadataValue(self::PROPERTY_BACKER);
|
||||
|
||||
return pht(
|
||||
'%s refunded %s to %s for %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$amount->formatForDisplay(),
|
||||
$this->renderHandleLink($backer_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
|
||||
return parent::getTitleForFeed($story);
|
||||
}
|
||||
|
||||
public function getMailTags() {
|
||||
$tags = parent::getMailTags();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_STATUS:
|
||||
$tags[] = self::MAILTAG_STATUS;
|
||||
break;
|
||||
case self::TYPE_BACKER:
|
||||
case self::TYPE_REFUND:
|
||||
$tags[] = self::MAILTAG_BACKER;
|
||||
break;
|
||||
default:
|
||||
$tags[] = self::MAILTAG_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
||||
|
||||
public function shouldHide() {
|
||||
$old = $this->getOldValue();
|
||||
switch ($this->getTransactionType()) {
|
||||
|
|
Loading…
Reference in a new issue