1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00

make PonderQuestionQuery policy aware

Summary: wanted to play with some policy stuff as its been a bit. Turns out you can't edit questions so this is very silly "so long as you are a user you can view it" policy. also sorry if you have a diff or twelve out for this in your sandbox(es).

Test Plan: loaded up ponder and clicked about

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2113

Differential Revision: https://secure.phabricator.com/D4163
This commit is contained in:
Bob Trahan 2012-12-11 18:03:16 -08:00
parent 4041a7e0f6
commit a7f4103f51
5 changed files with 35 additions and 5 deletions

View file

@ -2575,7 +2575,7 @@ phutil_register_library_map(array(
'PonderQuestionDetailView' => 'AphrontView', 'PonderQuestionDetailView' => 'AphrontView',
'PonderQuestionEditor' => 'PhabricatorEditor', 'PonderQuestionEditor' => 'PhabricatorEditor',
'PonderQuestionPreviewController' => 'PonderController', 'PonderQuestionPreviewController' => 'PonderController',
'PonderQuestionQuery' => 'PhabricatorOffsetPagedQuery', 'PonderQuestionQuery' => 'PhabricatorCursorPagedPolicyQuery',
'PonderQuestionSummaryView' => 'AphrontView', 'PonderQuestionSummaryView' => 'AphrontView',
'PonderQuestionViewController' => 'PonderController', 'PonderQuestionViewController' => 'PonderController',
'PonderReplyHandler' => 'PhabricatorMailReplyHandler', 'PonderReplyHandler' => 'PhabricatorMailReplyHandler',

View file

@ -503,6 +503,7 @@ final class PhabricatorObjectHandleData {
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES: case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery()) $questions = id(new PonderQuestionQuery())
->setViewer($this->viewer)
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
$questions = mpull($questions, null, 'getPHID'); $questions = mpull($questions, null, 'getPHID');

View file

@ -34,7 +34,8 @@ final class PonderFeedController extends PonderController {
$pager->setOffset($request->getStr('offset')); $pager->setOffset($request->getStr('offset'));
$pager->setURI($request->getRequestURI(), 'offset'); $pager->setURI($request->getRequestURI(), 'offset');
$query = new PonderQuestionQuery(); $query = id(new PonderQuestionQuery())
->setViewer($user);
if ($this->page == 'feed') { if ($this->page == 'feed') {
$query $query

View file

@ -1,6 +1,7 @@
<?php <?php
final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery { final class PonderQuestionQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
const ORDER_CREATED = 'order-created'; const ORDER_CREATED = 'order-created';
const ORDER_HOTTEST = 'order-hottest'; const ORDER_HOTTEST = 'order-hottest';
@ -36,6 +37,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
} }
return idx(id(new PonderQuestionQuery()) return idx(id(new PonderQuestionQuery())
->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->execute(), $id); ->execute(), $id);
} }
@ -47,6 +49,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
return array_shift(id(new PonderQuestionQuery()) return array_shift(id(new PonderQuestionQuery())
->withPHIDs(array($phid)) ->withPHIDs(array($phid))
->setViewer($viewer)
->execute()); ->execute());
} }
@ -65,6 +68,8 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
$where[] = qsprintf($conn_r, 'q.authorPHID IN (%Ls)', $this->authorPHIDs); $where[] = qsprintf($conn_r, 'q.authorPHID IN (%Ls)', $this->authorPHIDs);
} }
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where); return $this->formatWhereClause($where);
} }
@ -79,7 +84,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
} }
} }
public function execute() { public function loadPage() {
$question = new PonderQuestion(); $question = new PonderQuestion();
$conn_r = $question->establishConnection('r'); $conn_r = $question->establishConnection('r');

View file

@ -4,7 +4,8 @@ final class PonderQuestion extends PonderDAO
implements implements
PhabricatorMarkupInterface, PhabricatorMarkupInterface,
PonderVotableInterface, PonderVotableInterface,
PhabricatorSubscribableInterface { PhabricatorSubscribableInterface,
PhabricatorPolicyInterface {
const MARKUP_FIELD_CONTENT = 'markup:content'; const MARKUP_FIELD_CONTENT = 'markup:content';
@ -168,4 +169,26 @@ final class PonderQuestion extends PonderDAO
return parent::save(); return parent::save();
} }
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
$policy = PhabricatorPolicies::POLICY_NOONE;
switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW:
$policy = PhabricatorPolicies::POLICY_USER;
break;
}
return $policy;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
} }