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

Add Editor-based mail stamps: actor, via, silent, encrypted, new, mention, self-actor, self-mention

Summary: Ref T13053. Adds more mail tags with information available on the Editor object.

Test Plan: Banged around in Maniphest, viewed the resulting mail, all the stamps seemed to align with reality.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13053

Differential Revision: https://secure.phabricator.com/D18995
This commit is contained in:
epriestley 2018-02-05 10:31:56 -08:00
parent 9de54aedb5
commit 3131e733a8
9 changed files with 200 additions and 6 deletions

View file

@ -2220,6 +2220,7 @@ phutil_register_library_map(array(
'PhabricatorBoardResponseEngine' => 'applications/project/engine/PhabricatorBoardResponseEngine.php',
'PhabricatorBoolConfigType' => 'applications/config/type/PhabricatorBoolConfigType.php',
'PhabricatorBoolEditField' => 'applications/transactions/editfield/PhabricatorBoolEditField.php',
'PhabricatorBoolMailStamp' => 'applications/metamta/stamp/PhabricatorBoolMailStamp.php',
'PhabricatorBritishEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBritishEnglishTranslation.php',
'PhabricatorBuiltinDraftEngine' => 'applications/transactions/draft/PhabricatorBuiltinDraftEngine.php',
'PhabricatorBuiltinFileCachePurger' => 'applications/cache/purger/PhabricatorBuiltinFileCachePurger.php',
@ -2813,6 +2814,7 @@ phutil_register_library_map(array(
'PhabricatorEditPage' => 'applications/transactions/editengine/PhabricatorEditPage.php',
'PhabricatorEditType' => 'applications/transactions/edittype/PhabricatorEditType.php',
'PhabricatorEditor' => 'infrastructure/PhabricatorEditor.php',
'PhabricatorEditorMailEngineExtension' => 'applications/transactions/engineextension/PhabricatorEditorMailEngineExtension.php',
'PhabricatorEditorMultipleSetting' => 'applications/settings/setting/PhabricatorEditorMultipleSetting.php',
'PhabricatorEditorSetting' => 'applications/settings/setting/PhabricatorEditorSetting.php',
'PhabricatorElasticFulltextStorageEngine' => 'applications/search/fulltextstorage/PhabricatorElasticFulltextStorageEngine.php',
@ -3440,6 +3442,7 @@ phutil_register_library_map(array(
'PhabricatorPHIDListEditField' => 'applications/transactions/editfield/PhabricatorPHIDListEditField.php',
'PhabricatorPHIDListEditType' => 'applications/transactions/edittype/PhabricatorPHIDListEditType.php',
'PhabricatorPHIDListExportField' => 'infrastructure/export/field/PhabricatorPHIDListExportField.php',
'PhabricatorPHIDMailStamp' => 'applications/metamta/stamp/PhabricatorPHIDMailStamp.php',
'PhabricatorPHIDResolver' => 'applications/phid/resolver/PhabricatorPHIDResolver.php',
'PhabricatorPHIDType' => 'applications/phid/type/PhabricatorPHIDType.php',
'PhabricatorPHIDTypeTestCase' => 'applications/phid/type/__tests__/PhabricatorPHIDTypeTestCase.php',
@ -4395,6 +4398,7 @@ phutil_register_library_map(array(
'PhabricatorVersionedDraft' => 'applications/draft/storage/PhabricatorVersionedDraft.php',
'PhabricatorVeryWowEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorVeryWowEnglishTranslation.php',
'PhabricatorViewerDatasource' => 'applications/people/typeahead/PhabricatorViewerDatasource.php',
'PhabricatorViewerMailStamp' => 'applications/metamta/stamp/PhabricatorViewerMailStamp.php',
'PhabricatorWatcherHasObjectEdgeType' => 'applications/transactions/edges/PhabricatorWatcherHasObjectEdgeType.php',
'PhabricatorWebContentSource' => 'infrastructure/contentsource/PhabricatorWebContentSource.php',
'PhabricatorWebServerSetupCheck' => 'applications/config/check/PhabricatorWebServerSetupCheck.php',
@ -7582,6 +7586,7 @@ phutil_register_library_map(array(
'PhabricatorBoardResponseEngine' => 'Phobject',
'PhabricatorBoolConfigType' => 'PhabricatorTextConfigType',
'PhabricatorBoolEditField' => 'PhabricatorEditField',
'PhabricatorBoolMailStamp' => 'PhabricatorMailStamp',
'PhabricatorBritishEnglishTranslation' => 'PhutilTranslation',
'PhabricatorBuiltinDraftEngine' => 'PhabricatorDraftEngine',
'PhabricatorBuiltinFileCachePurger' => 'PhabricatorCachePurger',
@ -8267,6 +8272,7 @@ phutil_register_library_map(array(
'PhabricatorEditPage' => 'Phobject',
'PhabricatorEditType' => 'Phobject',
'PhabricatorEditor' => 'Phobject',
'PhabricatorEditorMailEngineExtension' => 'PhabricatorMailEngineExtension',
'PhabricatorEditorMultipleSetting' => 'PhabricatorSelectSetting',
'PhabricatorEditorSetting' => 'PhabricatorStringSetting',
'PhabricatorElasticFulltextStorageEngine' => 'PhabricatorFulltextStorageEngine',
@ -8973,6 +8979,7 @@ phutil_register_library_map(array(
'PhabricatorPHIDListEditField' => 'PhabricatorEditField',
'PhabricatorPHIDListEditType' => 'PhabricatorEditType',
'PhabricatorPHIDListExportField' => 'PhabricatorListExportField',
'PhabricatorPHIDMailStamp' => 'PhabricatorMailStamp',
'PhabricatorPHIDResolver' => 'Phobject',
'PhabricatorPHIDType' => 'Phobject',
'PhabricatorPHIDTypeTestCase' => 'PhutilTestCase',
@ -10137,6 +10144,7 @@ phutil_register_library_map(array(
'PhabricatorVersionedDraft' => 'PhabricatorDraftDAO',
'PhabricatorVeryWowEnglishTranslation' => 'PhutilTranslation',
'PhabricatorViewerDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorViewerMailStamp' => 'PhabricatorMailStamp',
'PhabricatorWatcherHasObjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorWebContentSource' => 'PhabricatorContentSource',
'PhabricatorWebServerSetupCheck' => 'PhabricatorSetupCheck',

View file

@ -0,0 +1,16 @@
<?php
final class PhabricatorBoolMailStamp
extends PhabricatorMailStamp {
const STAMPTYPE = 'bool';
public function renderStamps($value) {
if (!$value) {
return null;
}
return $this->renderStamp($this->getKey());
}
}

View file

@ -0,0 +1,36 @@
<?php
final class PhabricatorPHIDMailStamp
extends PhabricatorMailStamp {
const STAMPTYPE = 'phid';
public function renderStamps($value) {
if ($value === null) {
return null;
}
$value = (array)$value;
if (!$value) {
return null;
}
$viewer = $this->getViewer();
$handles = $viewer->loadHandles($value);
$results = array();
foreach ($value as $phid) {
$handle = $handles[$phid];
$mail_name = $handle->getMailStampName();
if ($mail_name === null) {
$mail_name = $handle->getPHID();
}
$results[] = $this->renderStamp($this->getKey(), $mail_name);
}
return $results;
}
}

View file

@ -0,0 +1,35 @@
<?php
final class PhabricatorViewerMailStamp
extends PhabricatorMailStamp {
const STAMPTYPE = 'viewer';
public function renderStamps($value) {
// If we're sending one mail to everyone, we never include viewer-based
// stamps since they'll only be accurate for one recipient. Recipients
// can still use the corresponding stamps with their usernames or PHIDs.
if (!PhabricatorMetaMTAMail::shouldMailEachRecipient()) {
return null;
}
$viewer_phid = $this->getViewer()->getPHID();
if (!$viewer_phid) {
return null;
}
if (!$value) {
return null;
}
$value = (array)$value;
$value = array_fuse($value);
if (!isset($value[$viewer_phid])) {
return null;
}
return $this->renderStamp($this->getKey());
}
}

View file

@ -39,11 +39,14 @@ final class PhabricatorPeopleUserPHIDType extends PhabricatorPHIDType {
foreach ($handles as $phid => $handle) {
$user = $objects[$phid];
$realname = $user->getRealName();
$username = $user->getUsername();
$handle->setName($user->getUsername());
$handle->setURI('/p/'.$user->getUsername().'/');
$handle->setFullName($user->getFullName());
$handle->setImageURI($user->getProfileImageURI());
$handle
->setName($username)
->setURI('/p/'.$username.'/')
->setFullName($user->getFullName())
->setImageURI($user->getProfileImageURI())
->setMailStampName('@'.$username);
if ($user->getIsMailingList()) {
$handle->setIcon('fa-envelope-o');

View file

@ -31,6 +31,7 @@ final class PhabricatorObjectHandle
private $subtitle;
private $tokenIcon;
private $commandLineObjectName;
private $mailStampName;
private $stateIcon;
private $stateColor;
@ -134,6 +135,15 @@ final class PhabricatorObjectHandle
return $this->objectName;
}
public function setMailStampName($mail_stamp_name) {
$this->mailStampName = $mail_stamp_name;
return $this;
}
public function getMailStampName() {
return $this->mailStampName;
}
public function setURI($uri) {
$this->uri = $uri;
return $this;

View file

@ -45,11 +45,12 @@ final class PhabricatorProjectProjectPHIDType extends PhabricatorPHIDType {
if (strlen($slug)) {
$handle->setObjectName('#'.$slug);
$handle->setMailStampName('#'.$slug);
$handle->setURI("/tag/{$slug}/");
} else {
// We set the name to the project's PHID to avoid a parse error when a
// project has no hashtag (as is the case with milestones by default).
// See T12659 for more details
// See T12659 for more details.
$handle->setCommandLineObjectName($project->getPHID());
$handle->setURI("/project/view/{$id}/");
}

View file

@ -179,7 +179,7 @@ abstract class PhabricatorApplicationTransactionEditor
return $this->isNewObject;
}
protected function getMentionedPHIDs() {
public function getMentionedPHIDs() {
return $this->mentionedPHIDs;
}
@ -201,6 +201,10 @@ abstract class PhabricatorApplicationTransactionEditor
return $this->silent;
}
public function getMustEncrypt() {
return $this->mustEncrypt;
}
public function setIsInverseEdgeEditor($is_inverse_edge_editor) {
$this->isInverseEdgeEditor = $is_inverse_edge_editor;
return $this;

View file

@ -0,0 +1,81 @@
<?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 PhabricatorViewerMailStamp())
->setKey('self-actor')
->setLabel(pht('You Acted'));
$templates[] = id(new PhabricatorViewerMailStamp())
->setKey('self-mention')
->setLabel(pht('You Were Mentioned'));
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('self-actor')
->setValue($editor->getActingAsPHID());
$this->getMailStamp('self-mention')
->setValue($mentioned_phids);
}
}