mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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',
|
'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',
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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');
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue