mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-22 11:39:03 +01: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:
parent
4041a7e0f6
commit
a7f4103f51
5 changed files with 35 additions and 5 deletions
|
@ -2575,7 +2575,7 @@ phutil_register_library_map(array(
|
|||
'PonderQuestionDetailView' => 'AphrontView',
|
||||
'PonderQuestionEditor' => 'PhabricatorEditor',
|
||||
'PonderQuestionPreviewController' => 'PonderController',
|
||||
'PonderQuestionQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'PonderQuestionQuery' => 'PhabricatorCursorPagedPolicyQuery',
|
||||
'PonderQuestionSummaryView' => 'AphrontView',
|
||||
'PonderQuestionViewController' => 'PonderController',
|
||||
'PonderReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
|
|
|
@ -503,6 +503,7 @@ final class PhabricatorObjectHandleData {
|
|||
break;
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
|
||||
$questions = id(new PonderQuestionQuery())
|
||||
->setViewer($this->viewer)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
$questions = mpull($questions, null, 'getPHID');
|
||||
|
|
|
@ -34,7 +34,8 @@ final class PonderFeedController extends PonderController {
|
|||
$pager->setOffset($request->getStr('offset'));
|
||||
$pager->setURI($request->getRequestURI(), 'offset');
|
||||
|
||||
$query = new PonderQuestionQuery();
|
||||
$query = id(new PonderQuestionQuery())
|
||||
->setViewer($user);
|
||||
|
||||
if ($this->page == 'feed') {
|
||||
$query
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
|
||||
final class PonderQuestionQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
const ORDER_CREATED = 'order-created';
|
||||
const ORDER_HOTTEST = 'order-hottest';
|
||||
|
@ -36,6 +37,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
|
|||
}
|
||||
|
||||
return idx(id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->execute(), $id);
|
||||
}
|
||||
|
@ -47,6 +49,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
|
|||
|
||||
return array_shift(id(new PonderQuestionQuery())
|
||||
->withPHIDs(array($phid))
|
||||
->setViewer($viewer)
|
||||
->execute());
|
||||
}
|
||||
|
||||
|
@ -65,6 +68,8 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
|
|||
$where[] = qsprintf($conn_r, 'q.authorPHID IN (%Ls)', $this->authorPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
@ -79,7 +84,7 @@ final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
|
|||
}
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
public function loadPage() {
|
||||
$question = new PonderQuestion();
|
||||
$conn_r = $question->establishConnection('r');
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ final class PonderQuestion extends PonderDAO
|
|||
implements
|
||||
PhabricatorMarkupInterface,
|
||||
PonderVotableInterface,
|
||||
PhabricatorSubscribableInterface {
|
||||
PhabricatorSubscribableInterface,
|
||||
PhabricatorPolicyInterface {
|
||||
|
||||
const MARKUP_FIELD_CONTENT = 'markup:content';
|
||||
|
||||
|
@ -168,4 +169,26 @@ final class PonderQuestion extends PonderDAO
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue