mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Move Differential to modular mail commands
Summary: Ref T7199. Convert Differential to modern modular commands. Test Plan: Used `bin/mail receive-test` to send command and comment mail to Differential. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7199 Differential Revision: https://secure.phabricator.com/D12239
This commit is contained in:
parent
c32fee0e48
commit
d4bfaa2feb
3 changed files with 99 additions and 96 deletions
|
@ -287,6 +287,7 @@ phutil_register_library_map(array(
|
|||
'DatabaseConfigurationProvider' => 'infrastructure/storage/configuration/DatabaseConfigurationProvider.php',
|
||||
'DefaultDatabaseConfigurationProvider' => 'infrastructure/storage/configuration/DefaultDatabaseConfigurationProvider.php',
|
||||
'DifferentialAction' => 'applications/differential/constants/DifferentialAction.php',
|
||||
'DifferentialActionEmailCommand' => 'applications/differential/command/DifferentialActionEmailCommand.php',
|
||||
'DifferentialActionMenuEventListener' => 'applications/differential/event/DifferentialActionMenuEventListener.php',
|
||||
'DifferentialAddCommentView' => 'applications/differential/view/DifferentialAddCommentView.php',
|
||||
'DifferentialAffectedPath' => 'applications/differential/storage/DifferentialAffectedPath.php',
|
||||
|
@ -3459,6 +3460,7 @@ phutil_register_library_map(array(
|
|||
'DarkConsoleServicesPlugin' => 'DarkConsolePlugin',
|
||||
'DarkConsoleXHProfPlugin' => 'DarkConsolePlugin',
|
||||
'DefaultDatabaseConfigurationProvider' => 'DatabaseConfigurationProvider',
|
||||
'DifferentialActionEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
||||
'DifferentialActionMenuEventListener' => 'PhabricatorEventListener',
|
||||
'DifferentialAddCommentView' => 'AphrontView',
|
||||
'DifferentialAffectedPath' => 'DifferentialDAO',
|
||||
|
@ -3578,7 +3580,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialQueryConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialQueryDiffsConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||
'DifferentialReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'DifferentialReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'DifferentialRepositoryField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialRepositoryLookup' => 'Phobject',
|
||||
'DifferentialRequiredSignaturesField' => 'DifferentialCoreCustomField',
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialActionEmailCommand
|
||||
extends MetaMTAEmailTransactionCommand {
|
||||
|
||||
private $command;
|
||||
private $action;
|
||||
private $aliases;
|
||||
|
||||
public function getCommand() {
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
private function setCommand($command) {
|
||||
$this->command = $command;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setAction($action) {
|
||||
$this->action = $action;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function getAction() {
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
private function setCommandAliases(array $aliases) {
|
||||
$this->aliases = $aliases;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommandAliases() {
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
public function getCommandObjects() {
|
||||
$actions = array(
|
||||
DifferentialAction::ACTION_REJECT => 'request',
|
||||
DifferentialAction::ACTION_ABANDON => 'abandon',
|
||||
DifferentialAction::ACTION_RECLAIM => 'reclaim',
|
||||
DifferentialAction::ACTION_RESIGN => 'resign',
|
||||
DifferentialAction::ACTION_RETHINK => 'rethink',
|
||||
DifferentialAction::ACTION_CLAIM => 'commandeer',
|
||||
);
|
||||
|
||||
if (PhabricatorEnv::getEnvConfig('differential.enable-email-accept')) {
|
||||
$actions[DifferentialAction::ACTION_ACCEPT] = 'accept';
|
||||
}
|
||||
|
||||
$aliases = array(
|
||||
DifferentialAction::ACTION_REJECT => array('reject'),
|
||||
DifferentialAction::ACTION_CLAIM => array('claim'),
|
||||
);
|
||||
|
||||
$objects = array();
|
||||
foreach ($actions as $action => $keyword) {
|
||||
$object = id(new DifferentialActionEmailCommand())
|
||||
->setCommand($keyword)
|
||||
->setAction($action);
|
||||
|
||||
if (isset($aliases[$action])) {
|
||||
$object->setCommandAliases($aliases[$action]);
|
||||
}
|
||||
|
||||
$objects[] = $object;
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function isCommandSupportedForObject(
|
||||
PhabricatorApplicationTransactionInterface $object) {
|
||||
return ($object instanceof DifferentialRevision);
|
||||
}
|
||||
|
||||
public function buildTransactions(
|
||||
PhabricatorUser $viewer,
|
||||
PhabricatorApplicationTransactionInterface $object,
|
||||
PhabricatorMetaMTAReceivedMail $mail,
|
||||
$command,
|
||||
array $argv) {
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = $object->getApplicationTransactionTemplate()
|
||||
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
||||
->setNewValue($this->getAction());
|
||||
|
||||
return $xactions;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
|
||||
final class DifferentialReplyHandler
|
||||
extends PhabricatorApplicationTransactionReplyHandler {
|
||||
|
||||
public function validateMailReceiver($mail_receiver) {
|
||||
if (!($mail_receiver instanceof DifferentialRevision)) {
|
||||
|
@ -8,100 +9,8 @@ final class DifferentialReplyHandler extends PhabricatorMailReplyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public function getPrivateReplyHandlerEmailAddress(
|
||||
PhabricatorObjectHandle $handle) {
|
||||
return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'D');
|
||||
}
|
||||
|
||||
public function getPublicReplyHandlerEmailAddress() {
|
||||
return $this->getDefaultPublicReplyHandlerEmailAddress('D');
|
||||
}
|
||||
|
||||
public function getSupportedCommands() {
|
||||
$actions = array(
|
||||
DifferentialAction::ACTION_COMMENT,
|
||||
DifferentialAction::ACTION_REJECT,
|
||||
DifferentialAction::ACTION_ABANDON,
|
||||
DifferentialAction::ACTION_RECLAIM,
|
||||
DifferentialAction::ACTION_RESIGN,
|
||||
DifferentialAction::ACTION_RETHINK,
|
||||
'unsubscribe',
|
||||
);
|
||||
|
||||
if (PhabricatorEnv::getEnvConfig('differential.enable-email-accept')) {
|
||||
$actions[] = DifferentialAction::ACTION_ACCEPT;
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$revision = $this->getMailReceiver();
|
||||
$viewer = $this->getActor();
|
||||
|
||||
$body_data = $mail->parseBody();
|
||||
$body = $body_data['body'];
|
||||
$body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
|
||||
|
||||
$xactions = array();
|
||||
$content_source = PhabricatorContentSource::newForSource(
|
||||
PhabricatorContentSource::SOURCE_EMAIL,
|
||||
array(
|
||||
'id' => $mail->getID(),
|
||||
));
|
||||
|
||||
$template = id(new DifferentialTransaction());
|
||||
|
||||
$commands = $body_data['commands'];
|
||||
foreach ($commands as $command_argv) {
|
||||
$command = head($command_argv);
|
||||
switch ($command) {
|
||||
case 'unsubscribe':
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||
->setNewValue(
|
||||
array(
|
||||
'-' => array($viewer->getPHID()),
|
||||
));
|
||||
break;
|
||||
case DifferentialAction::ACTION_ACCEPT:
|
||||
$accept_key = 'differential.enable-email-accept';
|
||||
$can_accept = PhabricatorEnv::getEnvConfig($accept_key);
|
||||
if (!$can_accept) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'You can not !accept revisions over email because '.
|
||||
'Differential is configured to disallow this.'));
|
||||
}
|
||||
// Fall through...
|
||||
case DifferentialAction::ACTION_REJECT:
|
||||
case DifferentialAction::ACTION_ABANDON:
|
||||
case DifferentialAction::ACTION_RECLAIM:
|
||||
case DifferentialAction::ACTION_RESIGN:
|
||||
case DifferentialAction::ACTION_RETHINK:
|
||||
case DifferentialAction::ACTION_CLAIM:
|
||||
case DifferentialAction::ACTION_REOPEN:
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(DifferentialTransaction::TYPE_ACTION)
|
||||
->setNewValue($command);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new DifferentialTransactionComment())
|
||||
->setContent($body));
|
||||
|
||||
$editor = id(new DifferentialTransactionEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSource($content_source)
|
||||
->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
|
||||
->setContinueOnMissingFields(true)
|
||||
->setContinueOnNoEffect(true);
|
||||
|
||||
$editor->applyTransactions($revision, $xactions);
|
||||
public function getObjectPrefix() {
|
||||
return 'D';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue