mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +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:
parent
22ad1ff2c5
commit
6bb31de305
4 changed files with 66 additions and 21 deletions
|
@ -61,14 +61,20 @@ final class PhabricatorAuthMessage
|
|||
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(
|
||||
PhabricatorUser $viewer,
|
||||
$message_key) {
|
||||
|
||||
$message = id(new PhabricatorAuthMessageQuery())
|
||||
->setViewer($viewer)
|
||||
->withMessageKeys(array($message_key))
|
||||
->executeOne();
|
||||
$message = self::loadMessage($viewer, $message_key);
|
||||
|
||||
if (!$message) {
|
||||
return null;
|
||||
|
|
|
@ -48,26 +48,38 @@ final class PhabricatorPeopleWelcomeController
|
|||
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));
|
||||
|
|
|
@ -58,4 +58,15 @@ abstract class PhabricatorPeopleMailEngine
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,9 +49,6 @@ final class PhabricatorPeopleWelcomeMailEngine
|
|||
$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 @@ final class PhabricatorPeopleWelcomeMailEngine
|
|||
$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 @@ final class PhabricatorPeopleWelcomeMailEngine
|
|||
->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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue