mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 13:22:42 +01:00
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
This commit is contained in:
parent
69eab4196d
commit
b3b0ef3647
2 changed files with 64 additions and 9 deletions
|
@ -74,10 +74,6 @@ abstract class PhabricatorApplication
|
||||||
return empty($uninstalled[get_class($this)]);
|
return empty($uninstalled[get_class($this)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isClassInstalled($class) {
|
|
||||||
return self::getByClass($class)->isInstalled();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isBeta() {
|
public function isBeta() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +284,7 @@ abstract class PhabricatorApplication
|
||||||
|
|
||||||
/* -( Application Management )--------------------------------------------- */
|
/* -( Application Management )--------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
public static function getByClass($class_name) {
|
public static function getByClass($class_name) {
|
||||||
$selected = null;
|
$selected = null;
|
||||||
$applications = PhabricatorApplication::getAllApplications();
|
$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 )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,21 @@ final class PhabricatorHomeMainController
|
||||||
|
|
||||||
private function buildMainResponse($nav, array $projects) {
|
private function buildMainResponse($nav, array $projects) {
|
||||||
assert_instances_of($projects, 'PhabricatorProject');
|
assert_instances_of($projects, 'PhabricatorProject');
|
||||||
|
$viewer = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$maniphest = 'PhabricatorApplicationManiphest';
|
$has_maniphest = PhabricatorApplication::isClassInstalledForViewer(
|
||||||
if (PhabricatorApplication::isClassInstalled($maniphest)) {
|
'PhabricatorApplicationManiphest',
|
||||||
|
$viewer);
|
||||||
|
|
||||||
|
$has_audit = PhabricatorApplication::isClassInstalledForViewer(
|
||||||
|
'PhabricatorApplicationAudit',
|
||||||
|
$viewer);
|
||||||
|
|
||||||
|
$has_differential = PhabricatorApplication::isClassInstalledForViewer(
|
||||||
|
'PhabricatorApplicationDifferential',
|
||||||
|
$viewer);
|
||||||
|
|
||||||
|
if ($has_maniphest) {
|
||||||
$unbreak_panel = $this->buildUnbreakNowPanel();
|
$unbreak_panel = $this->buildUnbreakNowPanel();
|
||||||
$triage_panel = $this->buildNeedsTriagePanel($projects);
|
$triage_panel = $this->buildNeedsTriagePanel($projects);
|
||||||
$tasks_panel = $this->buildTasksPanel();
|
$tasks_panel = $this->buildTasksPanel();
|
||||||
|
@ -45,8 +57,7 @@ final class PhabricatorHomeMainController
|
||||||
$tasks_panel = null;
|
$tasks_panel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$audit = 'PhabricatorApplicationAudit';
|
if ($has_audit) {
|
||||||
if (PhabricatorApplication::isClassInstalled($audit)) {
|
|
||||||
$audit_panel = $this->buildAuditPanel();
|
$audit_panel = $this->buildAuditPanel();
|
||||||
$commit_panel = $this->buildCommitPanel();
|
$commit_panel = $this->buildCommitPanel();
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +72,12 @@ final class PhabricatorHomeMainController
|
||||||
}
|
}
|
||||||
|
|
||||||
$jump_panel = $this->buildJumpPanel();
|
$jump_panel = $this->buildJumpPanel();
|
||||||
$revision_panel = $this->buildRevisionPanel();
|
|
||||||
|
if ($has_differential) {
|
||||||
|
$revision_panel = $this->buildRevisionPanel();
|
||||||
|
} else {
|
||||||
|
$revision_panel = null;
|
||||||
|
}
|
||||||
|
|
||||||
$content = array(
|
$content = array(
|
||||||
$jump_panel,
|
$jump_panel,
|
||||||
|
|
Loading…
Reference in a new issue