1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-28 04:00:17 +01:00

Use the customizable "Welcome Mail" message in welcome mail

Summary:
Depends on D19994. See PHI1027. If an install has customized the "Welcome Mail" message, include it in welcome mail. A special custom message from the profile screen overrides it, if provided.

(I fiddled with putting the custom message as "placeholder" text in the remarkup area as a hint, but newlines in "placeholder" text appear to have issues in Safari and Firefox. I think this is probably reasonably clear as-is.)

Make both render remarkup-into-text so things like links work properly, as it's reasonably likely that installs will want to link to things.

Test Plan:
  - With custom "Welcome Mail" text, sent mail with no custom override (got custom text) and a custom override (got overridden text).
  - Linked to some stuff, got sensible links in the mail (`bin/mail show-outbound`).

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19995
This commit is contained in:
epriestley 2019-01-17 19:05:45 -08:00
parent 22ad1ff2c5
commit 6bb31de305
4 changed files with 66 additions and 21 deletions

View file

@ -61,14 +61,20 @@ final class PhabricatorAuthMessage
return $this->getMessageType()->getDisplayName(); return $this->getMessageType()->getDisplayName();
} }
public static function loadMessage(
PhabricatorUser $viewer,
$message_key) {
return id(new PhabricatorAuthMessageQuery())
->setViewer($viewer)
->withMessageKeys(array($message_key))
->executeOne();
}
public static function loadMessageText( public static function loadMessageText(
PhabricatorUser $viewer, PhabricatorUser $viewer,
$message_key) { $message_key) {
$message = id(new PhabricatorAuthMessageQuery()) $message = self::loadMessage($viewer, $message_key);
->setViewer($viewer)
->withMessageKeys(array($message_key))
->executeOne();
if (!$message) { if (!$message) {
return null; return null;

View file

@ -48,26 +48,38 @@ final class PhabricatorPeopleWelcomeController
return id(new AphrontRedirectResponse())->setURI($profile_uri); 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()) $form = id(new AphrontFormView())
->setViewer($admin) ->setViewer($admin)
->appendInstructions( ->appendRemarkupInstructions(
pht( pht(
'This workflow will send this user ("%s") a copy of the "Welcome to '. 'This workflow will send this user ("%s") a copy of the "Welcome to '.
'Phabricator" email that users normally receive when their '. 'Phabricator" email that users normally receive when their '.
'accounts are created by an administrator.', 'accounts are created by an administrator.',
$user->getUsername())) $user->getUsername()))
->appendInstructions( ->appendRemarkupInstructions(
pht( pht(
'The email will contain a link that the user may use to log in '. 'The email will contain a link that the user may use to log in '.
'to their account. This link bypasses authentication requirements '. 'to their account. This link bypasses authentication requirements '.
'and allows them to log in without credentials. Sending a copy of '. '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.')) 'this email can be useful if the original was lost or never sent.'))
->appendInstructions( ->appendRemarkupInstructions($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.'))
->appendControl( ->appendControl(
id(new AphrontFormTextAreaControl()) id(new PhabricatorRemarkupControl())
->setName('message') ->setName('message')
->setLabel(pht('Custom Message')) ->setLabel(pht('Custom Message'))
->setValue($v_message)); ->setValue($v_message));

View file

@ -58,4 +58,15 @@ abstract class PhabricatorPeopleMailEngine
throw new PhabricatorPeopleMailEngineException($title, $body); 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);
}
} }

View file

@ -49,9 +49,6 @@ final class PhabricatorPeopleWelcomeMailEngine
$sender = $this->getSender(); $sender = $this->getSender();
$recipient = $this->getRecipient(); $recipient = $this->getRecipient();
$recipient_username = $recipient->getUserName();
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$base_uri = PhabricatorEnv::getProductionURI('/'); $base_uri = PhabricatorEnv::getProductionURI('/');
$engine = new PhabricatorAuthSessionEngine(); $engine = new PhabricatorAuthSessionEngine();
@ -99,13 +96,9 @@ final class PhabricatorPeopleWelcomeMailEngine
$message[] = pht(' %s', $base_uri); $message[] = pht(' %s', $base_uri);
} }
$custom_body = $this->getWelcomeMessage(); $message_body = $this->newBody();
if (strlen($custom_body)) { if ($message_body !== null) {
$message[] = $custom_body; $message[] = $message_body;
} else {
if (!$is_serious) {
$message[] = pht("Love,\nPhabricator");
}
} }
$message = implode("\n\n", $message); $message = implode("\n\n", $message);
@ -116,4 +109,27 @@ final class PhabricatorPeopleWelcomeMailEngine
->setBody($message); ->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;
}
} }