diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e4e76d0dd2..8ac1f5298e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1889,6 +1889,7 @@ phutil_register_library_map(array( 'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php', 'PonderMail' => 'applications/ponder/mail/PonderMail.php', 'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php', + 'PonderPHIDTypeAnswer' => 'applications/ponder/phid/PonderPHIDTypeAnswer.php', 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', @@ -3984,11 +3985,12 @@ phutil_register_library_map(array( 0 => 'PonderDAO', 1 => 'PhabricatorMarkupInterface', 2 => 'PonderVotableInterface', + 3 => 'PhabricatorPolicyInterface', ), 'PonderAnswerEditor' => 'PhabricatorEditor', 'PonderAnswerListView' => 'AphrontView', 'PonderAnswerPreviewController' => 'PonderController', - 'PonderAnswerQuery' => 'PhabricatorOffsetPagedQuery', + 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PonderAnswerSaveController' => 'PonderController', 'PonderAnswerViewController' => 'PonderController', 'PonderAnsweredMail' => 'PonderMail', @@ -4007,6 +4009,7 @@ phutil_register_library_map(array( 'PonderLiterals' => 'PonderConstants', 'PonderMail' => 'PhabricatorMail', 'PonderMentionMail' => 'PonderMail', + 'PonderPHIDTypeAnswer' => 'PhabricatorPHIDType', 'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType', 'PonderPostBodyView' => 'AphrontView', 'PonderQuestion' => diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index f9a7dbf709..3d27c5c7da 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -12,7 +12,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_OASC = 'OASC'; const PHID_TYPE_OASA = 'OASA'; const PHID_TYPE_TOBJ = 'TOBJ'; - const PHID_TYPE_ANSW = 'ANSW'; const PHID_TYPE_ACNT = 'ACNT'; const PHID_TYPE_PDCT = 'PDCT'; const PHID_TYPE_PRCH = 'PRCH'; diff --git a/src/applications/ponder/phid/PonderPHIDTypeAnswer.php b/src/applications/ponder/phid/PonderPHIDTypeAnswer.php new file mode 100644 index 0000000000..388677e156 --- /dev/null +++ b/src/applications/ponder/phid/PonderPHIDTypeAnswer.php @@ -0,0 +1,45 @@ +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}"); + } + } + +} diff --git a/src/applications/ponder/query/PonderAnswerQuery.php b/src/applications/ponder/query/PonderAnswerQuery.php index ed0c6f926f..4254682100 100644 --- a/src/applications/ponder/query/PonderAnswerQuery.php +++ b/src/applications/ponder/query/PonderAnswerQuery.php @@ -1,27 +1,13 @@ viewer = $viewer; - return $this; - } - - public function getViewer() { - return $this->viewer; - } - - public function executeOne() { - return head($this->execute()); - } - public function withIDs(array $ids) { $this->ids = $ids; return $this; @@ -66,14 +52,12 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { $this->authorPHIDs); } + $where[] = $this->buildPagingClause($conn_r); + return $this->formatWhereClause($where); } - private function buildOrderByClause($conn_r) { - return 'ORDER BY id ASC'; - } - - public function execute() { + public function loadPage() { $answer = new PonderAnswer(); $conn_r = $answer->establishConnection('r'); @@ -82,23 +66,28 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { 'SELECT a.* FROM %T a %Q %Q %Q', $answer->getTableName(), $this->buildWhereClause($conn_r), - $this->buildOrderByClause($conn_r), + $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); - $answers = $answer->loadAllFromArray($data); + return $answer->loadAllFromArray($data); + } - if ($answers) { - $questions = id(new PonderQuestionQuery()) - ->setViewer($this->getViewer()) - ->withIDs(mpull($answers, 'getQuestionID')) - ->execute(); + public function willFilterPage(array $answers) { + $questions = id(new PonderQuestionQuery()) + ->setViewer($this->getViewer()) + ->withIDs(mpull($answers, 'getQuestionID')) + ->execute(); - foreach ($answers as $answer) { - $question = idx($questions, $answer->getQuestionID()); - $answer->attachQuestion($question); - } + foreach ($answers as $answer) { + $question = idx($questions, $answer->getQuestionID()); + $answer->attachQuestion($question); } return $answers; } + + protected function getReversePaging() { + return true; + } + } diff --git a/src/applications/ponder/storage/PonderAnswer.php b/src/applications/ponder/storage/PonderAnswer.php index ba6b1f24da..a825723e34 100644 --- a/src/applications/ponder/storage/PonderAnswer.php +++ b/src/applications/ponder/storage/PonderAnswer.php @@ -1,11 +1,13 @@ 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()); + } + } + } diff --git a/src/applications/ponder/storage/PonderQuestion.php b/src/applications/ponder/storage/PonderQuestion.php index b473a2c335..ebaaf18158 100644 --- a/src/applications/ponder/storage/PonderQuestion.php +++ b/src/applications/ponder/storage/PonderQuestion.php @@ -172,6 +172,7 @@ final class PonderQuestion extends PonderDAO public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, ); } @@ -188,7 +189,7 @@ final class PonderQuestion extends PonderDAO } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { - return false; + return ($viewer->getPHID() == $this->getAuthorPHID()); } /* -( PhabricatorTokenReceiverInterface )---------------------------------- */ diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index f63c5cf960..ce6a86db55 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -155,7 +155,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { static $class_map = array( PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject', - PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount', PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase', PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',