@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+64 -9
+43 -4
src/applications/base/PhabricatorApplication.php
··· 74 74 return empty($uninstalled[get_class($this)]); 75 75 } 76 76 77 - public static function isClassInstalled($class) { 78 - return self::getByClass($class)->isInstalled(); 79 - } 80 - 81 77 public function isBeta() { 82 78 return false; 83 79 } ··· 288 284 289 285 /* -( Application Management )--------------------------------------------- */ 290 286 287 + 291 288 public static function getByClass($class_name) { 292 289 $selected = null; 293 290 $applications = PhabricatorApplication::getAllApplications(); ··· 342 339 } 343 340 344 341 return $apps; 342 + } 343 + 344 + 345 + /** 346 + * Determine if an application is installed, by application class name. 347 + * 348 + * To check if an application is installed //and// available to a particular 349 + * viewer, user @{method:isClassInstalledForViewer}. 350 + * 351 + * @param string Application class name. 352 + * @return bool True if the class is installed. 353 + * @task meta 354 + */ 355 + public static function isClassInstalled($class) { 356 + return self::getByClass($class)->isInstalled(); 357 + } 358 + 359 + 360 + /** 361 + * Determine if an application is installed and available to a viewer, by 362 + * application class name. 363 + * 364 + * To check if an application is installed at all, use 365 + * @{method:isClassInstalled}. 366 + * 367 + * @param string Application class name. 368 + * @param PhabricatorUser Viewing user. 369 + * @return bool True if the class is installed for the viewer. 370 + * @task meta 371 + */ 372 + public static function isClassInstalledForViewer( 373 + $class, 374 + PhabricatorUser $viewer) { 375 + 376 + if (!self::isClassInstalled($class)) { 377 + return false; 378 + } 379 + 380 + return PhabricatorPolicyFilter::hasCapability( 381 + $viewer, 382 + self::getByClass($class), 383 + PhabricatorPolicyCapability::CAN_VIEW); 345 384 } 346 385 347 386
+21 -5
src/applications/home/controller/PhabricatorHomeMainController.php
··· 33 33 34 34 private function buildMainResponse($nav, array $projects) { 35 35 assert_instances_of($projects, 'PhabricatorProject'); 36 + $viewer = $this->getRequest()->getUser(); 36 37 37 - $maniphest = 'PhabricatorApplicationManiphest'; 38 - if (PhabricatorApplication::isClassInstalled($maniphest)) { 38 + $has_maniphest = PhabricatorApplication::isClassInstalledForViewer( 39 + 'PhabricatorApplicationManiphest', 40 + $viewer); 41 + 42 + $has_audit = PhabricatorApplication::isClassInstalledForViewer( 43 + 'PhabricatorApplicationAudit', 44 + $viewer); 45 + 46 + $has_differential = PhabricatorApplication::isClassInstalledForViewer( 47 + 'PhabricatorApplicationDifferential', 48 + $viewer); 49 + 50 + if ($has_maniphest) { 39 51 $unbreak_panel = $this->buildUnbreakNowPanel(); 40 52 $triage_panel = $this->buildNeedsTriagePanel($projects); 41 53 $tasks_panel = $this->buildTasksPanel(); ··· 45 57 $tasks_panel = null; 46 58 } 47 59 48 - $audit = 'PhabricatorApplicationAudit'; 49 - if (PhabricatorApplication::isClassInstalled($audit)) { 60 + if ($has_audit) { 50 61 $audit_panel = $this->buildAuditPanel(); 51 62 $commit_panel = $this->buildCommitPanel(); 52 63 } else { ··· 61 72 } 62 73 63 74 $jump_panel = $this->buildJumpPanel(); 64 - $revision_panel = $this->buildRevisionPanel(); 75 + 76 + if ($has_differential) { 77 + $revision_panel = $this->buildRevisionPanel(); 78 + } else { 79 + $revision_panel = null; 80 + } 65 81 66 82 $content = array( 67 83 $jump_panel,