mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-22 20:51:10 +01:00
Use Application PHIDs for ANSW
Summary: Ref T2715. Ref T3578. - Use Application PHIDs for Ponder Answers. - Make Ponder answers policy-aware. - Make PonderAnswerQuery policy-aware. Test Plan: Used `phid.query`; browsed Ponder. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715, T3578 Differential Revision: https://secure.phabricator.com/D6582
This commit is contained in:
parent
f98ca03d7d
commit
ce16369f8e
7 changed files with 109 additions and 39 deletions
|
@ -1889,6 +1889,7 @@ phutil_register_library_map(array(
|
||||||
'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php',
|
'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php',
|
||||||
'PonderMail' => 'applications/ponder/mail/PonderMail.php',
|
'PonderMail' => 'applications/ponder/mail/PonderMail.php',
|
||||||
'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php',
|
'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php',
|
||||||
|
'PonderPHIDTypeAnswer' => 'applications/ponder/phid/PonderPHIDTypeAnswer.php',
|
||||||
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
|
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
|
||||||
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
|
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
|
||||||
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
||||||
|
@ -3984,11 +3985,12 @@ phutil_register_library_map(array(
|
||||||
0 => 'PonderDAO',
|
0 => 'PonderDAO',
|
||||||
1 => 'PhabricatorMarkupInterface',
|
1 => 'PhabricatorMarkupInterface',
|
||||||
2 => 'PonderVotableInterface',
|
2 => 'PonderVotableInterface',
|
||||||
|
3 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
'PonderAnswerEditor' => 'PhabricatorEditor',
|
'PonderAnswerEditor' => 'PhabricatorEditor',
|
||||||
'PonderAnswerListView' => 'AphrontView',
|
'PonderAnswerListView' => 'AphrontView',
|
||||||
'PonderAnswerPreviewController' => 'PonderController',
|
'PonderAnswerPreviewController' => 'PonderController',
|
||||||
'PonderAnswerQuery' => 'PhabricatorOffsetPagedQuery',
|
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PonderAnswerSaveController' => 'PonderController',
|
'PonderAnswerSaveController' => 'PonderController',
|
||||||
'PonderAnswerViewController' => 'PonderController',
|
'PonderAnswerViewController' => 'PonderController',
|
||||||
'PonderAnsweredMail' => 'PonderMail',
|
'PonderAnsweredMail' => 'PonderMail',
|
||||||
|
@ -4007,6 +4009,7 @@ phutil_register_library_map(array(
|
||||||
'PonderLiterals' => 'PonderConstants',
|
'PonderLiterals' => 'PonderConstants',
|
||||||
'PonderMail' => 'PhabricatorMail',
|
'PonderMail' => 'PhabricatorMail',
|
||||||
'PonderMentionMail' => 'PonderMail',
|
'PonderMentionMail' => 'PonderMail',
|
||||||
|
'PonderPHIDTypeAnswer' => 'PhabricatorPHIDType',
|
||||||
'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType',
|
'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType',
|
||||||
'PonderPostBodyView' => 'AphrontView',
|
'PonderPostBodyView' => 'AphrontView',
|
||||||
'PonderQuestion' =>
|
'PonderQuestion' =>
|
||||||
|
|
|
@ -12,7 +12,6 @@ final class PhabricatorPHIDConstants {
|
||||||
const PHID_TYPE_OASC = 'OASC';
|
const PHID_TYPE_OASC = 'OASC';
|
||||||
const PHID_TYPE_OASA = 'OASA';
|
const PHID_TYPE_OASA = 'OASA';
|
||||||
const PHID_TYPE_TOBJ = 'TOBJ';
|
const PHID_TYPE_TOBJ = 'TOBJ';
|
||||||
const PHID_TYPE_ANSW = 'ANSW';
|
|
||||||
const PHID_TYPE_ACNT = 'ACNT';
|
const PHID_TYPE_ACNT = 'ACNT';
|
||||||
const PHID_TYPE_PDCT = 'PDCT';
|
const PHID_TYPE_PDCT = 'PDCT';
|
||||||
const PHID_TYPE_PRCH = 'PRCH';
|
const PHID_TYPE_PRCH = 'PRCH';
|
||||||
|
|
45
src/applications/ponder/phid/PonderPHIDTypeAnswer.php
Normal file
45
src/applications/ponder/phid/PonderPHIDTypeAnswer.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PonderPHIDTypeAnswer extends PhabricatorPHIDType {
|
||||||
|
|
||||||
|
const TYPECONST = 'ANSW';
|
||||||
|
|
||||||
|
public function getTypeConstant() {
|
||||||
|
return self::TYPECONST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTypeName() {
|
||||||
|
return pht('Answer');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function newObject() {
|
||||||
|
return new PonderAnswer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadObjects(
|
||||||
|
PhabricatorObjectQuery $query,
|
||||||
|
array $phids) {
|
||||||
|
|
||||||
|
return id(new PonderAnswerQuery())
|
||||||
|
->setViewer($query->getViewer())
|
||||||
|
->withPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadHandles(
|
||||||
|
PhabricatorHandleQuery $query,
|
||||||
|
array $handles,
|
||||||
|
array $objects) {
|
||||||
|
|
||||||
|
foreach ($handles as $phid => $handle) {
|
||||||
|
$answer = $objects[$phid];
|
||||||
|
|
||||||
|
$id = $answer->getID();
|
||||||
|
$qid = $answer->getQuestionID();
|
||||||
|
|
||||||
|
$handle->setName("Answer {$id}");
|
||||||
|
$handle->setURI("/Q{$qid}#A{$id}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,27 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery {
|
final class PonderAnswerQuery
|
||||||
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $authorPHIDs;
|
private $authorPHIDs;
|
||||||
private $questionIDs;
|
private $questionIDs;
|
||||||
|
|
||||||
private $viewer;
|
|
||||||
|
|
||||||
public function setViewer(PhabricatorUser $viewer) {
|
|
||||||
$this->viewer = $viewer;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getViewer() {
|
|
||||||
return $this->viewer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function executeOne() {
|
|
||||||
return head($this->execute());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -66,14 +52,12 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery {
|
||||||
$this->authorPHIDs);
|
$this->authorPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildOrderByClause($conn_r) {
|
public function loadPage() {
|
||||||
return 'ORDER BY id ASC';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute() {
|
|
||||||
$answer = new PonderAnswer();
|
$answer = new PonderAnswer();
|
||||||
$conn_r = $answer->establishConnection('r');
|
$conn_r = $answer->establishConnection('r');
|
||||||
|
|
||||||
|
@ -82,12 +66,13 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery {
|
||||||
'SELECT a.* FROM %T a %Q %Q %Q',
|
'SELECT a.* FROM %T a %Q %Q %Q',
|
||||||
$answer->getTableName(),
|
$answer->getTableName(),
|
||||||
$this->buildWhereClause($conn_r),
|
$this->buildWhereClause($conn_r),
|
||||||
$this->buildOrderByClause($conn_r),
|
$this->buildOrderClause($conn_r),
|
||||||
$this->buildLimitClause($conn_r));
|
$this->buildLimitClause($conn_r));
|
||||||
|
|
||||||
$answers = $answer->loadAllFromArray($data);
|
return $answer->loadAllFromArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
if ($answers) {
|
public function willFilterPage(array $answers) {
|
||||||
$questions = id(new PonderQuestionQuery())
|
$questions = id(new PonderQuestionQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withIDs(mpull($answers, 'getQuestionID'))
|
->withIDs(mpull($answers, 'getQuestionID'))
|
||||||
|
@ -97,8 +82,12 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery {
|
||||||
$question = idx($questions, $answer->getQuestionID());
|
$question = idx($questions, $answer->getQuestionID());
|
||||||
$answer->attachQuestion($question);
|
$answer->attachQuestion($question);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $answers;
|
return $answers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getReversePaging() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PonderAnswer extends PonderDAO
|
final class PonderAnswer extends PonderDAO
|
||||||
implements PhabricatorMarkupInterface, PonderVotableInterface {
|
implements
|
||||||
|
PhabricatorMarkupInterface,
|
||||||
|
PonderVotableInterface,
|
||||||
|
PhabricatorPolicyInterface {
|
||||||
|
|
||||||
const MARKUP_FIELD_CONTENT = 'markup:content';
|
const MARKUP_FIELD_CONTENT = 'markup:content';
|
||||||
|
|
||||||
protected $phid;
|
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $questionID;
|
protected $questionID;
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ final class PonderAnswer extends PonderDAO
|
||||||
|
|
||||||
public function generatePHID() {
|
public function generatePHID() {
|
||||||
return PhabricatorPHID::generateNewPHID(
|
return PhabricatorPHID::generateNewPHID(
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_ANSW);
|
PonderPHIDTypeAnswer::TYPECONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setContentSource(PhabricatorContentSource $content_source) {
|
public function setContentSource(PhabricatorContentSource $content_source) {
|
||||||
|
@ -111,4 +113,36 @@ final class PonderAnswer extends PonderDAO
|
||||||
public function getVotablePHID() {
|
public function getVotablePHID() {
|
||||||
return $this->getPHID();
|
return $this->getPHID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
public function getCapabilities() {
|
||||||
|
return array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPolicy($capability) {
|
||||||
|
switch ($capability) {
|
||||||
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
return $this->getQuestion()->getPolicy($capability);
|
||||||
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||||
|
return PhabricatorPolicies::POLICY_NOONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||||
|
switch ($capability) {
|
||||||
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
||||||
|
return $this->getQuestion()->hasAutomaticCapability(
|
||||||
|
$capability,
|
||||||
|
$viewer);
|
||||||
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
||||||
|
return ($this->getAuthorPHID() == $viewer->getPHID());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,7 @@ final class PonderQuestion extends PonderDAO
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
return array(
|
return array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +189,7 @@ final class PonderQuestion extends PonderDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
||||||
return false;
|
return ($viewer->getPHID() == $this->getAuthorPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
||||||
|
|
|
@ -155,7 +155,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
||||||
|
|
||||||
static $class_map = array(
|
static $class_map = array(
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',
|
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer',
|
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',
|
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase',
|
PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',
|
PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',
|
||||||
|
|
Loading…
Reference in a new issue