1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Fix missing link targets for "View Object" header buttons in HTML email

Summary:
See <https://discourse.phabricator-community.org/t/view-task-from-maniphest-e-mail-doesnt-have-url/2827>.

I added "View Task" / "View Commit" buttons recently but the logic for generating URIs isn't quite right. Fix it up.

Test Plan:
  - Commented on a task.
  - Used `bin/mail show-outbound --id ... --dump-html > out.html` to dump the HTML.
  - Previewed the HTML in a browser.
  - This time, actually clicked the button to go to the task.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D20586
This commit is contained in:
epriestley 2019-06-18 07:22:15 -07:00
parent 6219d30f6b
commit 7538286499
4 changed files with 34 additions and 10 deletions

View file

@ -485,7 +485,8 @@ final class PhabricatorAuditEditor
return $phids; return $phids;
} }
protected function getObjectLinkButtonLabelForMail() { protected function getObjectLinkButtonLabelForMail(
PhabricatorLiskDAO $object) {
return pht('View Commit'); return pht('View Commit');
} }

View file

@ -601,7 +601,8 @@ final class DifferentialTransactionEditor
return $xactions; return $xactions;
} }
protected function getObjectLinkButtonLabelForMail() { protected function getObjectLinkButtonLabelForMail(
PhabricatorLiskDAO $object) {
return pht('View Revision'); return pht('View Revision');
} }
@ -614,8 +615,7 @@ final class DifferentialTransactionEditor
$body = id(new PhabricatorMetaMTAMailBody()) $body = id(new PhabricatorMetaMTAMailBody())
->setViewer($viewer); ->setViewer($viewer);
$revision_uri = $object->getURI(); $revision_uri = $this->getObjectLinkButtonURIForMail($object);
$revision_uri = PhabricatorEnv::getProductionURI($revision_uri);
$new_uri = $revision_uri.'/new/'; $new_uri = $revision_uri.'/new/';
$this->addHeadersAndCommentsToMailBody( $this->addHeadersAndCommentsToMailBody(

View file

@ -206,7 +206,8 @@ final class ManiphestTransactionEditor
->setSubject("T{$id}: {$title}"); ->setSubject("T{$id}: {$title}");
} }
protected function getObjectLinkButtonLabelForMail() { protected function getObjectLinkButtonLabelForMail(
PhabricatorLiskDAO $object) {
return pht('View Task'); return pht('View Task');
} }

View file

@ -3423,17 +3423,39 @@ abstract class PhabricatorApplicationTransactionEditor
->setContextObject($object); ->setContextObject($object);
$button_label = $this->getObjectLinkButtonLabelForMail($object); $button_label = $this->getObjectLinkButtonLabelForMail($object);
$button_uri = $this->getObjectLinkButtonURIForMail($object);
$this->addHeadersAndCommentsToMailBody(
$body,
$xactions,
$button_label,
$button_uri);
$this->addHeadersAndCommentsToMailBody($body, $xactions, $button_label);
$this->addCustomFieldsToMailBody($body, $object, $xactions); $this->addCustomFieldsToMailBody($body, $object, $xactions);
return $body; return $body;
} }
protected function getObjectLinkButtonLabelForMail() { protected function getObjectLinkButtonLabelForMail(
PhabricatorLiskDAO $object) {
return null; return null;
} }
protected function getObjectLinkButtonURIForMail(
PhabricatorLiskDAO $object) {
// Most objects define a "getURI()" method which does what we want, but
// this isn't formally part of an interface at time of writing. Try to
// call the method, expecting an exception if it does not exist.
try {
$uri = $object->getURI();
return PhabricatorEnv::getProductionURI($uri);
} catch (Exception $ex) {
return null;
}
}
/** /**
* @task mail * @task mail
*/ */
@ -3455,7 +3477,7 @@ abstract class PhabricatorApplicationTransactionEditor
PhabricatorMetaMTAMailBody $body, PhabricatorMetaMTAMailBody $body,
array $xactions, array $xactions,
$object_label = null, $object_label = null,
$object_href = null) { $object_uri = null) {
// First, remove transactions which shouldn't be rendered in mail. // First, remove transactions which shouldn't be rendered in mail.
foreach ($xactions as $key => $xaction) { foreach ($xactions as $key => $xaction) {
@ -3521,7 +3543,7 @@ abstract class PhabricatorApplicationTransactionEditor
$headers_html = phutil_implode_html(phutil_tag('br'), $headers_html); $headers_html = phutil_implode_html(phutil_tag('br'), $headers_html);
$header_button = null; $header_button = null;
if ($object_label !== null) { if ($object_label !== null && $object_uri !== null) {
$button_style = array( $button_style = array(
'text-decoration: none;', 'text-decoration: none;',
'padding: 4px 8px;', 'padding: 4px 8px;',
@ -3540,7 +3562,7 @@ abstract class PhabricatorApplicationTransactionEditor
'a', 'a',
array( array(
'style' => implode(' ', $button_style), 'style' => implode(' ', $button_style),
'href' => $object_href, 'href' => $object_uri,
), ),
$object_label); $object_label);
} }