@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+109 -39
+4 -1
src/__phutil_library_map__.php
··· 1889 1889 'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php', 1890 1890 'PonderMail' => 'applications/ponder/mail/PonderMail.php', 1891 1891 'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php', 1892 + 'PonderPHIDTypeAnswer' => 'applications/ponder/phid/PonderPHIDTypeAnswer.php', 1892 1893 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 1893 1894 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 1894 1895 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', ··· 3984 3985 0 => 'PonderDAO', 3985 3986 1 => 'PhabricatorMarkupInterface', 3986 3987 2 => 'PonderVotableInterface', 3988 + 3 => 'PhabricatorPolicyInterface', 3987 3989 ), 3988 3990 'PonderAnswerEditor' => 'PhabricatorEditor', 3989 3991 'PonderAnswerListView' => 'AphrontView', 3990 3992 'PonderAnswerPreviewController' => 'PonderController', 3991 - 'PonderAnswerQuery' => 'PhabricatorOffsetPagedQuery', 3993 + 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3992 3994 'PonderAnswerSaveController' => 'PonderController', 3993 3995 'PonderAnswerViewController' => 'PonderController', 3994 3996 'PonderAnsweredMail' => 'PonderMail', ··· 4007 4009 'PonderLiterals' => 'PonderConstants', 4008 4010 'PonderMail' => 'PhabricatorMail', 4009 4011 'PonderMentionMail' => 'PonderMail', 4012 + 'PonderPHIDTypeAnswer' => 'PhabricatorPHIDType', 4010 4013 'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType', 4011 4014 'PonderPostBodyView' => 'AphrontView', 4012 4015 'PonderQuestion' =>
-1
src/applications/phid/PhabricatorPHIDConstants.php
··· 12 12 const PHID_TYPE_OASC = 'OASC'; 13 13 const PHID_TYPE_OASA = 'OASA'; 14 14 const PHID_TYPE_TOBJ = 'TOBJ'; 15 - const PHID_TYPE_ANSW = 'ANSW'; 16 15 const PHID_TYPE_ACNT = 'ACNT'; 17 16 const PHID_TYPE_PDCT = 'PDCT'; 18 17 const PHID_TYPE_PRCH = 'PRCH';
+45
src/applications/ponder/phid/PonderPHIDTypeAnswer.php
··· 1 + <?php 2 + 3 + final class PonderPHIDTypeAnswer extends PhabricatorPHIDType { 4 + 5 + const TYPECONST = 'ANSW'; 6 + 7 + public function getTypeConstant() { 8 + return self::TYPECONST; 9 + } 10 + 11 + public function getTypeName() { 12 + return pht('Answer'); 13 + } 14 + 15 + public function newObject() { 16 + return new PonderAnswer(); 17 + } 18 + 19 + public function loadObjects( 20 + PhabricatorObjectQuery $query, 21 + array $phids) { 22 + 23 + return id(new PonderAnswerQuery()) 24 + ->setViewer($query->getViewer()) 25 + ->withPHIDs($phids) 26 + ->execute(); 27 + } 28 + 29 + public function loadHandles( 30 + PhabricatorHandleQuery $query, 31 + array $handles, 32 + array $objects) { 33 + 34 + foreach ($handles as $phid => $handle) { 35 + $answer = $objects[$phid]; 36 + 37 + $id = $answer->getID(); 38 + $qid = $answer->getQuestionID(); 39 + 40 + $handle->setName("Answer {$id}"); 41 + $handle->setURI("/Q{$qid}#A{$id}"); 42 + } 43 + } 44 + 45 + }
+21 -32
src/applications/ponder/query/PonderAnswerQuery.php
··· 1 1 <?php 2 2 3 - final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { 3 + final class PonderAnswerQuery 4 + extends PhabricatorCursorPagedPolicyAwareQuery { 4 5 5 6 private $ids; 6 7 private $phids; 7 8 private $authorPHIDs; 8 9 private $questionIDs; 9 - 10 - private $viewer; 11 - 12 - public function setViewer(PhabricatorUser $viewer) { 13 - $this->viewer = $viewer; 14 - return $this; 15 - } 16 - 17 - public function getViewer() { 18 - return $this->viewer; 19 - } 20 - 21 - public function executeOne() { 22 - return head($this->execute()); 23 - } 24 10 25 11 public function withIDs(array $ids) { 26 12 $this->ids = $ids; ··· 66 52 $this->authorPHIDs); 67 53 } 68 54 69 - return $this->formatWhereClause($where); 70 - } 55 + $where[] = $this->buildPagingClause($conn_r); 71 56 72 - private function buildOrderByClause($conn_r) { 73 - return 'ORDER BY id ASC'; 57 + return $this->formatWhereClause($where); 74 58 } 75 59 76 - public function execute() { 60 + public function loadPage() { 77 61 $answer = new PonderAnswer(); 78 62 $conn_r = $answer->establishConnection('r'); 79 63 ··· 82 66 'SELECT a.* FROM %T a %Q %Q %Q', 83 67 $answer->getTableName(), 84 68 $this->buildWhereClause($conn_r), 85 - $this->buildOrderByClause($conn_r), 69 + $this->buildOrderClause($conn_r), 86 70 $this->buildLimitClause($conn_r)); 87 71 88 - $answers = $answer->loadAllFromArray($data); 72 + return $answer->loadAllFromArray($data); 73 + } 89 74 90 - if ($answers) { 91 - $questions = id(new PonderQuestionQuery()) 92 - ->setViewer($this->getViewer()) 93 - ->withIDs(mpull($answers, 'getQuestionID')) 94 - ->execute(); 75 + public function willFilterPage(array $answers) { 76 + $questions = id(new PonderQuestionQuery()) 77 + ->setViewer($this->getViewer()) 78 + ->withIDs(mpull($answers, 'getQuestionID')) 79 + ->execute(); 95 80 96 - foreach ($answers as $answer) { 97 - $question = idx($questions, $answer->getQuestionID()); 98 - $answer->attachQuestion($question); 99 - } 81 + foreach ($answers as $answer) { 82 + $question = idx($questions, $answer->getQuestionID()); 83 + $answer->attachQuestion($question); 100 84 } 101 85 102 86 return $answers; 103 87 } 88 + 89 + protected function getReversePaging() { 90 + return true; 91 + } 92 + 104 93 }
+37 -3
src/applications/ponder/storage/PonderAnswer.php
··· 1 1 <?php 2 2 3 3 final class PonderAnswer extends PonderDAO 4 - implements PhabricatorMarkupInterface, PonderVotableInterface { 4 + implements 5 + PhabricatorMarkupInterface, 6 + PonderVotableInterface, 7 + PhabricatorPolicyInterface { 5 8 6 9 const MARKUP_FIELD_CONTENT = 'markup:content'; 7 10 8 - protected $phid; 9 11 protected $authorPHID; 10 12 protected $questionID; 11 13 ··· 60 62 61 63 public function generatePHID() { 62 64 return PhabricatorPHID::generateNewPHID( 63 - PhabricatorPHIDConstants::PHID_TYPE_ANSW); 65 + PonderPHIDTypeAnswer::TYPECONST); 64 66 } 65 67 66 68 public function setContentSource(PhabricatorContentSource $content_source) { ··· 111 113 public function getVotablePHID() { 112 114 return $this->getPHID(); 113 115 } 116 + 117 + 118 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 119 + 120 + 121 + public function getCapabilities() { 122 + return array( 123 + PhabricatorPolicyCapability::CAN_VIEW, 124 + PhabricatorPolicyCapability::CAN_EDIT, 125 + ); 126 + } 127 + 128 + public function getPolicy($capability) { 129 + switch ($capability) { 130 + case PhabricatorPolicyCapability::CAN_VIEW: 131 + return $this->getQuestion()->getPolicy($capability); 132 + case PhabricatorPolicyCapability::CAN_EDIT: 133 + return PhabricatorPolicies::POLICY_NOONE; 134 + } 135 + } 136 + 137 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 138 + switch ($capability) { 139 + case PhabricatorPolicyCapability::CAN_VIEW: 140 + return $this->getQuestion()->hasAutomaticCapability( 141 + $capability, 142 + $viewer); 143 + case PhabricatorPolicyCapability::CAN_EDIT: 144 + return ($this->getAuthorPHID() == $viewer->getPHID()); 145 + } 146 + } 147 + 114 148 }
+2 -1
src/applications/ponder/storage/PonderQuestion.php
··· 172 172 public function getCapabilities() { 173 173 return array( 174 174 PhabricatorPolicyCapability::CAN_VIEW, 175 + PhabricatorPolicyCapability::CAN_EDIT, 175 176 ); 176 177 } 177 178 ··· 188 189 } 189 190 190 191 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 191 - return false; 192 + return ($viewer->getPHID() == $this->getAuthorPHID()); 192 193 } 193 194 194 195 /* -( PhabricatorTokenReceiverInterface )---------------------------------- */
-1
src/infrastructure/edges/constants/PhabricatorEdgeConfig.php
··· 155 155 156 156 static $class_map = array( 157 157 PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject', 158 - PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', 159 158 PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount', 160 159 PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase', 161 160 PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',