Page MenuHomePhabricator

D7298.id16428.diff
No OneTemporary

D7298.id16428.diff

Index: src/applications/policy/query/PhabricatorPolicyQuery.php
===================================================================
--- src/applications/policy/query/PhabricatorPolicyQuery.php
+++ src/applications/policy/query/PhabricatorPolicyQuery.php
@@ -1,16 +1,11 @@
<?php
-final class PhabricatorPolicyQuery extends PhabricatorQuery {
+final class PhabricatorPolicyQuery
+ extends PhabricatorCursorPagedPolicyAwareQuery {
- private $viewer;
private $object;
private $phids;
- public function setViewer(PhabricatorUser $viewer) {
- $this->viewer = $viewer;
- return $this;
- }
-
public function setObject(PhabricatorPolicyInterface $object) {
$this->object = $object;
return $this;
@@ -58,11 +53,7 @@
return $policies;
}
- public function execute() {
- if (!$this->viewer) {
- throw new Exception('Call setViewer() before execute()!');
- }
-
+ public function loadPage() {
$phids = $this->phids;
if ($this->object && $this->phids) {
throw new Exception(
@@ -103,7 +94,7 @@
if ($handle_policies) {
$handles = id(new PhabricatorHandleQuery())
- ->setViewer($this->viewer)
+ ->setViewer($this->getViewer())
->withPHIDs($handle_policies)
->execute();
foreach ($handle_policies as $phid) {
@@ -180,11 +171,12 @@
private function loadObjectPolicyPHIDs() {
$phids = array();
+ $viewer = $this->getViewer();
- if ($this->viewer->getPHID()) {
+ if ($viewer->getPHID()) {
$projects = id(new PhabricatorProjectQuery())
- ->setViewer($this->viewer)
- ->withMemberPHIDs(array($this->viewer->getPHID()))
+ ->setViewer($viewer)
+ ->withMemberPHIDs(array($viewer->getPHID()))
->execute();
foreach ($projects as $project) {
$phids[] = $project->getPHID();
@@ -216,5 +208,11 @@
return $phids;
}
+ protected function shouldDisablePolicyFiltering() {
+ // Policy filtering of policies is currently perilous and not required by
+ // the application.
+ return true;
+ }
+
}
Index: src/applications/policy/storage/PhabricatorPolicy.php
===================================================================
--- src/applications/policy/storage/PhabricatorPolicy.php
+++ src/applications/policy/storage/PhabricatorPolicy.php
@@ -1,7 +1,8 @@
<?php
final class PhabricatorPolicy
- extends PhabricatorPolicyDAO {
+ extends PhabricatorPolicyDAO
+ implements PhabricatorPolicyInterface {
const ACTION_ALLOW = 'allow';
const ACTION_DENY = 'deny';
@@ -300,4 +301,29 @@
return $this->assertAttached($this->ruleObjects);
}
+
+/* -( PhabricatorPolicyInterface )----------------------------------------- */
+
+
+ public function getCapabilities() {
+ return array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ );
+ }
+
+ public function getPolicy($capability) {
+ // NOTE: We implement policies only so we can comply with the interface.
+ // The actual query skips them, as enforcing policies on policies seems
+ // perilous and isn't currently required by the application.
+ return PhabricatorPolicies::POLICY_PUBLIC;
+ }
+
+ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
+ return false;
+ }
+
+ public function describeAutomaticCapability($capability) {
+ return null;
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 10, 6:40 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7464294
Default Alt Text
D7298.id16428.diff (3 KB)

Event Timeline