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

Add an "Explicit-CCs" header to Differential

Summary: This header allows recipients to distinguish between CCs generated by Herald and CCs generated by humans.

Test Plan: Created a Herald rule to add a bunch of CC's to every revision. Created a revision. Added some CCs manually. Verified that only manual CCs appeared in the "Explicit" header.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran, epriestley

Maniphest Tasks: T808

Differential Revision: https://secure.phabricator.com/D2018
This commit is contained in:
epriestley 2012-03-26 09:55:38 -07:00
parent 2044e51206
commit 89c66cbbd4
6 changed files with 63 additions and 23 deletions

View file

@ -48,9 +48,9 @@ final class DifferentialSubscribeController extends DifferentialController {
case 'rem': case 'rem':
$button = 'Unsubscribe'; $button = 'Unsubscribe';
$title = 'Unsubscribe from Revision'; $title = 'Unsubscribe from Revision';
// TODO: Once herald is in, add a notice about not getting any more $prompt = 'Really unsubscribe from this revision? Herald will '.
// herald notifications. 'not resubscribe you to a revision you unsubscribe '.
$prompt = 'Really unsubscribe from this revision?'; 'from.';
break; break;
default: default:
return new Aphront400Response(); return new Aphront400Response();

View file

@ -234,6 +234,7 @@ final class DifferentialRevisionEditor {
); );
$rem_ccs = array(); $rem_ccs = array();
$xscript_phid = null;
if ($diff) { if ($diff) {
$adapter = new HeraldDifferentialRevisionAdapter( $adapter = new HeraldDifferentialRevisionAdapter(
$revision, $revision,
@ -294,36 +295,37 @@ final class DifferentialRevisionEditor {
array_keys($add['rev']), array_keys($add['rev']),
$this->actorPHID); $this->actorPHID);
/* // We want to attribute new CCs to a "reasonPHID", representing the reason
// they were added. This is either a user (if some user explicitly CCs
// TODO: When Herald is brought over, run through this stuff to figure // them, or uses "Add CCs...") or a Herald transcript PHID, indicating that
// out which adds are Herald's fault. // they were added by a Herald rule.
// TODO: Still need to do this.
if ($add['ccs'] || $rem['ccs']) { if ($add['ccs'] || $rem['ccs']) {
foreach (array_keys($add['ccs']) as $id) { $reasons = array();
if (empty($new['ccs'][$id])) { foreach ($add['ccs'] as $phid => $ignored) {
$reason_phid = 'TODO';//$xscript_phid; if (empty($new['ccs'][$phid])) {
$reasons[$phid] = $xscript_phid;
} else { } else {
$reason_phid = $this->getActorPHID(); $reasons[$phid] = $this->actorPHID;
} }
} }
foreach (array_keys($rem['ccs']) as $id) { foreach ($rem['ccs'] as $phid => $ignored) {
if (empty($new['ccs'][$id])) { if (empty($new['ccs'][$phid])) {
$reason_phid = $this->getActorPHID(); $reasons[$phid] = $this->actorPHID;
} else { } else {
$reason_phid = 'TODO';//$xscript_phid; $reasons[$phid] = $xscript_phid;
} }
} }
} else {
$reasons = $this->actorPHID;
} }
*/
self::alterCCs( self::alterCCs(
$revision, $revision,
$this->cc, $this->cc,
array_keys($rem['ccs']), array_keys($rem['ccs']),
array_keys($add['ccs']), array_keys($add['ccs']),
$this->actorPHID); $reasons);
$this->updateAuxiliaryFields(); $this->updateAuxiliaryFields();
@ -614,10 +616,14 @@ final class DifferentialRevisionEditor {
} }
foreach ($add_phids as $add) { foreach ($add_phids as $add) {
$reason = is_array($reason_phid)
? idx($reason_phid, $add)
: $reason_phid;
$raw[$add] = array( $raw[$add] = array(
'objectPHID' => $add, 'objectPHID' => $add,
'sequence' => idx($seq_map, $add, $sequence++), 'sequence' => idx($seq_map, $add, $sequence++),
'reasonPHID' => $reason_phid, 'reasonPHID' => $reason,
); );
} }

View file

@ -116,6 +116,33 @@ abstract class DifferentialMail {
$template->addHeader( $template->addHeader(
'X-Differential-CCs', 'X-Differential-CCs',
'<'.implode('>, <', $revision->getCCPHIDs()).'>'); '<'.implode('>, <', $revision->getCCPHIDs()).'>');
// Determine explicit CCs (those added by humans) and put them in a
// header so users can differentiate between Herald CCs and human CCs.
$relation_subscribed = DifferentialRevision::RELATION_SUBSCRIBED;
$raw = $revision->getRawRelations($relation_subscribed);
$reason_phids = ipull($raw, 'reasonPHID');
$reason_handles = id(new PhabricatorObjectHandleData($reason_phids))
->loadHandles();
$explicit_cc = array();
foreach ($raw as $relation) {
if (!$relation['reasonPHID']) {
continue;
}
$type = $reason_handles[$relation['reasonPHID']]->getType();
if ($type == PhabricatorPHIDConstants::PHID_TYPE_USER) {
$explicit_cc[] = $relation['objectPHID'];
}
}
if ($explicit_cc) {
$template->addHeader(
'X-Differential-Explicit-CCs',
'<'.implode('>, <', $explicit_cc).'>');
}
} }
} }

View file

@ -6,7 +6,9 @@
phutil_require_module('phabricator', 'applications/differential/storage/revision');
phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'applications/metamta/storage/mail');
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phabricator', 'infrastructure/events/constant/type'); phutil_require_module('phabricator', 'infrastructure/events/constant/type');

View file

@ -131,10 +131,12 @@ final class DifferentialRevisionCommentView extends AphrontView {
$metadata = $comment->getMetadata(); $metadata = $comment->getMetadata();
$added_reviewers = idx( $added_reviewers = idx(
$metadata, $metadata,
DifferentialComment::METADATA_ADDED_REVIEWERS); DifferentialComment::METADATA_ADDED_REVIEWERS,
array());
$added_ccs = idx( $added_ccs = idx(
$metadata, $metadata,
DifferentialComment::METADATA_ADDED_CCS); DifferentialComment::METADATA_ADDED_CCS,
array());
$verb = DifferentialAction::getActionPastTenseVerb($comment->getAction()); $verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
$verb = phutil_escape_html($verb); $verb = phutil_escape_html($verb);

View file

@ -62,7 +62,10 @@ The headers Phabricator adds to mail are:
are reviewing, versus revisions you are explicitly CC'd on or CC'd as are reviewing, versus revisions you are explicitly CC'd on or CC'd as
a result of Herald rules. a result of Herald rules.
- ##X-Differential-CCs##: this is attached to Differential mail and shows - ##X-Differential-CCs##: this is attached to Differential mail and shows
the explicit CCs on the revision. the CCs on the revision.
- ##X-Differential-Explicit-CCs##: this is attached to Differential mail and
shows the explicit CCs on the revision (those that were added by humans,
not by Herald).
- ##X-Phabricator-Mail-Tags##: this is attached to some mail and has - ##X-Phabricator-Mail-Tags##: this is attached to some mail and has
a list of descriptors about the mail. (This is fairly new and subject a list of descriptors about the mail. (This is fairly new and subject
to some change.) to some change.)