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

Allow most Slowvote fields to be edited

Summary: Just cheating on the hard stuff for now.

Test Plan: {F50207}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+129 -37
+1
src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
··· 43 43 '(?:query/(?P<queryKey>[^/]+)/)?' 44 44 => 'PhabricatorSlowvoteListController', 45 45 'create/' => 'PhabricatorSlowvoteEditController', 46 + 'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteEditController', 46 47 '(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController', 47 48 'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController', 48 49 ),
+76 -37
src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
··· 17 17 $request = $this->getRequest(); 18 18 $user = $request->getUser(); 19 19 20 - $poll = new PhabricatorSlowvotePoll(); 21 - $poll->setAuthorPHID($user->getPHID()); 22 - $poll->setViewPolicy(PhabricatorPolicies::POLICY_USER); 23 - 24 - $is_new = true; 20 + if ($this->id) { 21 + $poll = id(new PhabricatorSlowvoteQuery()) 22 + ->setViewer($user) 23 + ->withIDs(array($this->id)) 24 + ->requireCapabilities( 25 + array( 26 + PhabricatorPolicyCapability::CAN_VIEW, 27 + PhabricatorPolicyCapability::CAN_EDIT, 28 + )) 29 + ->executeOne(); 30 + if (!$poll) { 31 + return new Aphront404Response(); 32 + } 33 + $is_new = false; 34 + } else { 35 + $poll = id(new PhabricatorSlowvotePoll()) 36 + ->setAuthorPHID($user->getPHID()) 37 + ->setViewPolicy(PhabricatorPolicies::POLICY_USER); 38 + $is_new = true; 39 + } 25 40 26 41 $e_question = true; 27 42 $e_response = true; ··· 50 65 $e_question = null; 51 66 } 52 67 53 - $responses = array_filter($responses); 54 - if (empty($responses)) { 55 - $errors[] = pht('You must offer at least one response.'); 56 - $e_response = pht('Required'); 57 - } else { 58 - $e_response = null; 68 + if ($is_new) { 69 + $responses = array_filter($responses); 70 + if (empty($responses)) { 71 + $errors[] = pht('You must offer at least one response.'); 72 + $e_response = pht('Required'); 73 + } else { 74 + $e_response = null; 75 + } 59 76 } 60 77 61 78 $xactions = array(); ··· 81 98 $editor = id(new PhabricatorSlowvoteEditor()) 82 99 ->setActor($user) 83 100 ->setContinueOnNoEffect(true) 84 - ->setContentSourceFromRequest($request) 85 - ->applyTransactions($poll, $xactions); 101 + ->setContentSourceFromRequest($request); 86 102 87 - $poll->save(); 103 + $xactions = $editor->applyTransactions($poll, $xactions); 88 104 89 - foreach ($responses as $response) { 90 - $option = new PhabricatorSlowvoteOption(); 91 - $option->setName($response); 92 - $option->setPollID($poll->getID()); 93 - $option->save(); 105 + if ($is_new) { 106 + $poll->save(); 107 + 108 + foreach ($responses as $response) { 109 + $option = new PhabricatorSlowvoteOption(); 110 + $option->setName($response); 111 + $option->setPollID($poll->getID()); 112 + $option->save(); 113 + } 94 114 } 95 115 96 116 return id(new AphrontRedirectResponse()) ··· 131 151 ->setName('description') 132 152 ->setValue($v_description)); 133 153 134 - for ($ii = 0; $ii < 10; $ii++) { 135 - $n = ($ii + 1); 136 - $response = id(new AphrontFormTextControl()) 137 - ->setLabel(pht("Response %d", $n)) 138 - ->setName('response[]') 139 - ->setValue(idx($responses, $ii, '')); 154 + if ($is_new) { 155 + for ($ii = 0; $ii < 10; $ii++) { 156 + $n = ($ii + 1); 157 + $response = id(new AphrontFormTextControl()) 158 + ->setLabel(pht("Response %d", $n)) 159 + ->setName('response[]') 160 + ->setValue(idx($responses, $ii, '')); 161 + 162 + if ($ii == 0) { 163 + $response->setError($e_response); 164 + } 140 165 141 - if ($ii == 0) { 142 - $response->setError($e_response); 166 + $form->appendChild($response); 143 167 } 144 - 145 - $form->appendChild($response); 146 168 } 147 169 148 170 $poll_type_options = array( ··· 161 183 => pht('Only I can see the responses'), 162 184 ); 163 185 164 - $form 165 - ->appendChild( 186 + if ($is_new) { 187 + $form->appendChild( 166 188 id(new AphrontFormSelectControl()) 167 189 ->setLabel(pht('Vote Type')) 168 190 ->setName('method') 169 191 ->setValue($poll->getMethod()) 170 - ->setOptions($poll_type_options)) 192 + ->setOptions($poll_type_options)); 193 + } else { 194 + $form->appendChild( 195 + id(new AphrontFormStaticControl()) 196 + ->setLabel(pht('Vote Type')) 197 + ->setValue(idx($poll_type_options, $poll->getMethod()))); 198 + } 199 + 200 + if ($is_new) { 201 + $title = pht('Create Slowvote'); 202 + $button = pht('Create'); 203 + $cancel_uri = $this->getApplicationURI(); 204 + } else { 205 + $title = pht('Edit %s', 'V'.$poll->getID()); 206 + $button = pht('Save Changes'); 207 + $cancel_uri = '/V'.$poll->getID(); 208 + } 209 + 210 + $form 171 211 ->appendChild( 172 212 id(new AphrontFormSelectControl()) 173 213 ->setLabel(pht('Responses')) ··· 184 224 $v_shuffle)) 185 225 ->appendChild( 186 226 id(new AphrontFormSubmitControl()) 187 - ->setValue(pht('Create Slowvote')) 188 - ->addCancelButton('/vote/')); 227 + ->setValue($button) 228 + ->addCancelButton($cancel_uri)); 189 229 190 230 $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()); 191 231 $crumbs->addCrumb( 192 232 id(new PhabricatorCrumbView()) 193 - ->setName(pht('Create Slowvote')) 194 - ->setHref($this->getApplicationURI().'create/')); 233 + ->setName($title)); 195 234 196 235 return $this->buildApplicationPage( 197 236 array( ··· 200 239 $form, 201 240 ), 202 241 array( 203 - 'title' => pht('Create Slowvote'), 242 + 'title' => $title, 204 243 'device' => true, 205 244 'dust' => true, 206 245 ));
+13
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 370 370 ->setUser($viewer) 371 371 ->setObject($poll); 372 372 373 + $can_edit = PhabricatorPolicyFilter::hasCapability( 374 + $viewer, 375 + $poll, 376 + PhabricatorPolicyCapability::CAN_EDIT); 377 + 378 + $view->addAction( 379 + id(new PhabricatorActionView()) 380 + ->setName(pht('Edit Poll')) 381 + ->setIcon('edit') 382 + ->setHref($this->getApplicationURI('edit/'.$poll->getID().'/')) 383 + ->setDisabled(!$can_edit) 384 + ->setWorkflow(!$can_edit)); 385 + 373 386 return $view; 374 387 } 375 388
+18
src/applications/slowvote/editor/PhabricatorSlowvoteEditor.php
··· 17 17 return $types; 18 18 } 19 19 20 + protected function transactionHasEffect( 21 + PhabricatorLiskDAO $object, 22 + PhabricatorApplicationTransaction $xaction) { 23 + 24 + $old = $xaction->getOldValue(); 25 + $new = $xaction->getNewValue(); 26 + 27 + switch ($xaction->getTransactionType()) { 28 + case PhabricatorSlowvoteTransaction::TYPE_RESPONSES: 29 + return ((int)$old !== (int)$new); 30 + case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE: 31 + return ((bool)$old !== (bool)$new); 32 + } 33 + 34 + return parent::transactionHasEffect($object, $xaction); 35 + } 36 + 37 + 20 38 protected function getCustomTransactionOldValue( 21 39 PhabricatorLiskDAO $object, 22 40 PhabricatorApplicationTransaction $xaction) {
+21
src/applications/slowvote/storage/PhabricatorSlowvoteTransaction.php
··· 114 114 return parent::getColor(); 115 115 } 116 116 117 + public function hasChangeDetails() { 118 + switch ($this->getTransactionType()) { 119 + case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION: 120 + return true; 121 + } 122 + return parent::hasChangeDetails(); 123 + } 124 + 125 + public function renderChangeDetails(PhabricatorUser $viewer) { 126 + $old = $this->getOldValue(); 127 + $new = $this->getNewValue(); 128 + 129 + $view = id(new PhabricatorApplicationTransactionTextDiffDetailView()) 130 + ->setUser($viewer) 131 + ->setOldText($old) 132 + ->setNewText($new); 133 + 134 + return $view->render(); 135 + } 136 + 137 + 117 138 } 118 139