1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-09 06:11:01 +01:00
phorge-phorge/src/applications/transactions/engineextension/PhabricatorEditorMailEngineExtension.php
epriestley f214abb63f When a change removes recipients from an object, send them one last email
Summary:
Depends on D19018. Fixes T4776. Ref T13053. When you remove someone from an object's recipient list (for example, by removing them a reviewer, auditor, subscriber, owner or author) we currently do not send them mail about it because they're no longer connected to the object.

In many of these cases (Commandeer, Reassign) the actual action in the UI adds them back to the object somehow (as a reviewer or subscriber, respectively) so this doesn't actually matter. However, there's no recovery mechanism for reviewer or subscriber removal.

This is slightly bad from a policy/threat viewpoint since it means an attacker can remove all the recipients of an object "somewhat" silently. This isn't really silent, but it's less un-silent than it should be.

It's also just not very good from a human interaction perspective: if Alice removes Bob as a reviewer, possibly "against his will", he should be notified about that. In the good case, Alice wrote a nice goodbye note that he should get to read. In the bad case, he should get a chance to correct the mistake.

Also add a `removed(@user)` mail stamp so you can route these locally if you want.

Test Plan:
  - Created and edited some different objects without catching anything broken.
  - Removed subscribers from tasks, saw the final email include the removed recipients with a `removed()` stamp.

I'm not totally sure this doesn't have any surprising behavior or break any weird objects, but I think anything that crops up should be easy to fix.

Reviewers: amckinley

Subscribers: sophiebits

Maniphest Tasks: T13053, T4776

Differential Revision: https://secure.phabricator.com/D19019
2018-02-08 06:28:11 -08:00

81 lines
2.1 KiB
PHP

<?php
final class PhabricatorEditorMailEngineExtension
extends PhabricatorMailEngineExtension {
const EXTENSIONKEY = 'editor';
public function supportsObject($object) {
return true;
}
public function newMailStampTemplates($object) {
$templates = array();
$templates[] = id(new PhabricatorPHIDMailStamp())
->setKey('actor')
->setLabel(pht('Acting User'));
$templates[] = id(new PhabricatorStringMailStamp())
->setKey('via')
->setLabel(pht('Via Content Source'));
$templates[] = id(new PhabricatorBoolMailStamp())
->setKey('silent')
->setLabel(pht('Silent Edit'));
$templates[] = id(new PhabricatorBoolMailStamp())
->setKey('encrypted')
->setLabel(pht('Encryption Required'));
$templates[] = id(new PhabricatorBoolMailStamp())
->setKey('new')
->setLabel(pht('New Object'));
$templates[] = id(new PhabricatorPHIDMailStamp())
->setKey('mention')
->setLabel(pht('Mentioned User'));
$templates[] = id(new PhabricatorStringMailStamp())
->setKey('herald')
->setLabel(pht('Herald Rule'));
$templates[] = id(new PhabricatorPHIDMailStamp())
->setKey('removed')
->setLabel(pht('Recipient Removed'));
return $templates;
}
public function newMailStamps($object, array $xactions) {
$editor = $this->getEditor();
$viewer = $this->getViewer();
$this->getMailStamp('actor')
->setValue($editor->getActingAsPHID());
$content_source = $editor->getContentSource();
$this->getMailStamp('via')
->setValue($content_source->getSourceTypeConstant());
$this->getMailStamp('silent')
->setValue($editor->getIsSilent());
$this->getMailStamp('encrypted')
->setValue($editor->getMustEncrypt());
$this->getMailStamp('new')
->setValue($editor->getIsNewObject());
$mentioned_phids = $editor->getMentionedPHIDs();
$this->getMailStamp('mention')
->setValue($mentioned_phids);
$this->getMailStamp('herald')
->setValue($editor->getHeraldRuleMonograms());
$this->getMailStamp('removed')
->setValue($editor->getRemovedRecipientPHIDs());
}
}