1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Add a "Send Test Notification" button to make testing the server easier

Summary: Ref T4324. Currently, it's a bit of a pain to send yourself notifications, and often involves multiple browsers. Instead, add a button to send them.

Test Plan: {F114495}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4324

Differential Revision: https://secure.phabricator.com/D8255
This commit is contained in:
epriestley 2014-02-17 16:00:33 -08:00
parent 6740082df9
commit 18f856ac6f
7 changed files with 104 additions and 5 deletions

View file

@ -1697,6 +1697,7 @@ phutil_register_library_map(array(
'PhabricatorNamedQuery' => 'applications/search/storage/PhabricatorNamedQuery.php',
'PhabricatorNamedQueryQuery' => 'applications/search/query/PhabricatorNamedQueryQuery.php',
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
'PhabricatorNotificationAdHocFeedStory' => 'applications/notification/feed/PhabricatorNotificationAdHocFeedStory.php',
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
'PhabricatorNotificationClient' => 'applications/notification/client/PhabricatorNotificationClient.php',
@ -1707,6 +1708,7 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php',
'PhabricatorNotificationQuery' => 'applications/notification/PhabricatorNotificationQuery.php',
'PhabricatorNotificationStatusController' => 'applications/notification/controller/PhabricatorNotificationStatusController.php',
'PhabricatorNotificationTestController' => 'applications/notification/controller/PhabricatorNotificationTestController.php',
'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/PhabricatorOAuthClientAuthorization.php',
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationBaseController.php',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/PhabricatorOAuthClientAuthorizationDeleteController.php',
@ -4430,6 +4432,7 @@ phutil_register_library_map(array(
),
'PhabricatorNamedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorNoteExample' => 'PhabricatorUIExample',
'PhabricatorNotificationAdHocFeedStory' => 'PhabricatorFeedStory',
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorNotificationController' => 'PhabricatorController',
@ -4438,6 +4441,7 @@ phutil_register_library_map(array(
'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController',
'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController',
'PhabricatorNotificationTestController' => 'PhabricatorNotificationController',
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController',

View file

@ -10,6 +10,17 @@ final class PhabricatorFeedStoryPublisher {
private $primaryObjectPHID;
private $subscribedPHIDs = array();
private $mailRecipientPHIDs = array();
private $notifyAuthor;
public function setNotifyAuthor($notify_author) {
$this->notifyAuthor = $notify_author;
return $this;
}
public function getNotifyAuthor() {
return $this->notifyAuthor;
}
public function setRelatedPHIDs(array $phids) {
$this->relatedPHIDs = $phids;
@ -116,9 +127,12 @@ final class PhabricatorFeedStoryPublisher {
private function insertNotifications($chrono_key) {
$subscribed_phids = $this->subscribedPHIDs;
$subscribed_phids = array_diff(
$subscribed_phids,
array($this->storyAuthorPHID));
if (!$this->notifyAuthor) {
$subscribed_phids = array_diff(
$subscribed_phids,
array($this->storyAuthorPHID));
}
if (!$subscribed_phids) {
return;

View file

@ -19,6 +19,7 @@ final class PhabricatorApplicationNotifications extends PhabricatorApplication {
'individual/' => 'PhabricatorNotificationIndividualController',
'status/' => 'PhabricatorNotificationStatusController',
'clear/' => 'PhabricatorNotificationClearController',
'test/' => 'PhabricatorNotificationTestController',
),
);
}

View file

@ -26,7 +26,7 @@ final class PhabricatorNotificationIndividualController
$response = array(
'pertinent' => true,
'primaryObjectPHID' => head($stories)->getPrimaryObjectPHID(),
'content' => $content,
'content' => hsprintf('%s', $content),
);
return id(new AphrontAjaxResponse())->setContent($response);

View file

@ -59,8 +59,23 @@ final class PhabricatorNotificationStatusController
'wide',
));
$test_icon = id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
->setSpriteIcon('warning');
$test_button = id(new PHUIButtonView())
->setTag('a')
->setWorkflow(true)
->setText(pht('Send Test Notification'))
->setHref($this->getApplicationURI("test/"))
->setIcon($test_icon);
$header = id(new PHUIHeaderView())
->setHeader(pht('Notification Server Status'))
->addActionLink($test_button);
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Server Status'))
->setHeader($header)
->appendChild($table);
return $box;

View file

@ -0,0 +1,38 @@
<?php
final class PhabricatorNotificationTestController
extends PhabricatorNotificationController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$story_type = 'PhabricatorNotificationAdHocFeedStory';
$story_data = array(
'title' => pht(
'This is a test notification, sent at %s.',
phabricator_datetime(time(), $viewer)),
);
$viewer_phid = $viewer->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($viewer_phid)
->setRelatedPHIDs(array($viewer_phid))
->setPrimaryObjectPHID($viewer_phid)
->setSubscribedPHIDs(array($viewer_phid))
->setNotifyAuthor(true)
->publish();
}
return id(new AphrontAjaxResponse());
}
}

View file

@ -0,0 +1,27 @@
<?php
final class PhabricatorNotificationAdHocFeedStory extends PhabricatorFeedStory {
public function getPrimaryObjectPHID() {
return $this->getAuthorPHID();
}
public function renderView() {
$data = $this->getStoryData();
$author_phid = $data->getAuthorPHID();
$view = $this->newStoryView();
$view->setTitle($data->getValue('title'));
$view->setImage($this->getHandle($author_phid)->getImageURI());
return $view;
}
public function renderText() {
$data = $this->getStoryData();
return $data->getValue('title');
}
}