From 20892b0bc2d908dd0354c5468d580e01c3ce2c4b Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 May 2011 08:33:27 -0700 Subject: [PATCH] Link to attached objects in email when a Maniphest task has stuff attached Summary: When files or revisions are attached to a Maniphest task, link to the new stuff in the email. See T116. Test Plan: Attached files and revisions to a task, got sensible-looking emails about it. Reviewed By: tomo Reviewers: tomo, jungejason, tuomaspelkonen, aran CC: aran, tomo Differential Revision: 286 --- .../ManiphestTransactionDetailView.php | 61 +++++++++++++++++++ .../view/transactiondetail/__init__.php | 1 + 2 files changed, 62 insertions(+) diff --git a/src/applications/maniphest/view/transactiondetail/ManiphestTransactionDetailView.php b/src/applications/maniphest/view/transactiondetail/ManiphestTransactionDetailView.php index 4c5ffd8d77..6277e7d145 100644 --- a/src/applications/maniphest/view/transactiondetail/ManiphestTransactionDetailView.php +++ b/src/applications/maniphest/view/transactiondetail/ManiphestTransactionDetailView.php @@ -70,10 +70,18 @@ class ManiphestTransactionDetailView extends AphrontView { } $descs = implode("\n", $descs); + if ($comments) { $descs .= "\n".$comments; } + foreach ($this->transactions as $transaction) { + $supplemental = $this->renderSupplementalLinksForEmail($transaction); + if ($supplemental) { + $descs .= "\n\n".$supplemental; + } + } + $this->forEmail = false; return array($action, $descs); } @@ -149,6 +157,59 @@ class ManiphestTransactionDetailView extends AphrontView { ''); } + private function renderSupplementalLinksForEmail($transaction) { + $handles = $this->handles; + + $type = $transaction->getTransactionType(); + $new = $transaction->getNewValue(); + $old = $transaction->getOldValue(); + + switch ($type) { + case ManiphestTransactionType::TYPE_ATTACH: + $old_raw = nonempty($old, array()); + $new_raw = nonempty($new, array()); + + $attach_types = array( + PhabricatorPHIDConstants::PHID_TYPE_DREV, + PhabricatorPHIDConstants::PHID_TYPE_FILE, + ); + + foreach ($attach_types as $type) { + $old = array_keys(idx($old_raw, $type, array())); + $new = array_keys(idx($new_raw, $type, array())); + if ($old != $new) { + break; + } + } + + $added = array_diff($new, $old); + if (!$added) { + break; + } + + $links = array(); + foreach (array_select_keys($handles, $added) as $handle) { + $links[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); + } + $links = implode("\n", $links); + + switch ($type) { + case PhabricatorPHIDConstants::PHID_TYPE_DREV: + $title = 'ATTACHED REVISIONS'; + break; + case PhabricatorPHIDConstants::PHID_TYPE_FILE: + $title = 'ATTACHED FILES'; + break; + } + + return $title."\n".$links; + default: + break; + } + + return null; + } + private function describeAction($transaction) { $verb = null; $desc = null; diff --git a/src/applications/maniphest/view/transactiondetail/__init__.php b/src/applications/maniphest/view/transactiondetail/__init__.php index a5700bb1af..a7da42d3a8 100644 --- a/src/applications/maniphest/view/transactiondetail/__init__.php +++ b/src/applications/maniphest/view/transactiondetail/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/maniphest/constants/status'); phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); phutil_require_module('phabricator', 'applications/phid/constants'); phutil_require_module('phabricator', 'infrastructure/celerity/api'); +phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'view/base'); phutil_require_module('phabricator', 'view/utils');