From b21cd24341c6552a3fbd21305ca682a161129a6b Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 18 Jan 2017 06:05:25 -0800 Subject: [PATCH] When Favorites is uninstalled or not visible to the viewer, hide the menu Summary: Ref T5867. The `executeOne()` currently raises a policy exception if the application isn't visible to the viewer, or we fatal if the application has been uninstalled. Test Plan: - Viewed pages with the application uninstalled, saw working pages with no favorites menu. - Viewed pages with the application restricted, saw working pages with no favorites menu. Reviewers: chad Reviewed By: chad Maniphest Tasks: T5867 Differential Revision: https://secure.phabricator.com/D17219 --- .../PhabricatorFavoritesApplication.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/applications/favorites/application/PhabricatorFavoritesApplication.php b/src/applications/favorites/application/PhabricatorFavoritesApplication.php index 842d2e33b0..958355a2b5 100644 --- a/src/applications/favorites/application/PhabricatorFavoritesApplication.php +++ b/src/applications/favorites/application/PhabricatorFavoritesApplication.php @@ -36,6 +36,11 @@ final class PhabricatorFavoritesApplication extends PhabricatorApplication { PhabricatorUser $viewer, PhabricatorController $controller = null) { + $dropdown = $this->renderFavoritesDropdown($viewer); + if (!$dropdown) { + return null; + } + return id(new PHUIButtonView()) ->setTag('a') ->setHref('#') @@ -43,17 +48,21 @@ final class PhabricatorFavoritesApplication extends PhabricatorApplication { ->addClass('phabricator-core-user-menu') ->setNoCSS(true) ->setDropdown(true) - ->setDropdownMenu($this->renderFavoritesDropdown($viewer)); + ->setDropdownMenu($dropdown); } private function renderFavoritesDropdown(PhabricatorUser $viewer) { - $application = __CLASS__; - $favorites = id(new PhabricatorApplicationQuery()) + + $applications = id(new PhabricatorApplicationQuery()) ->setViewer($viewer) ->withClasses(array($application)) ->withInstalled(true) - ->executeOne(); + ->execute(); + $favorites = head($applications); + if (!$favorites) { + return null; + } $menu_engine = id(new PhabricatorFavoritesProfileMenuEngine()) ->setViewer($viewer)