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

Move Slowvote response visibility to a separate object

Summary: Ref T13682. This change supports modifying these constants to be sensible strings instead of opaque integers.

Test Plan: Created and edited polls.

Maniphest Tasks: T13682

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

+126 -32
+2
src/__phutil_library_map__.php
··· 5872 5872 'SlowvoteConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteConduitAPIMethod.php', 5873 5873 'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php', 5874 5874 'SlowvoteInfoConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteInfoConduitAPIMethod.php', 5875 + 'SlowvotePollResponseVisibility' => 'applications/slowvote/constants/SlowvotePollResponseVisibility.php', 5875 5876 'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php', 5876 5877 'SlowvoteSearchConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteSearchConduitAPIMethod.php', 5877 5878 'SubscriptionListDialogBuilder' => 'applications/subscriptions/view/SubscriptionListDialogBuilder.php', ··· 12773 12774 'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod', 12774 12775 'SlowvoteEmbedView' => 'AphrontView', 12775 12776 'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod', 12777 + 'SlowvotePollResponseVisibility' => 'Phobject', 12776 12778 'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule', 12777 12779 'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 12778 12780 'SubscriptionListDialogBuilder' => 'Phobject',
+75
src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
··· 1 + <?php 2 + 3 + final class SlowvotePollResponseVisibility 4 + extends Phobject { 5 + 6 + const RESPONSES_VISIBLE = 0; 7 + const RESPONSES_VOTERS = 1; 8 + const RESPONSES_OWNER = 2; 9 + 10 + private $key; 11 + 12 + public static function newResponseVisibilityObject($key) { 13 + $object = new self(); 14 + $object->key = $key; 15 + return $object; 16 + } 17 + 18 + public function getKey() { 19 + return $this->key; 20 + } 21 + 22 + public static function getAll() { 23 + $map = self::getMap(); 24 + 25 + $result = array(); 26 + foreach ($map as $key => $spec) { 27 + $result[$key] = self::newResponseVisibilityObject($key); 28 + } 29 + 30 + return $result; 31 + } 32 + 33 + public function getName() { 34 + $name = $this->getProperty('name'); 35 + 36 + if ($name === null) { 37 + $name = pht('Unknown ("%s")', $this->getKey()); 38 + } 39 + 40 + return $name; 41 + } 42 + 43 + public function getNameForEdit() { 44 + $name = $this->getProperty('name.edit'); 45 + 46 + if ($name === null) { 47 + $name = pht('Unknown ("%s")', $this->getKey()); 48 + } 49 + 50 + return $name; 51 + } 52 + 53 + private function getProperty($key, $default = null) { 54 + $spec = idx(self::getMap(), $this->getKey()); 55 + return idx($spec, $key, $default); 56 + } 57 + 58 + private static function getMap() { 59 + return array( 60 + self::RESPONSES_VISIBLE => array( 61 + 'name' => pht('Always Visible'), 62 + 'name.edit' => pht('Anyone can see the responses'), 63 + ), 64 + self::RESPONSES_VOTERS => array( 65 + 'name' => pht('Voters'), 66 + 'name.edit' => pht('Require a vote to see the responses'), 67 + ), 68 + self::RESPONSES_OWNER => array( 69 + 'name' => pht('Owner'), 70 + 'name.edit' => pht('Only the poll owner can see the responses'), 71 + ), 72 + ); 73 + } 74 + 75 + }
+3 -9
src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 49 49 if ($request->isFormPost()) { 50 50 $v_question = $request->getStr('question'); 51 51 $v_description = $request->getStr('description'); 52 - $v_responses = (int)$request->getInt('responses'); 52 + $v_responses = $request->getStr('responses'); 53 53 $v_shuffle = (int)$request->getBool('shuffle'); 54 54 $v_view_policy = $request->getStr('viewPolicy'); 55 55 $v_projects = $request->getArr('projects'); ··· 196 196 pht('Approval (Multiple Choice)'), 197 197 ); 198 198 199 - $response_type_options = array( 200 - PhabricatorSlowvotePoll::RESPONSES_VISIBLE 201 - => pht('Allow anyone to see the responses'), 202 - PhabricatorSlowvotePoll::RESPONSES_VOTERS 203 - => pht('Require a vote to see the responses'), 204 - PhabricatorSlowvotePoll::RESPONSES_OWNER 205 - => pht('Only I can see the responses'), 206 - ); 199 + $response_type_map = SlowvotePollResponseVisibility::getAll(); 200 + $response_type_options = mpull($response_type_map, 'getNameForEdit'); 207 201 208 202 if ($is_new) { 209 203 $form->appendChild(
+5 -6
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 13 13 PhabricatorSpacesInterface, 14 14 PhabricatorConduitResultInterface { 15 15 16 - const RESPONSES_VISIBLE = 0; 17 - const RESPONSES_VOTERS = 1; 18 - const RESPONSES_OWNER = 2; 19 - 20 16 const METHOD_PLURALITY = 0; 21 17 const METHOD_APPROVAL = 1; 22 18 23 19 protected $question; 24 20 protected $description; 25 21 protected $authorPHID; 26 - protected $responseVisibility = 0; 22 + protected $responseVisibility; 27 23 protected $shuffle = 0; 28 24 protected $method; 29 25 protected $viewPolicy; ··· 43 39 $view_policy = $app->getPolicy( 44 40 PhabricatorSlowvoteDefaultViewCapability::CAPABILITY); 45 41 42 + $default_responses = SlowvotePollResponseVisibility::RESPONSES_VISIBLE; 43 + 46 44 return id(new PhabricatorSlowvotePoll()) 47 45 ->setAuthorPHID($actor->getPHID()) 48 46 ->setViewPolicy($view_policy) 49 - ->setSpacePHID($actor->getDefaultSpacePHID()); 47 + ->setSpacePHID($actor->getDefaultSpacePHID()) 48 + ->setResponseVisibility($default_responses); 50 49 } 51 50 52 51 protected function getConfiguration() {
+14 -10
src/applications/slowvote/view/SlowvoteEmbedView.php
··· 77 77 78 78 $vis = $poll->getResponseVisibility(); 79 79 if ($this->areResultsVisible()) { 80 - if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) { 80 + if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) { 81 81 $quip = pht('Only you can see the results.'); 82 82 } else { 83 83 $quip = pht('Voting improves cardiovascular endurance.'); 84 84 } 85 - } else if ($vis == PhabricatorSlowvotePoll::RESPONSES_VOTERS) { 85 + } else if ($vis == SlowvotePollResponseVisibility::RESPONSES_VOTERS) { 86 86 $quip = pht('You must vote to see the results.'); 87 - } else if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) { 87 + } else if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) { 88 88 $quip = pht('Only the author can see the results.'); 89 89 } 90 90 ··· 321 321 private function areResultsVisible() { 322 322 $poll = $this->getPoll(); 323 323 324 - $vis = $poll->getResponseVisibility(); 325 - if ($vis == PhabricatorSlowvotePoll::RESPONSES_VISIBLE) { 324 + $visibility = $poll->getResponseVisibility(); 325 + if ($visibility == SlowvotePollResponseVisibility::RESPONSES_VISIBLE) { 326 326 return true; 327 - } else if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) { 328 - return ($poll->getAuthorPHID() == $this->getUser()->getPHID()); 329 - } else { 330 - $choices = mgroup($poll->getChoices(), 'getAuthorPHID'); 331 - return (bool)idx($choices, $this->getUser()->getPHID()); 332 327 } 328 + 329 + $viewer = $this->getViewer(); 330 + 331 + if ($visibility == SlowvotePollResponseVisibility::RESPONSES_OWNER) { 332 + return ($poll->getAuthorPHID() === $viewer->getPHID()); 333 + } 334 + 335 + $choices = mgroup($poll->getChoices(), 'getAuthorPHID'); 336 + return (bool)idx($choices, $viewer->getPHID()); 333 337 } 334 338 335 339 }
+27 -7
src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
··· 6 6 const TRANSACTIONTYPE = 'vote:responses'; 7 7 8 8 public function generateOldValue($object) { 9 - return (int)$object->getResponseVisibility(); 9 + return $object->getResponseVisibility(); 10 10 } 11 11 12 12 public function applyInternalEffects($object, $value) { ··· 14 14 } 15 15 16 16 public function getTitle() { 17 - // TODO: This could be more detailed 17 + $old_name = $this->getOldResponseVisibilityObject()->getName(); 18 + $new_name = $this->getNewResponseVisibilityObject()->getName(); 19 + 18 20 return pht( 19 - '%s changed who can see the responses.', 20 - $this->renderAuthor()); 21 + '%s changed who can see the responses from %s to %s.', 22 + $this->renderAuthor(), 23 + $this->renderValue($old_name), 24 + $this->renderValue($new_name)); 21 25 } 22 26 23 27 public function getTitleForFeed() { 24 - // TODO: This could be more detailed 28 + $old_name = $this->getOldResponseVisibilityObject()->getName(); 29 + $new_name = $this->getNewResponseVisibilityObject()->getName(); 30 + 25 31 return pht( 26 - '%s changed who can see the responses of %s.', 32 + '%s changed who can see the responses of %s from %s to %s.', 27 33 $this->renderAuthor(), 28 - $this->renderObject()); 34 + $this->renderObject(), 35 + $this->renderValue($old_name), 36 + $this->renderValue($new_name)); 37 + } 38 + 39 + private function getOldResponseVisibilityObject() { 40 + return $this->newResponseVisibilityObject($this->getOldValue()); 41 + } 42 + 43 + private function getNewResponseVisibilityObject() { 44 + return $this->newResponseVisibilityObject($this->getNewValue()); 45 + } 46 + 47 + private function newResponseVisibilityObject($value) { 48 + return SlowvotePollResponseVisibility::newResponseVisibilityObject($value); 29 49 } 30 50 31 51 }