mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add a "test message" action for contact numbers
Summary: Depends on D20024. See D20022. Put something in place temporarily until we build out validation at some point. Test Plan: Sent myself a test message. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20025
This commit is contained in:
parent
587e9cea19
commit
ab2cbbd9f9
6 changed files with 103 additions and 0 deletions
|
@ -2212,6 +2212,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthContactNumberPrimaryTransaction' => 'PhabricatorAuthContactNumberTransactionType',
|
||||
'PhabricatorAuthContactNumberQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorAuthContactNumberStatusTransaction' => 'PhabricatorAuthContactNumberTransactionType',
|
||||
'PhabricatorAuthContactNumberTestController' => 'PhabricatorAuthContactNumberController',
|
||||
'PhabricatorAuthContactNumberTransaction' => 'PhabricatorModularTransaction',
|
||||
'PhabricatorAuthContactNumberTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorAuthContactNumberTransactionType' => 'PhabricatorModularTransactionType',
|
||||
|
@ -8116,6 +8119,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthTemporaryTokenType' => 'Phobject',
|
||||
'PhabricatorAuthTemporaryTokenTypeModule' => 'PhabricatorConfigModule',
|
||||
'PhabricatorAuthTerminateSessionController' => 'PhabricatorAuthController',
|
||||
'PhabricatorAuthTestSMSAction' => 'PhabricatorSystemAction',
|
||||
'PhabricatorAuthTryFactorAction' => 'PhabricatorSystemAction',
|
||||
'PhabricatorAuthUnlinkController' => 'PhabricatorAuthController',
|
||||
'PhabricatorAuthValidateController' => 'PhabricatorAuthController',
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorAuthTestSMSAction extends PhabricatorSystemAction {
|
||||
|
||||
const TYPECONST = 'auth.sms.test';
|
||||
|
||||
public function getActionConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getScoreThreshold() {
|
||||
return 60 / phutil_units('1 hour in seconds');
|
||||
}
|
||||
|
||||
public function getLimitExplanation() {
|
||||
return pht(
|
||||
'You and other users on this install are collectively sending too '.
|
||||
'many test text messages too quickly. Wait a few minutes to continue '.
|
||||
'texting tests.');
|
||||
}
|
||||
|
||||
}
|
|
@ -115,6 +115,8 @@ final class PhabricatorAuthApplication extends PhabricatorApplication {
|
|||
'PhabricatorAuthContactNumberDisableController',
|
||||
'primary/(?P<id>[1-9]\d*)/' =>
|
||||
'PhabricatorAuthContactNumberPrimaryController',
|
||||
'test/(?P<id>[1-9]\d*)/' =>
|
||||
'PhabricatorAuthContactNumberTestController',
|
||||
),
|
||||
),
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorAuthContactNumberTestController
|
||||
extends PhabricatorAuthContactNumberController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->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()))
|
||||
->setSensitiveContent(false)
|
||||
->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);
|
||||
}
|
||||
|
||||
}
|
|
@ -98,6 +98,14 @@ final class PhabricatorAuthContactNumberViewController
|
|||
->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');
|
||||
|
|
|
@ -187,6 +187,9 @@ final class PhabricatorMetaMTAMailViewController
|
|||
->setStacked(true);
|
||||
|
||||
$headers = $mail->getDeliveredHeaders();
|
||||
if (!$headers) {
|
||||
$headers = array();
|
||||
}
|
||||
|
||||
// Sort headers by name.
|
||||
$headers = isort($headers, 0);
|
||||
|
|
Loading…
Reference in a new issue