mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Update the "Notification Test" workflow to use more modern mechanisms
Summary: Depends on D19860. Ref T13222. Ref T10743. See PHI996. Long ago, there were different types of feed stories. Over time, there was less and less need for this, and nowadays basically everything is a "transaction" feed story. Each story renders differently, but they're fundamentally all about transactions. The Notification test controller still uses a custom type of feed story to send notifications. Move away from this, and apply a transaction against the user instead. This has the same ultimate effect, but involves less weird custom code from ages long forgotten. This doesn't fix the actual problem with these things showing up in feed. Currently, stories always use the same rendering for feed and notifications, and there need to be some additional changes to fix this. So no behavioral change yet, just slightly more reasonable code. Test Plan: Clicked the button and got some test notifications, with Aphlict running. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13222, T10743 Differential Revision: https://secure.phabricator.com/D19861
This commit is contained in:
parent
55a1ef339f
commit
ba83380565
8 changed files with 115 additions and 43 deletions
|
@ -4623,6 +4623,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserLogView' => 'applications/people/view/PhabricatorUserLogView.php',
|
||||
'PhabricatorUserMessageCountCacheType' => 'applications/people/cache/PhabricatorUserMessageCountCacheType.php',
|
||||
'PhabricatorUserNotificationCountCacheType' => 'applications/people/cache/PhabricatorUserNotificationCountCacheType.php',
|
||||
'PhabricatorUserNotifyTransaction' => 'applications/people/xaction/PhabricatorUserNotifyTransaction.php',
|
||||
'PhabricatorUserPHIDResolver' => 'applications/phid/resolver/PhabricatorUserPHIDResolver.php',
|
||||
'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php',
|
||||
'PhabricatorUserPreferencesCacheType' => 'applications/people/cache/PhabricatorUserPreferencesCacheType.php',
|
||||
|
@ -10676,6 +10677,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUserLogView' => 'AphrontView',
|
||||
'PhabricatorUserMessageCountCacheType' => 'PhabricatorUserCacheType',
|
||||
'PhabricatorUserNotificationCountCacheType' => 'PhabricatorUserCacheType',
|
||||
'PhabricatorUserNotifyTransaction' => 'PhabricatorUserTransactionType',
|
||||
'PhabricatorUserPHIDResolver' => 'PhabricatorPHIDResolver',
|
||||
'PhabricatorUserPreferences' => array(
|
||||
'PhabricatorUserDAO',
|
||||
|
|
|
@ -6,34 +6,31 @@ final class PhabricatorNotificationTestController
|
|||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$story_type = 'PhabricatorNotificationTestFeedStory';
|
||||
$story_data = array(
|
||||
'title' => pht(
|
||||
'This is a test notification, sent at %s.',
|
||||
phabricator_datetime(time(), $viewer)),
|
||||
);
|
||||
|
||||
$viewer_phid = $viewer->getPHID();
|
||||
|
||||
// NOTE: Because we don't currently show you your own notifications, make
|
||||
// sure this comes from a different PHID.
|
||||
$application_phid = id(new PhabricatorNotificationsApplication())
|
||||
->getPHID();
|
||||
|
||||
// TODO: When it's easier to get these buttons to render as forms, this
|
||||
// would be slightly nicer as a more standard isFormPost() check.
|
||||
|
||||
if ($request->validateCSRF()) {
|
||||
id(new PhabricatorFeedStoryPublisher())
|
||||
->setStoryType($story_type)
|
||||
->setStoryData($story_data)
|
||||
->setStoryTime(time())
|
||||
->setStoryAuthorPHID($application_phid)
|
||||
->setRelatedPHIDs(array($viewer_phid))
|
||||
->setPrimaryObjectPHID($viewer_phid)
|
||||
->setSubscribedPHIDs(array($viewer_phid))
|
||||
->setNotifyAuthor(true)
|
||||
->publish();
|
||||
$message_text = pht(
|
||||
'This is a test notification, sent at %s.',
|
||||
phabricator_datetime(time(), $viewer));
|
||||
|
||||
// NOTE: Currently, the FeedStoryPublisher explicitly filters out
|
||||
// notifications about your own actions. Send this notification from
|
||||
// a different actor to get around this.
|
||||
$application_phid = id(new PhabricatorNotificationsApplication())
|
||||
->getPHID();
|
||||
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(new PhabricatorUserTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorUserNotifyTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($message_text)
|
||||
->setForceNotifyPHIDs(array($viewer->getPHID()));
|
||||
|
||||
$editor = id(new PhabricatorUserTransactionEditor())
|
||||
->setActor($viewer)
|
||||
->setActingAsPHID($application_phid)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
$editor->applyTransactions($viewer, $xactions);
|
||||
}
|
||||
|
||||
return id(new AphrontAjaxResponse());
|
||||
|
|
|
@ -43,6 +43,11 @@ final class PhabricatorPeopleProfileManageController
|
|||
->setCurtain($curtain)
|
||||
->addPropertySection(pht('Details'), $properties);
|
||||
|
||||
$timeline = $this->buildTransactionTimeline(
|
||||
$user,
|
||||
new PhabricatorPeopleTransactionQuery());
|
||||
$timeline->setShouldTerminate(true);
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle(
|
||||
array(
|
||||
|
@ -54,6 +59,7 @@ final class PhabricatorPeopleProfileManageController
|
|||
->appendChild(
|
||||
array(
|
||||
$manage,
|
||||
$timeline,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -11,4 +11,18 @@ final class PhabricatorUserTransactionEditor
|
|||
return pht('Users');
|
||||
}
|
||||
|
||||
protected function shouldPublishFeedStory(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getMailTo(PhabricatorLiskDAO $object) {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getMailCC(PhabricatorLiskDAO $object) {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,19 +35,10 @@ final class PhabricatorUserDisableTransaction
|
|||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
if ($new) {
|
||||
return pht(
|
||||
'%s disabled %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
} else {
|
||||
return pht(
|
||||
'%s enabled %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
public function shouldHideForFeed() {
|
||||
// Don't publish feed stories about disabling users, since this can be
|
||||
// a sensitive action.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorUserNotifyTransaction
|
||||
extends PhabricatorUserTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'notify';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateNewValue($object, $value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s sent this user a test notification.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
return $this->getNewValue();
|
||||
}
|
||||
|
||||
public function shouldHideForFeed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function shouldHideForMail() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -3378,9 +3378,28 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
return array_unique(array_merge(
|
||||
$this->getMailTo($object),
|
||||
$this->getMailCC($object)));
|
||||
// If some transactions are forcing notification delivery, add the forced
|
||||
// recipients to the notify list.
|
||||
$force_list = array();
|
||||
foreach ($xactions as $xaction) {
|
||||
$force_phids = $xaction->getForceNotifyPHIDs();
|
||||
|
||||
if (!$force_phids) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($force_phids as $force_phid) {
|
||||
$force_list[] = $force_phid;
|
||||
}
|
||||
}
|
||||
|
||||
$to_list = $this->getMailTo($object);
|
||||
$cc_list = $this->getMailCC($object);
|
||||
|
||||
$full_list = array_merge($force_list, $to_list, $cc_list);
|
||||
$full_list = array_fuse($full_list);
|
||||
|
||||
return array_keys($full_list);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1662,6 +1662,15 @@ abstract class PhabricatorApplicationTransaction
|
|||
return null;
|
||||
}
|
||||
|
||||
public function setForceNotifyPHIDs(array $phids) {
|
||||
$this->setMetadataValue('notify.force', $phids);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getForceNotifyPHIDs() {
|
||||
return $this->getMetadataValue('notify.force', array());
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
|
Loading…
Reference in a new issue