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

Provide application and object level policy controls in Slowvote

Summary: Ref T603. Gives the create/edit interface a policy control, and adds an application-level default.

Test Plan: Created and edited polls.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+64 -3
+2
src/__phutil_library_map__.php
··· 1665 1665 'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php', 1666 1666 'PhabricatorSetupIssueExample' => 'applications/uiexample/examples/PhabricatorSetupIssueExample.php', 1667 1667 'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php', 1668 + 'PhabricatorSlowvoteCapabilityDefaultView' => 'applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php', 1668 1669 'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php', 1669 1670 'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php', 1670 1671 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', ··· 3876 3877 'PhabricatorSetupCheckTimezone' => 'PhabricatorSetupCheck', 3877 3878 'PhabricatorSetupIssueExample' => 'PhabricatorUIExample', 3878 3879 'PhabricatorSetupIssueView' => 'AphrontView', 3880 + 'PhabricatorSlowvoteCapabilityDefaultView' => 'PhabricatorPolicyCapability', 3879 3881 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', 3880 3882 'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO', 3881 3883 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
+8
src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
··· 50 50 ); 51 51 } 52 52 53 + public function getCustomCapabilities() { 54 + return array( 55 + PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY => array( 56 + 'caption' => pht('Default view policy for new polls.'), 57 + ), 58 + ); 59 + } 60 + 53 61 }
+20
src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php
··· 1 + <?php 2 + 3 + final class PhabricatorSlowvoteCapabilityDefaultView 4 + extends PhabricatorPolicyCapability { 5 + 6 + const CAPABILITY = 'slowvote.default.view'; 7 + 8 + public function getCapabilityKey() { 9 + return self::CAPABILITY; 10 + } 11 + 12 + public function getCapabilityName() { 13 + return pht('Default View Policy'); 14 + } 15 + 16 + public function shouldAllowPublicPolicySetting() { 17 + return true; 18 + } 19 + 20 + }
+20 -3
src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 32 32 } 33 33 $is_new = false; 34 34 } else { 35 - $poll = id(new PhabricatorSlowvotePoll()) 36 - ->setAuthorPHID($user->getPHID()) 37 - ->setViewPolicy(PhabricatorPolicies::POLICY_USER); 35 + $poll = PhabricatorSlowvotePoll::initializeNewPoll($user); 38 36 $is_new = true; 39 37 } 40 38 ··· 53 51 $v_description = $request->getStr('description'); 54 52 $v_responses = (int)$request->getInt('responses'); 55 53 $v_shuffle = (int)$request->getBool('shuffle'); 54 + $v_view_policy = $request->getStr('viewPolicy'); 56 55 57 56 if ($is_new) { 58 57 $poll->setMethod($request->getInt('method')); ··· 94 93 ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE) 95 94 ->setNewValue($v_shuffle); 96 95 96 + $xactions[] = id(clone $template) 97 + ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 98 + ->setNewValue($v_view_policy); 99 + 97 100 if (empty($errors)) { 98 101 $editor = id(new PhabricatorSlowvoteEditor()) 99 102 ->setActor($user) ··· 115 118 116 119 return id(new AphrontRedirectResponse()) 117 120 ->setURI('/V'.$poll->getID()); 121 + } else { 122 + $poll->setViewPolicy($v_view_policy); 118 123 } 119 124 } 120 125 ··· 206 211 $cancel_uri = '/V'.$poll->getID(); 207 212 } 208 213 214 + $policies = id(new PhabricatorPolicyQuery()) 215 + ->setViewer($user) 216 + ->setObject($poll) 217 + ->execute(); 218 + 209 219 $form 210 220 ->appendChild( 211 221 id(new AphrontFormSelectControl()) ··· 221 231 1, 222 232 pht('Show choices in random order.'), 223 233 $v_shuffle)) 234 + ->appendChild( 235 + id(new AphrontFormPolicyControl()) 236 + ->setUser($user) 237 + ->setName('viewPolicy') 238 + ->setPolicyObject($poll) 239 + ->setPolicies($policies) 240 + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)) 224 241 ->appendChild( 225 242 id(new AphrontFormSubmitControl()) 226 243 ->setValue($button)
+14
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 28 28 private $choices = self::ATTACHABLE; 29 29 private $viewerChoices = self::ATTACHABLE; 30 30 31 + public static function initializeNewPoll(PhabricatorUser $actor) { 32 + $app = id(new PhabricatorApplicationQuery()) 33 + ->setViewer($actor) 34 + ->withClasses(array('PhabricatorApplicationSlowvote')) 35 + ->executeOne(); 36 + 37 + $view_policy = $app->getPolicy( 38 + PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY); 39 + 40 + return id(new PhabricatorSlowvotePoll()) 41 + ->setAuthorPHID($actor->getPHID()) 42 + ->setViewPolicy($view_policy); 43 + } 44 + 31 45 public function getConfiguration() { 32 46 return array( 33 47 self::CONFIG_AUX_PHID => true,