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,