1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-12 18:02:40 +01:00

Consolidate some application email receiver code in preparation for API changes

Summary:
Ref T7477. The various "create a new X via email" applications (Paste, Differential, Maniphest, etc) all have a bunch of duplicate code.

The inheritance stack here is generally a little weird. Extend these from a shared parent to reduce the number of callsites I need to change when this API is adjusted for T7477.

Test Plan: Ran unit tests. This will get more thorough testing once more pieces are in place.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T7477

Differential Revision: https://secure.phabricator.com/D19950
This commit is contained in:
epriestley 2019-01-03 09:53:40 -08:00
parent e48c36697a
commit dda3ff89e0
8 changed files with 61 additions and 72 deletions

View file

@ -2111,6 +2111,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationEditHTTPParameterHelpView' => 'applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php', 'PhabricatorApplicationEditHTTPParameterHelpView' => 'applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php',
'PhabricatorApplicationEditor' => 'applications/meta/editor/PhabricatorApplicationEditor.php', 'PhabricatorApplicationEditor' => 'applications/meta/editor/PhabricatorApplicationEditor.php',
'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php', 'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php',
'PhabricatorApplicationMailReceiver' => 'applications/metamta/receiver/PhabricatorApplicationMailReceiver.php',
'PhabricatorApplicationObjectMailEngineExtension' => 'applications/transactions/engineextension/PhabricatorApplicationObjectMailEngineExtension.php', 'PhabricatorApplicationObjectMailEngineExtension' => 'applications/transactions/engineextension/PhabricatorApplicationObjectMailEngineExtension.php',
'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php', 'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php',
'PhabricatorApplicationPolicyChangeTransaction' => 'applications/meta/xactions/PhabricatorApplicationPolicyChangeTransaction.php', 'PhabricatorApplicationPolicyChangeTransaction' => 'applications/meta/xactions/PhabricatorApplicationPolicyChangeTransaction.php',
@ -5852,7 +5853,7 @@ phutil_register_library_map(array(
'DifferentialCreateCommentConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialCreateCommentConduitAPIMethod' => 'DifferentialConduitAPIMethod',
'DifferentialCreateDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialCreateDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod',
'DifferentialCreateInlineConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialCreateInlineConduitAPIMethod' => 'DifferentialConduitAPIMethod',
'DifferentialCreateMailReceiver' => 'PhabricatorMailReceiver', 'DifferentialCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
'DifferentialCreateRawDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialCreateRawDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod',
'DifferentialCreateRevisionConduitAPIMethod' => 'DifferentialConduitAPIMethod', 'DifferentialCreateRevisionConduitAPIMethod' => 'DifferentialConduitAPIMethod',
'DifferentialCustomField' => 'PhabricatorCustomField', 'DifferentialCustomField' => 'PhabricatorCustomField',
@ -6704,7 +6705,7 @@ phutil_register_library_map(array(
'FeedStoryNotificationGarbageCollector' => 'PhabricatorGarbageCollector', 'FeedStoryNotificationGarbageCollector' => 'PhabricatorGarbageCollector',
'FileAllocateConduitAPIMethod' => 'FileConduitAPIMethod', 'FileAllocateConduitAPIMethod' => 'FileConduitAPIMethod',
'FileConduitAPIMethod' => 'ConduitAPIMethod', 'FileConduitAPIMethod' => 'ConduitAPIMethod',
'FileCreateMailReceiver' => 'PhabricatorMailReceiver', 'FileCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
'FileDeletionWorker' => 'PhabricatorWorker', 'FileDeletionWorker' => 'PhabricatorWorker',
'FileDownloadConduitAPIMethod' => 'FileConduitAPIMethod', 'FileDownloadConduitAPIMethod' => 'FileConduitAPIMethod',
'FileInfoConduitAPIMethod' => 'FileConduitAPIMethod', 'FileInfoConduitAPIMethod' => 'FileConduitAPIMethod',
@ -7232,7 +7233,7 @@ phutil_register_library_map(array(
), ),
'ManiphestConstants' => 'Phobject', 'ManiphestConstants' => 'Phobject',
'ManiphestController' => 'PhabricatorController', 'ManiphestController' => 'PhabricatorController',
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver', 'ManiphestCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
'ManiphestCreateTaskConduitAPIMethod' => 'ManiphestConduitAPIMethod', 'ManiphestCreateTaskConduitAPIMethod' => 'ManiphestConduitAPIMethod',
'ManiphestCustomField' => 'PhabricatorCustomField', 'ManiphestCustomField' => 'PhabricatorCustomField',
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
@ -7679,7 +7680,7 @@ phutil_register_library_map(array(
'PassphraseTokenCredentialType' => 'PassphraseCredentialType', 'PassphraseTokenCredentialType' => 'PassphraseCredentialType',
'PasteConduitAPIMethod' => 'ConduitAPIMethod', 'PasteConduitAPIMethod' => 'ConduitAPIMethod',
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod', 'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver', 'PasteCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
'PasteDefaultEditCapability' => 'PhabricatorPolicyCapability', 'PasteDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability', 'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
@ -7740,6 +7741,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationEditHTTPParameterHelpView' => 'AphrontView', 'PhabricatorApplicationEditHTTPParameterHelpView' => 'AphrontView',
'PhabricatorApplicationEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorApplicationEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController',
'PhabricatorApplicationMailReceiver' => 'PhabricatorMailReceiver',
'PhabricatorApplicationObjectMailEngineExtension' => 'PhabricatorMailEngineExtension', 'PhabricatorApplicationObjectMailEngineExtension' => 'PhabricatorMailEngineExtension',
'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController',
'PhabricatorApplicationPolicyChangeTransaction' => 'PhabricatorApplicationTransactionType', 'PhabricatorApplicationPolicyChangeTransaction' => 'PhabricatorApplicationTransactionType',
@ -11364,7 +11366,7 @@ phutil_register_library_map(array(
'PonderQuestionAnswerWikiTransaction' => 'PonderQuestionTransactionType', 'PonderQuestionAnswerWikiTransaction' => 'PonderQuestionTransactionType',
'PonderQuestionCommentController' => 'PonderController', 'PonderQuestionCommentController' => 'PonderController',
'PonderQuestionContentTransaction' => 'PonderQuestionTransactionType', 'PonderQuestionContentTransaction' => 'PonderQuestionTransactionType',
'PonderQuestionCreateMailReceiver' => 'PhabricatorMailReceiver', 'PonderQuestionCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
'PonderQuestionEditController' => 'PonderController', 'PonderQuestionEditController' => 'PonderController',
'PonderQuestionEditEngine' => 'PhabricatorEditEngine', 'PonderQuestionEditEngine' => 'PhabricatorEditEngine',
'PonderQuestionEditor' => 'PonderEditor', 'PonderQuestionEditor' => 'PonderEditor',

View file

@ -1,15 +1,10 @@
<?php <?php
final class DifferentialCreateMailReceiver extends PhabricatorMailReceiver { final class DifferentialCreateMailReceiver
extends PhabricatorApplicationMailReceiver {
public function isEnabled() { protected function newApplication() {
return PhabricatorApplication::isClassInstalled( return new PhabricatorDifferentialApplication();
'PhabricatorDifferentialApplication');
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$differential_app = new PhabricatorDifferentialApplication();
return $this->canAcceptApplicationMail($differential_app, $mail);
} }
protected function processReceivedMail( protected function processReceivedMail(

View file

@ -1,15 +1,10 @@
<?php <?php
final class FileCreateMailReceiver extends PhabricatorMailReceiver { final class FileCreateMailReceiver
extends PhabricatorApplicationMailReceiver {
public function isEnabled() { protected function newApplication() {
$app_class = 'PhabricatorFilesApplication'; return new PhabricatorFilesApplication();
return PhabricatorApplication::isClassInstalled($app_class);
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$files_app = new PhabricatorFilesApplication();
return $this->canAcceptApplicationMail($files_app, $mail);
} }
protected function processReceivedMail( protected function processReceivedMail(

View file

@ -1,15 +1,10 @@
<?php <?php
final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver { final class ManiphestCreateMailReceiver
extends PhabricatorApplicationMailReceiver {
public function isEnabled() { protected function newApplication() {
return PhabricatorApplication::isClassInstalled( return new PhabricatorManiphestApplication();
'PhabricatorManiphestApplication');
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$maniphest_app = new PhabricatorManiphestApplication();
return $this->canAcceptApplicationMail($maniphest_app, $mail);
} }
protected function processReceivedMail( protected function processReceivedMail(

View file

@ -0,0 +1,34 @@
<?php
abstract class PhabricatorApplicationMailReceiver
extends PhabricatorMailReceiver {
abstract protected function newApplication();
final public function isEnabled() {
return $this->newApplication()->isInstalled();
}
final public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$application = $this->newApplication();
$viewer = $this->getViewer();
$application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer($viewer)
->withApplicationPHIDs(array($application->getPHID()))
->execute();
foreach ($mail->newTargetAddresses() as $address) {
foreach ($application_emails as $application_email) {
$create_address = $application_email->newAddress();
if (PhabricatorMailUtil::matchAddresses($create_address, $address)) {
$this->setApplicationEmail($application_email);
return true;
}
}
}
return false;
}
}

View file

@ -16,28 +16,6 @@ abstract class PhabricatorMailReceiver extends Phobject {
abstract public function isEnabled(); abstract public function isEnabled();
abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail); abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail);
final protected function canAcceptApplicationMail(
PhabricatorApplication $app,
PhabricatorMetaMTAReceivedMail $mail) {
$application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery())
->setViewer($this->getViewer())
->withApplicationPHIDs(array($app->getPHID()))
->execute();
foreach ($mail->newTargetAddresses() as $address) {
foreach ($application_emails as $application_email) {
$create_address = $application_email->newAddress();
if (PhabricatorMailUtil::matchAddresses($create_address, $address)) {
$this->setApplicationEmail($application_email);
return true;
}
}
}
return false;
}
abstract protected function processReceivedMail( abstract protected function processReceivedMail(
PhabricatorMetaMTAReceivedMail $mail, PhabricatorMetaMTAReceivedMail $mail,

View file

@ -1,15 +1,10 @@
<?php <?php
final class PasteCreateMailReceiver extends PhabricatorMailReceiver { final class PasteCreateMailReceiver
extends PhabricatorApplicationMailReceiver {
public function isEnabled() { protected function newApplication() {
$app_class = 'PhabricatorPasteApplication'; return new PhabricatorPasteApplication();
return PhabricatorApplication::isClassInstalled($app_class);
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$paste_app = new PhabricatorPasteApplication();
return $this->canAcceptApplicationMail($paste_app, $mail);
} }
protected function processReceivedMail( protected function processReceivedMail(

View file

@ -1,15 +1,10 @@
<?php <?php
final class PonderQuestionCreateMailReceiver extends PhabricatorMailReceiver { final class PonderQuestionCreateMailReceiver
extends PhabricatorApplicationMailReceiver {
public function isEnabled() { protected function newApplication() {
$app_class = 'PhabricatorPonderApplication'; return new PhabricatorPonderApplication();
return PhabricatorApplication::isClassInstalled($app_class);
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$ponder_app = new PhabricatorPonderApplication();
return $this->canAcceptApplicationMail($ponder_app, $mail);
} }
protected function processReceivedMail( protected function processReceivedMail(