Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php
| Show All 29 Lines | abstract class PhabricatorPolicyAwareQuery extends PhabricatorOffsetPagedQuery { | ||||
| private $viewer; | private $viewer; | ||||
| private $parentQuery; | private $parentQuery; | ||||
| private $rawResultLimit; | private $rawResultLimit; | ||||
| private $capabilities; | private $capabilities; | ||||
| private $workspace = array(); | private $workspace = array(); | ||||
| private $inFlightPHIDs = array(); | private $inFlightPHIDs = array(); | ||||
| private $policyFilteredPHIDs = array(); | private $policyFilteredPHIDs = array(); | ||||
| private $canUseApplication; | |||||
| /** | /** | ||||
| * Should we continue or throw an exception when a query result is filtered | * Should we continue or throw an exception when a query result is filtered | ||||
| * by policy rules? | * by policy rules? | ||||
| * | * | ||||
| * Values are `true` (raise exceptions), `false` (do not raise exceptions) | * Values are `true` (raise exceptions), `false` (do not raise exceptions) | ||||
| * and `null` (inherit from parent query, with no exceptions by default). | * and `null` (inherit from parent query, with no exceptions by default). | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 627 Lines • ▼ Show 20 Lines | /* -( Policy Query Implementation )---------------------------------------- */ | ||||
| * Determine if the viewer has permission to use this query's application. | * Determine if the viewer has permission to use this query's application. | ||||
| * For queries which aren't part of an application, this method always returns | * For queries which aren't part of an application, this method always returns | ||||
| * true. | * true. | ||||
| * | * | ||||
| * @return bool True if the viewer has application-level permission to | * @return bool True if the viewer has application-level permission to | ||||
| * execute the query. | * execute the query. | ||||
| */ | */ | ||||
| public function canViewerUseQueryApplication() { | public function canViewerUseQueryApplication() { | ||||
| if ($this->canUseApplication === null) { | |||||
| $class = $this->getQueryApplicationClass(); | $class = $this->getQueryApplicationClass(); | ||||
| if (!$class) { | if (!$class) { | ||||
| $this->canUseApplication = true; | return true; | ||||
| } else { | |||||
| $result = id(new PhabricatorApplicationQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withClasses(array($class)) | |||||
| ->execute(); | |||||
| $this->canUseApplication = (bool)$result; | |||||
| } | |||||
| } | } | ||||
| return $this->canUseApplication; | $viewer = $this->getViewer(); | ||||
| return PhabricatorApplication::isClassInstalledForViewer($class, $viewer); | |||||
| } | } | ||||
| } | } | ||||