diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2212,6 +2212,7 @@ 'PhabricatorAuthContactNumberPrimaryTransaction' => 'applications/auth/xaction/PhabricatorAuthContactNumberPrimaryTransaction.php', 'PhabricatorAuthContactNumberQuery' => 'applications/auth/query/PhabricatorAuthContactNumberQuery.php', 'PhabricatorAuthContactNumberStatusTransaction' => 'applications/auth/xaction/PhabricatorAuthContactNumberStatusTransaction.php', + 'PhabricatorAuthContactNumberTestController' => 'applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php', 'PhabricatorAuthContactNumberTransaction' => 'applications/auth/storage/PhabricatorAuthContactNumberTransaction.php', 'PhabricatorAuthContactNumberTransactionQuery' => 'applications/auth/query/PhabricatorAuthContactNumberTransactionQuery.php', 'PhabricatorAuthContactNumberTransactionType' => 'applications/auth/xaction/PhabricatorAuthContactNumberTransactionType.php', @@ -2368,6 +2369,7 @@ 'PhabricatorAuthTemporaryTokenType' => 'applications/auth/tokentype/PhabricatorAuthTemporaryTokenType.php', 'PhabricatorAuthTemporaryTokenTypeModule' => 'applications/auth/tokentype/PhabricatorAuthTemporaryTokenTypeModule.php', 'PhabricatorAuthTerminateSessionController' => 'applications/auth/controller/PhabricatorAuthTerminateSessionController.php', + 'PhabricatorAuthTestSMSAction' => 'applications/auth/action/PhabricatorAuthTestSMSAction.php', 'PhabricatorAuthTryFactorAction' => 'applications/auth/action/PhabricatorAuthTryFactorAction.php', 'PhabricatorAuthUnlinkController' => 'applications/auth/controller/PhabricatorAuthUnlinkController.php', 'PhabricatorAuthValidateController' => 'applications/auth/controller/PhabricatorAuthValidateController.php', @@ -7924,6 +7926,7 @@ 'PhabricatorAuthContactNumberPrimaryTransaction' => 'PhabricatorAuthContactNumberTransactionType', 'PhabricatorAuthContactNumberQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorAuthContactNumberStatusTransaction' => 'PhabricatorAuthContactNumberTransactionType', + 'PhabricatorAuthContactNumberTestController' => 'PhabricatorAuthContactNumberController', 'PhabricatorAuthContactNumberTransaction' => 'PhabricatorModularTransaction', 'PhabricatorAuthContactNumberTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorAuthContactNumberTransactionType' => 'PhabricatorModularTransactionType', @@ -8116,6 +8119,7 @@ 'PhabricatorAuthTemporaryTokenType' => 'Phobject', 'PhabricatorAuthTemporaryTokenTypeModule' => 'PhabricatorConfigModule', 'PhabricatorAuthTerminateSessionController' => 'PhabricatorAuthController', + 'PhabricatorAuthTestSMSAction' => 'PhabricatorSystemAction', 'PhabricatorAuthTryFactorAction' => 'PhabricatorSystemAction', 'PhabricatorAuthUnlinkController' => 'PhabricatorAuthController', 'PhabricatorAuthValidateController' => 'PhabricatorAuthController', diff --git a/src/applications/auth/action/PhabricatorAuthTestSMSAction.php b/src/applications/auth/action/PhabricatorAuthTestSMSAction.php new file mode 100644 --- /dev/null +++ b/src/applications/auth/action/PhabricatorAuthTestSMSAction.php @@ -0,0 +1,22 @@ +[1-9]\d*)/' => 'PhabricatorAuthContactNumberPrimaryController', + 'test/(?P[1-9]\d*)/' => + 'PhabricatorAuthContactNumberTestController', ), ), diff --git a/src/applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php b/src/applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php new file mode 100644 --- /dev/null +++ b/src/applications/auth/controller/contact/PhabricatorAuthContactNumberTestController.php @@ -0,0 +1,65 @@ +getViewer(); + $id = $request->getURIData('id'); + + $number = id(new PhabricatorAuthContactNumberQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->executeOne(); + if (!$number) { + return new Aphront404Response(); + } + + $id = $number->getID(); + $cancel_uri = $number->getURI(); + + // NOTE: This is a global limit shared by all users. + PhabricatorSystemActionEngine::willTakeAction( + array(id(new PhabricatorAuthApplication())->getPHID()), + new PhabricatorAuthTestSMSAction(), + 1); + + if ($request->isFormPost()) { + $uri = PhabricatorEnv::getURI('/'); + $uri = new PhutilURI($uri); + + $mail = id(new PhabricatorMetaMTAMail()) + ->setMessageType(PhabricatorMailSMSMessage::MESSAGETYPE) + ->addTos(array($viewer->getPHID())) + ->setForceDelivery(true) + ->setSensitiveContent(true) + ->setBody( + pht( + 'This is a terse test text message from Phabricator (%s).', + $uri->getDomain())) + ->save(); + + return id(new AphrontRedirectResponse())->setURI($mail->getURI()); + } + + $number_display = phutil_tag( + 'strong', + array(), + $number->getDisplayName()); + + return $this->newDialog() + ->setTitle(pht('Set Test Message')) + ->appendParagraph( + pht( + 'Send a test message to %s?', + $number_display)) + ->addSubmitButton(pht('Send SMS')) + ->addCancelButton($cancel_uri); + } + +} diff --git a/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php b/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php --- a/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php +++ b/src/applications/auth/controller/contact/PhabricatorAuthContactNumberViewController.php @@ -98,6 +98,14 @@ ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); + $curtain->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Send Test Message')) + ->setIcon('fa-envelope-o') + ->setHref($this->getApplicationURI("contact/test/{$id}/")) + ->setDisabled(!$can_edit) + ->setWorkflow(true)); + if ($number->isDisabled()) { $disable_uri = $this->getApplicationURI("contact/enable/{$id}/"); $disable_name = pht('Enable Contact Number'); diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php --- a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php @@ -187,6 +187,9 @@ ->setStacked(true); $headers = $mail->getDeliveredHeaders(); + if (!$headers) { + $headers = array(); + } // Sort headers by name. $headers = isort($headers, 0);