From b3b0ef3647e8e85dc5249994f3fa549961c54e41 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 15 Mar 2014 11:28:02 -0700 Subject: [PATCH] Use viwer-based checks for application visibility when rendering home elements Summary: Fixes T4619. Currently, even if a viewer can't see Maniphest, they'll still see empty panels on the home page. These panels will always be empty so there's no real policy violation, but it's confusing. Longer term, dashboards should fix this. Test Plan: Viewed home page with a user with and without permissions on the apps. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4619 Differential Revision: https://secure.phabricator.com/D8545 --- .../base/PhabricatorApplication.php | 47 +++++++++++++++++-- .../PhabricatorHomeMainController.php | 26 ++++++++-- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/applications/base/PhabricatorApplication.php b/src/applications/base/PhabricatorApplication.php index c3f1ff2438..bed89ed741 100644 --- a/src/applications/base/PhabricatorApplication.php +++ b/src/applications/base/PhabricatorApplication.php @@ -74,10 +74,6 @@ abstract class PhabricatorApplication return empty($uninstalled[get_class($this)]); } - public static function isClassInstalled($class) { - return self::getByClass($class)->isInstalled(); - } - public function isBeta() { return false; } @@ -288,6 +284,7 @@ abstract class PhabricatorApplication /* -( Application Management )--------------------------------------------- */ + public static function getByClass($class_name) { $selected = null; $applications = PhabricatorApplication::getAllApplications(); @@ -345,6 +342,48 @@ abstract class PhabricatorApplication } + /** + * Determine if an application is installed, by application class name. + * + * To check if an application is installed //and// available to a particular + * viewer, user @{method:isClassInstalledForViewer}. + * + * @param string Application class name. + * @return bool True if the class is installed. + * @task meta + */ + public static function isClassInstalled($class) { + return self::getByClass($class)->isInstalled(); + } + + + /** + * Determine if an application is installed and available to a viewer, by + * application class name. + * + * To check if an application is installed at all, use + * @{method:isClassInstalled}. + * + * @param string Application class name. + * @param PhabricatorUser Viewing user. + * @return bool True if the class is installed for the viewer. + * @task meta + */ + public static function isClassInstalledForViewer( + $class, + PhabricatorUser $viewer) { + + if (!self::isClassInstalled($class)) { + return false; + } + + return PhabricatorPolicyFilter::hasCapability( + $viewer, + self::getByClass($class), + PhabricatorPolicyCapability::CAN_VIEW); + } + + /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/home/controller/PhabricatorHomeMainController.php b/src/applications/home/controller/PhabricatorHomeMainController.php index 488d73da66..057f68f47b 100644 --- a/src/applications/home/controller/PhabricatorHomeMainController.php +++ b/src/applications/home/controller/PhabricatorHomeMainController.php @@ -33,9 +33,21 @@ final class PhabricatorHomeMainController private function buildMainResponse($nav, array $projects) { assert_instances_of($projects, 'PhabricatorProject'); + $viewer = $this->getRequest()->getUser(); - $maniphest = 'PhabricatorApplicationManiphest'; - if (PhabricatorApplication::isClassInstalled($maniphest)) { + $has_maniphest = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorApplicationManiphest', + $viewer); + + $has_audit = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorApplicationAudit', + $viewer); + + $has_differential = PhabricatorApplication::isClassInstalledForViewer( + 'PhabricatorApplicationDifferential', + $viewer); + + if ($has_maniphest) { $unbreak_panel = $this->buildUnbreakNowPanel(); $triage_panel = $this->buildNeedsTriagePanel($projects); $tasks_panel = $this->buildTasksPanel(); @@ -45,8 +57,7 @@ final class PhabricatorHomeMainController $tasks_panel = null; } - $audit = 'PhabricatorApplicationAudit'; - if (PhabricatorApplication::isClassInstalled($audit)) { + if ($has_audit) { $audit_panel = $this->buildAuditPanel(); $commit_panel = $this->buildCommitPanel(); } else { @@ -61,7 +72,12 @@ final class PhabricatorHomeMainController } $jump_panel = $this->buildJumpPanel(); - $revision_panel = $this->buildRevisionPanel(); + + if ($has_differential) { + $revision_panel = $this->buildRevisionPanel(); + } else { + $revision_panel = null; + } $content = array( $jump_panel, -- 2.54.0