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

Make most slowvote fields edit transactionally

Summary: No support for responses yet, since they're more complicated, but put everything else on the transactions plan. This also prepares polls for editability, shortly.

Test Plan: {F50205}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+188 -20
+4 -2
src/__phutil_library_map__.php
··· 1529 1529 'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php', 1530 1530 'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php', 1531 1531 'PhabricatorSlowvoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteController.php', 1532 - 'PhabricatorSlowvoteCreateController' => 'applications/slowvote/controller/PhabricatorSlowvoteCreateController.php', 1533 1532 'PhabricatorSlowvoteDAO' => 'applications/slowvote/storage/PhabricatorSlowvoteDAO.php', 1533 + 'PhabricatorSlowvoteEditController' => 'applications/slowvote/controller/PhabricatorSlowvoteEditController.php', 1534 1534 'PhabricatorSlowvoteEditor' => 'applications/slowvote/editor/PhabricatorSlowvoteEditor.php', 1535 1535 'PhabricatorSlowvoteListController' => 'applications/slowvote/controller/PhabricatorSlowvoteListController.php', 1536 1536 'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php', ··· 3490 3490 'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO', 3491 3491 'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController', 3492 3492 'PhabricatorSlowvoteController' => 'PhabricatorController', 3493 - 'PhabricatorSlowvoteCreateController' => 'PhabricatorSlowvoteController', 3494 3493 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', 3494 + 'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController', 3495 3495 'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor', 3496 3496 'PhabricatorSlowvoteListController' => 3497 3497 array( ··· 3503 3503 array( 3504 3504 0 => 'PhabricatorSlowvoteDAO', 3505 3505 1 => 'PhabricatorPolicyInterface', 3506 + 2 => 'PhabricatorSubscribableInterface', 3507 + 3 => 'PhabricatorTokenReceiverInterface', 3506 3508 ), 3507 3509 'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController', 3508 3510 'PhabricatorSlowvoteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+1 -1
src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
··· 42 42 '/vote/' => array( 43 43 '(?:query/(?P<queryKey>[^/]+)/)?' 44 44 => 'PhabricatorSlowvoteListController', 45 - 'create/' => 'PhabricatorSlowvoteCreateController', 45 + 'create/' => 'PhabricatorSlowvoteEditController', 46 46 '(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController', 47 47 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController', 48 48 ),
+58 -14
src/applications/slowvote/controller/PhabricatorSlowvoteCreateController.php src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 3 3 /** 4 4 * @group slowvote 5 5 */ 6 - final class PhabricatorSlowvoteCreateController 6 + final class PhabricatorSlowvoteEditController 7 7 extends PhabricatorSlowvoteController { 8 8 9 + private $id; 10 + 11 + public function willProcessRequest(array $data) { 12 + $this->id = idx($data, 'id'); 13 + } 14 + 9 15 public function processRequest() { 10 16 11 17 $request = $this->getRequest(); ··· 13 19 14 20 $poll = new PhabricatorSlowvotePoll(); 15 21 $poll->setAuthorPHID($user->getPHID()); 22 + $poll->setViewPolicy(PhabricatorPolicies::POLICY_USER); 23 + 24 + $is_new = true; 16 25 17 26 $e_question = true; 18 27 $e_response = true; 19 28 $errors = array(); 20 29 21 - $responses = $request->getArr('response'); 30 + $v_question = $poll->getQuestion(); 31 + $v_description = $poll->getDescription(); 32 + $v_responses = $poll->getResponseVisibility(); 33 + $v_shuffle = $poll->getShuffle(); 22 34 35 + $responses = $request->getArr('response'); 23 36 if ($request->isFormPost()) { 24 - $poll->setQuestion($request->getStr('question')); 25 - $poll->setResponseVisibility($request->getInt('response_visibility')); 26 - $poll->setShuffle((int)$request->getBool('shuffle', false)); 27 - $poll->setMethod($request->getInt('method')); 37 + $v_question = $request->getStr('question'); 38 + $v_description = $request->getStr('description'); 39 + $v_responses = $request->getInt('responses'); 40 + $v_shuffle = (int)$request->getBool('shuffle'); 28 41 29 - $poll->setDescription(''); 30 - $poll->setViewPolicy(PhabricatorPolicies::POLICY_USER); 42 + if ($is_new) { 43 + $poll->setMethod($request->getInt('method')); 44 + } 31 45 32 - if (!strlen($poll->getQuestion())) { 46 + if (!strlen($v_question)) { 33 47 $e_question = pht('Required'); 34 48 $errors[] = pht('You must ask a poll question.'); 35 49 } else { ··· 44 58 $e_response = null; 45 59 } 46 60 61 + $xactions = array(); 62 + $template = id(new PhabricatorSlowvoteTransaction()); 63 + 64 + $xactions[] = id(clone $template) 65 + ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_QUESTION) 66 + ->setNewValue($v_question); 67 + 68 + $xactions[] = id(clone $template) 69 + ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION) 70 + ->setNewValue($v_description); 71 + 72 + $xactions[] = id(clone $template) 73 + ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_RESPONSES) 74 + ->setNewValue($v_responses); 75 + 76 + $xactions[] = id(clone $template) 77 + ->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE) 78 + ->setNewValue($v_shuffle); 79 + 47 80 if (empty($errors)) { 81 + $editor = id(new PhabricatorSlowvoteEditor()) 82 + ->setActor($user) 83 + ->setContinueOnNoEffect(true) 84 + ->setContentSourceFromRequest($request) 85 + ->applyTransactions($poll, $xactions); 86 + 48 87 $poll->save(); 49 88 50 89 foreach ($responses as $response) { ··· 84 123 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) 85 124 ->setLabel(pht('Question')) 86 125 ->setName('question') 87 - ->setValue($poll->getQuestion()) 88 - ->setError($e_question)); 126 + ->setValue($v_question) 127 + ->setError($e_question)) 128 + ->appendChild( 129 + id(new PhabricatorRemarkupControl()) 130 + ->setLabel(pht('Description')) 131 + ->setName('description') 132 + ->setValue($v_description)); 89 133 90 134 for ($ii = 0; $ii < 10; $ii++) { 91 135 $n = ($ii + 1); ··· 127 171 ->appendChild( 128 172 id(new AphrontFormSelectControl()) 129 173 ->setLabel(pht('Responses')) 130 - ->setName('response_visibility') 131 - ->setValue($poll->getResponseVisibility()) 174 + ->setName('responses') 175 + ->setValue($v_responses) 132 176 ->setOptions($response_type_options)) 133 177 ->appendChild( 134 178 id(new AphrontFormCheckboxControl()) ··· 137 181 'shuffle', 138 182 1, 139 183 pht('Show choices in random order.'), 140 - $poll->getShuffle())) 184 + $v_shuffle)) 141 185 ->appendChild( 142 186 id(new AphrontFormSubmitControl()) 143 187 ->setValue(pht('Create Slowvote'))
+1 -1
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 391 391 $view->invokeWillRenderEvent(); 392 392 393 393 if (strlen($poll->getDescription())) { 394 - $view->addTextSection( 394 + $view->addTextContent( 395 395 $output = PhabricatorMarkupEngine::renderOneObject( 396 396 id(new PhabricatorMarkupOneOff())->setContent( 397 397 $poll->getDescription()),
+31
src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
··· 7 7 $types = parent::getTransactionTypes(); 8 8 9 9 $types[] = PhabricatorTransactions::TYPE_COMMENT; 10 + $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 11 + 12 + $types[] = PhabricatorSlowvoteTransaction::TYPE_QUESTION; 13 + $types[] = PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION; 14 + $types[] = PhabricatorSlowvoteTransaction::TYPE_RESPONSES; 15 + $types[] = PhabricatorSlowvoteTransaction::TYPE_SHUFFLE; 10 16 11 17 return $types; 12 18 } ··· 16 22 PhabricatorApplicationTransaction $xaction) { 17 23 18 24 switch ($xaction->getTransactionType()) { 25 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 26 + return $object->getQuestion(); 27 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 28 + return $object->getDescription(); 29 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 30 + return $object->getResponseVisibility(); 31 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 32 + return $object->getShuffle(); 19 33 } 20 34 } 21 35 ··· 24 38 PhabricatorApplicationTransaction $xaction) { 25 39 26 40 switch ($xaction->getTransactionType()) { 41 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 42 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 43 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 44 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 45 + return $xaction->getNewValue(); 27 46 } 28 47 } 29 48 ··· 32 51 PhabricatorApplicationTransaction $xaction) { 33 52 34 53 switch ($xaction->getTransactionType()) { 54 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 55 + $object->setQuestion($xaction->getNewValue()); 56 + break; 57 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 58 + $object->setDescription($xaction->getNewValue()); 59 + break; 60 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 61 + $object->setResponseVisibility($xaction->getNewValue()); 62 + break; 63 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 64 + $object->setShuffle($xaction->getNewValue()); 65 + break; 35 66 } 36 67 } 37 68
+93 -2
src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
··· 3 3 final class PhabricatorSlowvoteTransaction 4 4 extends PhabricatorApplicationTransaction { 5 5 6 - const TYPE_NAME = 'vote:name'; 6 + const TYPE_QUESTION = 'vote:question'; 7 7 const TYPE_DESCRIPTION = 'vote:description'; 8 - const TYPE_OPTION = 'vote:option'; 8 + const TYPE_RESPONSES = 'vote:responses'; 9 + const TYPE_SHUFFLE = 'vote:shuffle'; 9 10 10 11 public function getApplicationName() { 11 12 return 'slowvote'; ··· 21 22 22 23 public function getApplicationObjectTypeName() { 23 24 return pht('vote'); 25 + } 26 + 27 + public function shouldHide() { 28 + $old = $this->getOldValue(); 29 + $new = $this->getNewValue(); 30 + 31 + switch ($this->getTransactionType()) { 32 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 33 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 34 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 35 + return ($old === null); 36 + } 37 + 38 + return parent::shouldHide(); 39 + } 40 + 41 + public function getTitle() { 42 + $author_phid = $this->getAuthorPHID(); 43 + 44 + $old = $this->getOldValue(); 45 + $new = $this->getNewValue(); 46 + 47 + switch ($this->getTransactionType()) { 48 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 49 + if ($old === null) { 50 + return pht( 51 + '%s created this poll.', 52 + $this->renderHandleLink($author_phid)); 53 + } else { 54 + return pht( 55 + '%s changed the poll question from "%s" to "%s".', 56 + $this->renderHandleLink($author_phid), 57 + $old, 58 + $new); 59 + } 60 + break; 61 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 62 + return pht( 63 + '%s updated the description for this poll.', 64 + $this->renderHandleLink($author_phid)); 65 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 66 + // TODO: This could be more detailed 67 + return pht( 68 + '%s changed who can see the responses.', 69 + $this->renderHandleLink($author_phid)); 70 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 71 + if ($new) { 72 + return pht( 73 + '%s made poll responses appear in a random order.', 74 + $this->renderHandleLink($author_phid)); 75 + } else { 76 + return pht( 77 + '%s made poll responses appear in a fixed order.', 78 + $this->renderHandleLink($author_phid)); 79 + } 80 + break; 81 + } 82 + 83 + return parent::getTitle(); 84 + } 85 + 86 + public function getIcon() { 87 + $old = $this->getOldValue(); 88 + $new = $this->getNewValue(); 89 + 90 + switch ($this->getTransactionType()) { 91 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 92 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 93 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 94 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 95 + return 'edit'; 96 + } 97 + 98 + return parent::getIcon(); 99 + } 100 + 101 + 102 + public function getColor() { 103 + $old = $this->getOldValue(); 104 + $new = $this->getNewValue(); 105 + 106 + switch ($this->getTransactionType()) { 107 + case PhabricatorSlowvoteTransaction::TYPE_QUESTION: 108 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 109 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 110 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 111 + return PhabricatorTransactions::COLOR_BLUE; 112 + } 113 + 114 + return parent::getColor(); 24 115 } 25 116 26 117 }