mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +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)]);
|
||||
}
|
||||
|
||||
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 )----------------------------------------- */
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue