@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+34 -10
+2 -1
src/applications/audit/editor/PhabricatorAuditEditor.php
··· 485 485 return $phids; 486 486 } 487 487 488 - protected function getObjectLinkButtonLabelForMail() { 488 + protected function getObjectLinkButtonLabelForMail( 489 + PhabricatorLiskDAO $object) { 489 490 return pht('View Commit'); 490 491 } 491 492
+3 -3
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 601 601 return $xactions; 602 602 } 603 603 604 - protected function getObjectLinkButtonLabelForMail() { 604 + protected function getObjectLinkButtonLabelForMail( 605 + PhabricatorLiskDAO $object) { 605 606 return pht('View Revision'); 606 607 } 607 608 ··· 614 615 $body = id(new PhabricatorMetaMTAMailBody()) 615 616 ->setViewer($viewer); 616 617 617 - $revision_uri = $object->getURI(); 618 - $revision_uri = PhabricatorEnv::getProductionURI($revision_uri); 618 + $revision_uri = $this->getObjectLinkButtonURIForMail($object); 619 619 $new_uri = $revision_uri.'/new/'; 620 620 621 621 $this->addHeadersAndCommentsToMailBody(
+2 -1
src/applications/maniphest/editor/ManiphestTransactionEditor.php
··· 206 206 ->setSubject("T{$id}: {$title}"); 207 207 } 208 208 209 - protected function getObjectLinkButtonLabelForMail() { 209 + protected function getObjectLinkButtonLabelForMail( 210 + PhabricatorLiskDAO $object) { 210 211 return pht('View Task'); 211 212 } 212 213
+27 -5
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 3423 3423 ->setContextObject($object); 3424 3424 3425 3425 $button_label = $this->getObjectLinkButtonLabelForMail($object); 3426 + $button_uri = $this->getObjectLinkButtonURIForMail($object); 3426 3427 3427 - $this->addHeadersAndCommentsToMailBody($body, $xactions, $button_label); 3428 + $this->addHeadersAndCommentsToMailBody( 3429 + $body, 3430 + $xactions, 3431 + $button_label, 3432 + $button_uri); 3433 + 3428 3434 $this->addCustomFieldsToMailBody($body, $object, $xactions); 3429 3435 3430 3436 return $body; 3431 3437 } 3432 3438 3433 - protected function getObjectLinkButtonLabelForMail() { 3439 + protected function getObjectLinkButtonLabelForMail( 3440 + PhabricatorLiskDAO $object) { 3434 3441 return null; 3435 3442 } 3436 3443 3444 + protected function getObjectLinkButtonURIForMail( 3445 + PhabricatorLiskDAO $object) { 3446 + 3447 + // Most objects define a "getURI()" method which does what we want, but 3448 + // this isn't formally part of an interface at time of writing. Try to 3449 + // call the method, expecting an exception if it does not exist. 3450 + 3451 + try { 3452 + $uri = $object->getURI(); 3453 + return PhabricatorEnv::getProductionURI($uri); 3454 + } catch (Exception $ex) { 3455 + return null; 3456 + } 3457 + } 3458 + 3437 3459 /** 3438 3460 * @task mail 3439 3461 */ ··· 3455 3477 PhabricatorMetaMTAMailBody $body, 3456 3478 array $xactions, 3457 3479 $object_label = null, 3458 - $object_href = null) { 3480 + $object_uri = null) { 3459 3481 3460 3482 // First, remove transactions which shouldn't be rendered in mail. 3461 3483 foreach ($xactions as $key => $xaction) { ··· 3521 3543 $headers_html = phutil_implode_html(phutil_tag('br'), $headers_html); 3522 3544 3523 3545 $header_button = null; 3524 - if ($object_label !== null) { 3546 + if ($object_label !== null && $object_uri !== null) { 3525 3547 $button_style = array( 3526 3548 'text-decoration: none;', 3527 3549 'padding: 4px 8px;', ··· 3540 3562 'a', 3541 3563 array( 3542 3564 'style' => implode(' ', $button_style), 3543 - 'href' => $object_href, 3565 + 'href' => $object_uri, 3544 3566 ), 3545 3567 $object_label); 3546 3568 }