mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Implement a "!subscribe" mail command
Summary: Ref T7199. Implements "!subscribe". Test Plan: Used `bin/mail receive-test` to apply the command to objects. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7199 Differential Revision: https://secure.phabricator.com/D12247
This commit is contained in:
parent
cb6349b88c
commit
be1fbba698
2 changed files with 76 additions and 0 deletions
|
@ -2550,6 +2550,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
|
'PhabricatorSubscriptionsEditController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php',
|
||||||
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
|
'PhabricatorSubscriptionsEditor' => 'applications/subscriptions/editor/PhabricatorSubscriptionsEditor.php',
|
||||||
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
|
'PhabricatorSubscriptionsListController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsListController.php',
|
||||||
|
'PhabricatorSubscriptionsSubscribeEmailCommand' => 'applications/subscriptions/command/PhabricatorSubscriptionsSubscribeEmailCommand.php',
|
||||||
'PhabricatorSubscriptionsTransactionController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php',
|
'PhabricatorSubscriptionsTransactionController' => 'applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php',
|
||||||
'PhabricatorSubscriptionsUIEventListener' => 'applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php',
|
'PhabricatorSubscriptionsUIEventListener' => 'applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php',
|
||||||
'PhabricatorSubscriptionsUnsubscribeEmailCommand' => 'applications/subscriptions/command/PhabricatorSubscriptionsUnsubscribeEmailCommand.php',
|
'PhabricatorSubscriptionsUnsubscribeEmailCommand' => 'applications/subscriptions/command/PhabricatorSubscriptionsUnsubscribeEmailCommand.php',
|
||||||
|
@ -5937,6 +5938,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
|
'PhabricatorSubscriptionsEditController' => 'PhabricatorController',
|
||||||
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
|
'PhabricatorSubscriptionsEditor' => 'PhabricatorEditor',
|
||||||
'PhabricatorSubscriptionsListController' => 'PhabricatorController',
|
'PhabricatorSubscriptionsListController' => 'PhabricatorController',
|
||||||
|
'PhabricatorSubscriptionsSubscribeEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
||||||
'PhabricatorSubscriptionsTransactionController' => 'PhabricatorController',
|
'PhabricatorSubscriptionsTransactionController' => 'PhabricatorController',
|
||||||
'PhabricatorSubscriptionsUIEventListener' => 'PhabricatorEventListener',
|
'PhabricatorSubscriptionsUIEventListener' => 'PhabricatorEventListener',
|
||||||
'PhabricatorSubscriptionsUnsubscribeEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
'PhabricatorSubscriptionsUnsubscribeEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorSubscriptionsSubscribeEmailCommand
|
||||||
|
extends MetaMTAEmailTransactionCommand {
|
||||||
|
|
||||||
|
public function getCommand() {
|
||||||
|
return 'subscribe';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandSyntax() {
|
||||||
|
return '**!subscribe** //username #project ...//';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandSummary() {
|
||||||
|
return pht('Add users or projects as subscribers.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandDescription() {
|
||||||
|
return pht(
|
||||||
|
'Add one or more subscribers to the object. You can add users '.
|
||||||
|
'by providing their usernames, or add projects by adding their '.
|
||||||
|
'hashtags. For example, use `!subscribe alincoln #ios` to add the '.
|
||||||
|
'user `alincoln` and the project with hashtag `#ios` as subscribers.'.
|
||||||
|
"\n\n".
|
||||||
|
'Subscribers which are invalid or unrecognized will be ignored. This '.
|
||||||
|
'command has no effect if you do not specify any subscribers.'.
|
||||||
|
"\n\n".
|
||||||
|
'Users who are CC\'d on the email itself are also automatically '.
|
||||||
|
'subscribed if Phabricator knows which accounts are linked to their '.
|
||||||
|
'email addresses.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandAliases() {
|
||||||
|
return array(
|
||||||
|
'cc',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isCommandSupportedForObject(
|
||||||
|
PhabricatorApplicationTransactionInterface $object) {
|
||||||
|
return ($object instanceof PhabricatorSubscribableInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildTransactions(
|
||||||
|
PhabricatorUser $viewer,
|
||||||
|
PhabricatorApplicationTransactionInterface $object,
|
||||||
|
PhabricatorMetaMTAReceivedMail $mail,
|
||||||
|
$command,
|
||||||
|
array $argv) {
|
||||||
|
|
||||||
|
$subscriber_phids = id(new PhabricatorObjectListQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setAllowedTypes(
|
||||||
|
array(
|
||||||
|
PhabricatorPeopleUserPHIDType::TYPECONST,
|
||||||
|
PhabricatorProjectProjectPHIDType::TYPECONST,
|
||||||
|
))
|
||||||
|
->setObjectList(implode(' ', $argv))
|
||||||
|
->setAllowPartialResults(true)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
|
||||||
|
$xactions[] = $object->getApplicationTransactionTemplate()
|
||||||
|
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||||
|
->setNewValue(
|
||||||
|
array(
|
||||||
|
'+' => array_fuse($subscriber_phids),
|
||||||
|
));
|
||||||
|
|
||||||
|
return $xactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue