mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +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:
parent
e48c36697a
commit
dda3ff89e0
8 changed files with 61 additions and 72 deletions
|
@ -2111,6 +2111,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationEditHTTPParameterHelpView' => 'applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php',
|
||||
'PhabricatorApplicationEditor' => 'applications/meta/editor/PhabricatorApplicationEditor.php',
|
||||
'PhabricatorApplicationEmailCommandsController' => 'applications/meta/controller/PhabricatorApplicationEmailCommandsController.php',
|
||||
'PhabricatorApplicationMailReceiver' => 'applications/metamta/receiver/PhabricatorApplicationMailReceiver.php',
|
||||
'PhabricatorApplicationObjectMailEngineExtension' => 'applications/transactions/engineextension/PhabricatorApplicationObjectMailEngineExtension.php',
|
||||
'PhabricatorApplicationPanelController' => 'applications/meta/controller/PhabricatorApplicationPanelController.php',
|
||||
'PhabricatorApplicationPolicyChangeTransaction' => 'applications/meta/xactions/PhabricatorApplicationPolicyChangeTransaction.php',
|
||||
|
@ -5852,7 +5853,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialCreateCommentConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialCreateDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialCreateInlineConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'DifferentialCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
|
||||
'DifferentialCreateRawDiffConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialCreateRevisionConduitAPIMethod' => 'DifferentialConduitAPIMethod',
|
||||
'DifferentialCustomField' => 'PhabricatorCustomField',
|
||||
|
@ -6704,7 +6705,7 @@ phutil_register_library_map(array(
|
|||
'FeedStoryNotificationGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'FileAllocateConduitAPIMethod' => 'FileConduitAPIMethod',
|
||||
'FileConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'FileCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'FileCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
|
||||
'FileDeletionWorker' => 'PhabricatorWorker',
|
||||
'FileDownloadConduitAPIMethod' => 'FileConduitAPIMethod',
|
||||
'FileInfoConduitAPIMethod' => 'FileConduitAPIMethod',
|
||||
|
@ -7232,7 +7233,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'ManiphestConstants' => 'Phobject',
|
||||
'ManiphestController' => 'PhabricatorController',
|
||||
'ManiphestCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'ManiphestCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
|
||||
'ManiphestCreateTaskConduitAPIMethod' => 'ManiphestConduitAPIMethod',
|
||||
'ManiphestCustomField' => 'PhabricatorCustomField',
|
||||
'ManiphestCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
|
||||
|
@ -7679,7 +7680,7 @@ phutil_register_library_map(array(
|
|||
'PassphraseTokenCredentialType' => 'PassphraseCredentialType',
|
||||
'PasteConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'PasteCreateConduitAPIMethod' => 'PasteConduitAPIMethod',
|
||||
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'PasteCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
|
||||
'PasteDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
||||
'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
||||
'PasteEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
|
@ -7740,6 +7741,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationEditHTTPParameterHelpView' => 'AphrontView',
|
||||
'PhabricatorApplicationEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorApplicationEmailCommandsController' => 'PhabricatorApplicationsController',
|
||||
'PhabricatorApplicationMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'PhabricatorApplicationObjectMailEngineExtension' => 'PhabricatorMailEngineExtension',
|
||||
'PhabricatorApplicationPanelController' => 'PhabricatorApplicationsController',
|
||||
'PhabricatorApplicationPolicyChangeTransaction' => 'PhabricatorApplicationTransactionType',
|
||||
|
@ -11364,7 +11366,7 @@ phutil_register_library_map(array(
|
|||
'PonderQuestionAnswerWikiTransaction' => 'PonderQuestionTransactionType',
|
||||
'PonderQuestionCommentController' => 'PonderController',
|
||||
'PonderQuestionContentTransaction' => 'PonderQuestionTransactionType',
|
||||
'PonderQuestionCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||
'PonderQuestionCreateMailReceiver' => 'PhabricatorApplicationMailReceiver',
|
||||
'PonderQuestionEditController' => 'PonderController',
|
||||
'PonderQuestionEditEngine' => 'PhabricatorEditEngine',
|
||||
'PonderQuestionEditor' => 'PonderEditor',
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialCreateMailReceiver extends PhabricatorMailReceiver {
|
||||
final class DifferentialCreateMailReceiver
|
||||
extends PhabricatorApplicationMailReceiver {
|
||||
|
||||
public function isEnabled() {
|
||||
return PhabricatorApplication::isClassInstalled(
|
||||
'PhabricatorDifferentialApplication');
|
||||
}
|
||||
|
||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$differential_app = new PhabricatorDifferentialApplication();
|
||||
return $this->canAcceptApplicationMail($differential_app, $mail);
|
||||
protected function newApplication() {
|
||||
return new PhabricatorDifferentialApplication();
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class FileCreateMailReceiver extends PhabricatorMailReceiver {
|
||||
final class FileCreateMailReceiver
|
||||
extends PhabricatorApplicationMailReceiver {
|
||||
|
||||
public function isEnabled() {
|
||||
$app_class = 'PhabricatorFilesApplication';
|
||||
return PhabricatorApplication::isClassInstalled($app_class);
|
||||
}
|
||||
|
||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$files_app = new PhabricatorFilesApplication();
|
||||
return $this->canAcceptApplicationMail($files_app, $mail);
|
||||
protected function newApplication() {
|
||||
return new PhabricatorFilesApplication();
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
|
||||
final class ManiphestCreateMailReceiver
|
||||
extends PhabricatorApplicationMailReceiver {
|
||||
|
||||
public function isEnabled() {
|
||||
return PhabricatorApplication::isClassInstalled(
|
||||
'PhabricatorManiphestApplication');
|
||||
}
|
||||
|
||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$maniphest_app = new PhabricatorManiphestApplication();
|
||||
return $this->canAcceptApplicationMail($maniphest_app, $mail);
|
||||
protected function newApplication() {
|
||||
return new PhabricatorManiphestApplication();
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,28 +16,6 @@ abstract class PhabricatorMailReceiver extends Phobject {
|
|||
|
||||
abstract public function isEnabled();
|
||||
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(
|
||||
PhabricatorMetaMTAReceivedMail $mail,
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class PasteCreateMailReceiver extends PhabricatorMailReceiver {
|
||||
final class PasteCreateMailReceiver
|
||||
extends PhabricatorApplicationMailReceiver {
|
||||
|
||||
public function isEnabled() {
|
||||
$app_class = 'PhabricatorPasteApplication';
|
||||
return PhabricatorApplication::isClassInstalled($app_class);
|
||||
}
|
||||
|
||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$paste_app = new PhabricatorPasteApplication();
|
||||
return $this->canAcceptApplicationMail($paste_app, $mail);
|
||||
protected function newApplication() {
|
||||
return new PhabricatorPasteApplication();
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class PonderQuestionCreateMailReceiver extends PhabricatorMailReceiver {
|
||||
final class PonderQuestionCreateMailReceiver
|
||||
extends PhabricatorApplicationMailReceiver {
|
||||
|
||||
public function isEnabled() {
|
||||
$app_class = 'PhabricatorPonderApplication';
|
||||
return PhabricatorApplication::isClassInstalled($app_class);
|
||||
}
|
||||
|
||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||
$ponder_app = new PhabricatorPonderApplication();
|
||||
return $this->canAcceptApplicationMail($ponder_app, $mail);
|
||||
protected function newApplication() {
|
||||
return new PhabricatorPonderApplication();
|
||||
}
|
||||
|
||||
protected function processReceivedMail(
|
||||
|
|
Loading…
Reference in a new issue