@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.

Add Edit/View Policy to Ponder Questions

Summary: Ref T3578, adds ability to set a default edit and view policy for questions. Not sure what to set viewPolicy to ?

Test Plan: Test an old question, edit policy still on myself. Test a new question, see new default.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T3578

Differential Revision: https://secure.phabricator.com/D13791

+121 -18
+5
resources/sql/autopatches/20150804.ponder.question.1.sql
··· 1 + ALTER TABLE {$NAMESPACE}_ponder.ponder_question 2 + ADD editPolicy VARBINARY(64) NOT NULL; 3 + 4 + ALTER TABLE {$NAMESPACE}_ponder.ponder_question 5 + ADD viewPolicy VARBINARY(64) NOT NULL;
+2
resources/sql/autopatches/20150804.ponder.question.2.sql
··· 1 + UPDATE {$NAMESPACE}_ponder.ponder_question 2 + SET editPolicy = authorPHID WHERE editPolicy = '';
+2
resources/sql/autopatches/20150804.ponder.question.3.sql
··· 1 + UPDATE {$NAMESPACE}_ponder.ponder_question 2 + SET viewPolicy = 'users' WHERE viewPolicy = '';
+4
src/__phutil_library_map__.php
··· 3399 3399 'PonderEditor' => 'applications/ponder/editor/PonderEditor.php', 3400 3400 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 3401 3401 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', 3402 + 'PonderQuestionDefaultEditCapability' => 'applications/ponder/capability/PonderQuestionDefaultEditCapability.php', 3403 + 'PonderQuestionDefaultViewCapability' => 'applications/ponder/capability/PonderQuestionDefaultViewCapability.php', 3402 3404 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', 3403 3405 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', 3404 3406 'PonderQuestionHasVotingUserEdgeType' => 'applications/ponder/edge/PonderQuestionHasVotingUserEdgeType.php', ··· 7590 7592 'PhabricatorDestructibleInterface', 7591 7593 ), 7592 7594 'PonderQuestionCommentController' => 'PonderController', 7595 + 'PonderQuestionDefaultEditCapability' => 'PhabricatorPolicyCapability', 7596 + 'PonderQuestionDefaultViewCapability' => 'PhabricatorPolicyCapability', 7593 7597 'PonderQuestionEditController' => 'PonderController', 7594 7598 'PonderQuestionEditor' => 'PonderEditor', 7595 7599 'PonderQuestionHasVotingUserEdgeType' => 'PhabricatorEdgeType',
+13
src/applications/ponder/application/PhabricatorPonderApplication.php
··· 91 91 ); 92 92 } 93 93 94 + protected function getCustomCapabilities() { 95 + return array( 96 + PonderQuestionDefaultViewCapability::CAPABILITY => array( 97 + 'template' => PonderQuestionPHIDType::TYPECONST, 98 + 'capability' => PhabricatorPolicyCapability::CAN_VIEW, 99 + ), 100 + PonderQuestionDefaultEditCapability::CAPABILITY => array( 101 + 'template' => PonderQuestionPHIDType::TYPECONST, 102 + 'capability' => PhabricatorPolicyCapability::CAN_EDIT, 103 + ), 104 + ); 105 + } 106 + 94 107 public function getApplicationSearchDocumentTypes() { 95 108 return array( 96 109 PonderQuestionPHIDType::TYPECONST,
+12
src/applications/ponder/capability/PonderQuestionDefaultEditCapability.php
··· 1 + <?php 2 + 3 + final class PonderQuestionDefaultEditCapability 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'ponder.question.default.edit'; 7 + 8 + public function getCapabilityName() { 9 + return pht('Default Question Edit Policy'); 10 + } 11 + 12 + }
+16
src/applications/ponder/capability/PonderQuestionDefaultViewCapability.php
··· 1 + <?php 2 + 3 + final class PonderQuestionDefaultViewCapability 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'ponder.question.default.view'; 7 + 8 + public function getCapabilityName() { 9 + return pht('Default Question View Policy'); 10 + } 11 + 12 + public function shouldAllowPublicPolicySetting() { 13 + return true; 14 + } 15 + 16 + }
+38 -12
src/applications/ponder/controller/PonderQuestionEditController.php
··· 3 3 final class PonderQuestionEditController extends PonderController { 4 4 5 5 public function handleRequest(AphrontRequest $request) { 6 - $user = $request->getViewer(); 6 + $viewer = $request->getViewer(); 7 7 $id = $request->getURIData('id'); 8 8 9 9 if ($id) { 10 10 $question = id(new PonderQuestionQuery()) 11 - ->setViewer($user) 11 + ->setViewer($viewer) 12 12 ->withIDs(array($id)) 13 13 ->requireCapabilities( 14 14 array( ··· 24 24 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 25 25 $v_projects = array_reverse($v_projects); 26 26 } else { 27 - $question = id(new PonderQuestion()) 28 - ->setStatus(PonderQuestionStatus::STATUS_OPEN) 29 - ->setAuthorPHID($user->getPHID()) 30 - ->setVoteCount(0) 31 - ->setAnswerCount(0) 32 - ->setHeat(0.0); 27 + $question = PonderQuestion::initializeNewQuestion($viewer); 33 28 $v_projects = array(); 34 29 } 35 30 36 31 $v_title = $question->getTitle(); 37 32 $v_content = $question->getContent(); 33 + $v_view = $question->getViewPolicy(); 34 + $v_edit = $question->getEditPolicy(); 38 35 39 36 $errors = array(); 40 37 $e_title = true; ··· 42 39 $v_title = $request->getStr('title'); 43 40 $v_content = $request->getStr('content'); 44 41 $v_projects = $request->getArr('projects'); 42 + $v_view = $request->getStr('viewPolicy'); 43 + $v_edit = $request->getStr('editPolicy'); 45 44 46 45 $len = phutil_utf8_strlen($v_title); 47 46 if ($len < 1) { ··· 64 63 ->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT) 65 64 ->setNewValue($v_content); 66 65 66 + $xactions[] = id(clone $template) 67 + ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 68 + ->setNewValue($v_view); 69 + 70 + $xactions[] = id(clone $template) 71 + ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 72 + ->setNewValue($v_edit); 73 + 67 74 $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; 68 75 $xactions[] = id(new PonderQuestionTransaction()) 69 76 ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) ··· 71 78 ->setNewValue(array('=' => array_fuse($v_projects))); 72 79 73 80 $editor = id(new PonderQuestionEditor()) 74 - ->setActor($user) 81 + ->setActor($viewer) 75 82 ->setContentSourceFromRequest($request) 76 83 ->setContinueOnNoEffect(true); 77 84 ··· 82 89 } 83 90 } 84 91 92 + $policies = id(new PhabricatorPolicyQuery()) 93 + ->setViewer($viewer) 94 + ->setObject($question) 95 + ->execute(); 96 + 85 97 $form = id(new AphrontFormView()) 86 - ->setUser($user) 98 + ->setUser($viewer) 87 99 ->appendChild( 88 100 id(new AphrontFormTextControl()) 89 101 ->setLabel(pht('Question')) ··· 92 104 ->setError($e_title)) 93 105 ->appendChild( 94 106 id(new PhabricatorRemarkupControl()) 95 - ->setUser($user) 107 + ->setUser($viewer) 96 108 ->setName('content') 97 109 ->setID('content') 98 110 ->setValue($v_content) 99 111 ->setLabel(pht('Description')) 100 - ->setUser($user)); 112 + ->setUser($viewer)) 113 + ->appendControl( 114 + id(new AphrontFormPolicyControl()) 115 + ->setName('viewPolicy') 116 + ->setPolicyObject($question) 117 + ->setPolicies($policies) 118 + ->setValue($v_view) 119 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) 120 + ->appendControl( 121 + id(new AphrontFormPolicyControl()) 122 + ->setName('editPolicy') 123 + ->setPolicyObject($question) 124 + ->setPolicies($policies) 125 + ->setValue($v_edit) 126 + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)); 101 127 102 128 $form->appendControl( 103 129 id(new AphrontFormTokenizerControl())
+3
src/applications/ponder/editor/PonderQuestionEditor.php
··· 66 66 $types = parent::getTransactionTypes(); 67 67 68 68 $types[] = PhabricatorTransactions::TYPE_COMMENT; 69 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 70 + $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 71 + 69 72 $types[] = PonderQuestionTransaction::TYPE_TITLE; 70 73 $types[] = PonderQuestionTransaction::TYPE_CONTENT; 71 74 $types[] = PonderQuestionTransaction::TYPE_ANSWERS;
+26 -6
src/applications/ponder/storage/PonderQuestion.php
··· 21 21 protected $status; 22 22 protected $content; 23 23 protected $contentSource; 24 + protected $viewPolicy; 25 + protected $editPolicy; 24 26 25 27 protected $voteCount; 26 28 protected $answerCount; ··· 30 32 private $answers; 31 33 private $vote; 32 34 private $comments; 35 + 36 + public static function initializeNewQuestion(PhabricatorUser $actor) { 37 + $app = id(new PhabricatorApplicationQuery()) 38 + ->setViewer($actor) 39 + ->withClasses(array('PhabricatorPonderApplication')) 40 + ->executeOne(); 41 + 42 + $view_policy = $app->getPolicy( 43 + PonderQuestionDefaultViewCapability::CAPABILITY); 44 + $edit_policy = $app->getPolicy( 45 + PonderQuestionDefaultEditCapability::CAPABILITY); 46 + 47 + return id(new PonderQuestion()) 48 + ->setAuthorPHID($actor->getPHID()) 49 + ->setViewPolicy($view_policy) 50 + ->setEditPolicy($edit_policy) 51 + ->setStatus(PonderQuestionStatus::STATUS_OPEN) 52 + ->setVoteCount(0) 53 + ->setAnswerCount(0) 54 + ->setHeat(0.0); 55 + } 33 56 34 57 protected function getConfiguration() { 35 58 return array( ··· 234 257 } 235 258 236 259 public function getPolicy($capability) { 237 - $policy = PhabricatorPolicies::POLICY_NOONE; 238 - 239 260 switch ($capability) { 240 261 case PhabricatorPolicyCapability::CAN_VIEW: 241 - $policy = PhabricatorPolicies::POLICY_USER; 242 - break; 262 + return $this->getViewPolicy(); 263 + case PhabricatorPolicyCapability::CAN_EDIT: 264 + return $this->getEditPolicy(); 243 265 } 244 - 245 - return $policy; 246 266 } 247 267 248 268 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {