From 18f856ac6f1fa37b7854924feb1fc30e46875090 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 17 Feb 2014 16:00:33 -0800 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 ++ .../feed/PhabricatorFeedStoryPublisher.php | 20 ++++++++-- .../PhabricatorApplicationNotifications.php | 1 + ...icatorNotificationIndividualController.php | 2 +- ...habricatorNotificationStatusController.php | 17 ++++++++- .../PhabricatorNotificationTestController.php | 38 +++++++++++++++++++ .../PhabricatorNotificationAdHocFeedStory.php | 27 +++++++++++++ 7 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/applications/notification/controller/PhabricatorNotificationTestController.php create mode 100644 src/applications/notification/feed/PhabricatorNotificationAdHocFeedStory.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c4f5a0c54a..d9f65bbdce 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/feed/PhabricatorFeedStoryPublisher.php b/src/applications/feed/PhabricatorFeedStoryPublisher.php index 9448a4f616..509ded6f52 100644 --- a/src/applications/feed/PhabricatorFeedStoryPublisher.php +++ b/src/applications/feed/PhabricatorFeedStoryPublisher.php @@ -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; diff --git a/src/applications/notification/application/PhabricatorApplicationNotifications.php b/src/applications/notification/application/PhabricatorApplicationNotifications.php index b26c54238a..a4925c107d 100644 --- a/src/applications/notification/application/PhabricatorApplicationNotifications.php +++ b/src/applications/notification/application/PhabricatorApplicationNotifications.php @@ -19,6 +19,7 @@ final class PhabricatorApplicationNotifications extends PhabricatorApplication { 'individual/' => 'PhabricatorNotificationIndividualController', 'status/' => 'PhabricatorNotificationStatusController', 'clear/' => 'PhabricatorNotificationClearController', + 'test/' => 'PhabricatorNotificationTestController', ), ); } diff --git a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php index 0186ccd3c1..ee5e7cae25 100644 --- a/src/applications/notification/controller/PhabricatorNotificationIndividualController.php +++ b/src/applications/notification/controller/PhabricatorNotificationIndividualController.php @@ -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); diff --git a/src/applications/notification/controller/PhabricatorNotificationStatusController.php b/src/applications/notification/controller/PhabricatorNotificationStatusController.php index c8fb0b5fd4..03532380fc 100644 --- a/src/applications/notification/controller/PhabricatorNotificationStatusController.php +++ b/src/applications/notification/controller/PhabricatorNotificationStatusController.php @@ -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; diff --git a/src/applications/notification/controller/PhabricatorNotificationTestController.php b/src/applications/notification/controller/PhabricatorNotificationTestController.php new file mode 100644 index 0000000000..d63154ad5d --- /dev/null +++ b/src/applications/notification/controller/PhabricatorNotificationTestController.php @@ -0,0 +1,38 @@ +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()); + } + +} diff --git a/src/applications/notification/feed/PhabricatorNotificationAdHocFeedStory.php b/src/applications/notification/feed/PhabricatorNotificationAdHocFeedStory.php new file mode 100644 index 0000000000..286b81f01f --- /dev/null +++ b/src/applications/notification/feed/PhabricatorNotificationAdHocFeedStory.php @@ -0,0 +1,27 @@ +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'); + } + +}