diff --git a/src/applications/auth/storage/PhabricatorAuthMessage.php b/src/applications/auth/storage/PhabricatorAuthMessage.php --- a/src/applications/auth/storage/PhabricatorAuthMessage.php +++ b/src/applications/auth/storage/PhabricatorAuthMessage.php @@ -61,14 +61,20 @@ return $this->getMessageType()->getDisplayName(); } - public static function loadMessageText( + public static function loadMessage( PhabricatorUser $viewer, $message_key) { - - $message = id(new PhabricatorAuthMessageQuery()) + return id(new PhabricatorAuthMessageQuery()) ->setViewer($viewer) ->withMessageKeys(array($message_key)) ->executeOne(); + } + + public static function loadMessageText( + PhabricatorUser $viewer, + $message_key) { + + $message = self::loadMessage($viewer, $message_key); if (!$message) { return null; diff --git a/src/applications/people/controller/PhabricatorPeopleWelcomeController.php b/src/applications/people/controller/PhabricatorPeopleWelcomeController.php --- a/src/applications/people/controller/PhabricatorPeopleWelcomeController.php +++ b/src/applications/people/controller/PhabricatorPeopleWelcomeController.php @@ -48,26 +48,38 @@ return id(new AphrontRedirectResponse())->setURI($profile_uri); } + $default_message = PhabricatorAuthMessage::loadMessage( + $admin, + PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY); + if (strlen($default_message->getMessageText())) { + $message_instructions = pht( + 'The email will identify you as the sender. You may optionally '. + 'replace the [[ %s | default custom mail body ]] with different text '. + 'by providing a message below.', + $default_message->getURI()); + } else { + $message_instructions = pht( + 'The email will identify you as the sender. You may optionally '. + 'include additional text in the mail body by specifying it below.'); + } + $form = id(new AphrontFormView()) ->setViewer($admin) - ->appendInstructions( + ->appendRemarkupInstructions( pht( 'This workflow will send this user ("%s") a copy of the "Welcome to '. 'Phabricator" email that users normally receive when their '. 'accounts are created by an administrator.', $user->getUsername())) - ->appendInstructions( + ->appendRemarkupInstructions( pht( 'The email will contain a link that the user may use to log in '. 'to their account. This link bypasses authentication requirements '. 'and allows them to log in without credentials. Sending a copy of '. 'this email can be useful if the original was lost or never sent.')) - ->appendInstructions( - pht( - 'The email will identify you as the sender. You may optionally '. - 'include additional text in the mail body by specifying it below.')) + ->appendRemarkupInstructions($message_instructions) ->appendControl( - id(new AphrontFormTextAreaControl()) + id(new PhabricatorRemarkupControl()) ->setName('message') ->setLabel(pht('Custom Message')) ->setValue($v_message)); diff --git a/src/applications/people/mail/PhabricatorPeopleMailEngine.php b/src/applications/people/mail/PhabricatorPeopleMailEngine.php --- a/src/applications/people/mail/PhabricatorPeopleMailEngine.php +++ b/src/applications/people/mail/PhabricatorPeopleMailEngine.php @@ -58,4 +58,15 @@ throw new PhabricatorPeopleMailEngineException($title, $body); } + final protected function newRemarkupText($text) { + $recipient = $this->getRecipient(); + + $engine = PhabricatorMarkupEngine::newMarkupEngine(array()) + ->setConfig('viewer', $recipient) + ->setConfig('uri.base', PhabricatorEnv::getProductionURI('/')) + ->setMode(PhutilRemarkupEngine::MODE_TEXT); + + return $engine->markupText($text); + } + } diff --git a/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php b/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php --- a/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php +++ b/src/applications/people/mail/PhabricatorPeopleWelcomeMailEngine.php @@ -49,9 +49,6 @@ $sender = $this->getSender(); $recipient = $this->getRecipient(); - $recipient_username = $recipient->getUserName(); - $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); - $base_uri = PhabricatorEnv::getProductionURI('/'); $engine = new PhabricatorAuthSessionEngine(); @@ -99,13 +96,9 @@ $message[] = pht(' %s', $base_uri); } - $custom_body = $this->getWelcomeMessage(); - if (strlen($custom_body)) { - $message[] = $custom_body; - } else { - if (!$is_serious) { - $message[] = pht("Love,\nPhabricator"); - } + $message_body = $this->newBody(); + if ($message_body !== null) { + $message[] = $message_body; } $message = implode("\n\n", $message); @@ -116,4 +109,27 @@ ->setBody($message); } + private function newBody() { + $recipient = $this->getRecipient(); + + $custom_body = $this->getWelcomeMessage(); + if (strlen($custom_body)) { + return $this->newRemarkupText($custom_body); + } + + $default_body = PhabricatorAuthMessage::loadMessageText( + $recipient, + PhabricatorAuthWelcomeMailMessageType::MESSAGEKEY); + if (strlen($default_body)) { + return $this->newRemarkupText($default_body); + } + + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + if (!$is_serious) { + return pht("Love,\nPhabricator"); + } + + return null; + } + }