1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 06:50:55 +01:00

Update Slowvote for handleRequest

Summary: Moves to use handleRequest

Test Plan: Make a new poll, edit, see list

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13720
This commit is contained in:
Chad Little 2015-07-27 07:42:40 -07:00
parent 2d35d6053a
commit 7fa4e455b6
6 changed files with 47 additions and 82 deletions

View file

@ -3,19 +3,13 @@
final class PhabricatorSlowvoteCloseController final class PhabricatorSlowvoteCloseController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$poll = id(new PhabricatorSlowvoteQuery()) $poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -42,7 +36,7 @@ final class PhabricatorSlowvoteCloseController
->setNewValue($new_status); ->setNewValue($new_status);
id(new PhabricatorSlowvoteEditor()) id(new PhabricatorSlowvoteEditor())
->setActor($user) ->setActor($viewer)
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true) ->setContinueOnMissingFields(true)

View file

@ -3,23 +3,17 @@
final class PhabricatorSlowvoteCommentController final class PhabricatorSlowvoteCommentController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if (!$request->isFormPost()) { if (!$request->isFormPost()) {
return new Aphront400Response(); return new Aphront400Response();
} }
$poll = id(new PhabricatorSlowvoteQuery()) $poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->executeOne(); ->executeOne();
if (!$poll) { if (!$poll) {
return new Aphront404Response(); return new Aphront404Response();
@ -38,7 +32,7 @@ final class PhabricatorSlowvoteCommentController
->setContent($request->getStr('comment'))); ->setContent($request->getStr('comment')));
$editor = id(new PhabricatorSlowvoteEditor()) $editor = id(new PhabricatorSlowvoteEditor())
->setActor($user) ->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest()) ->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setIsPreview($is_preview); ->setIsPreview($is_preview);
@ -57,7 +51,7 @@ final class PhabricatorSlowvoteCommentController
if ($request->isAjax() && $is_preview) { if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse()) return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user) ->setViewer($viewer)
->setTransactions($xactions) ->setTransactions($xactions)
->setIsPreview($is_preview); ->setIsPreview($is_preview);
} else { } else {

View file

@ -3,21 +3,14 @@
final class PhabricatorSlowvoteEditController final class PhabricatorSlowvoteEditController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
public function willProcessRequest(array $data) { if ($id) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
$poll = id(new PhabricatorSlowvoteQuery()) $poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
@ -29,7 +22,7 @@ final class PhabricatorSlowvoteEditController
} }
$is_new = false; $is_new = false;
} else { } else {
$poll = PhabricatorSlowvotePoll::initializeNewPoll($user); $poll = PhabricatorSlowvotePoll::initializeNewPoll($viewer);
$is_new = true; $is_new = true;
} }
@ -119,7 +112,7 @@ final class PhabricatorSlowvoteEditController
->setNewValue(array('=' => array_fuse($v_projects))); ->setNewValue(array('=' => array_fuse($v_projects)));
$editor = id(new PhabricatorSlowvoteEditor()) $editor = id(new PhabricatorSlowvoteEditor())
->setActor($user) ->setActor($viewer)
->setContinueOnNoEffect(true) ->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request); ->setContentSourceFromRequest($request);
@ -153,7 +146,7 @@ final class PhabricatorSlowvoteEditController
'protracted deliberation.')); 'protracted deliberation.'));
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($viewer)
->appendChild($instructions) ->appendChild($instructions)
->appendChild( ->appendChild(
id(new AphrontFormTextAreaControl()) id(new AphrontFormTextAreaControl())
@ -164,7 +157,7 @@ final class PhabricatorSlowvoteEditController
->setError($e_question)) ->setError($e_question))
->appendChild( ->appendChild(
id(new PhabricatorRemarkupControl()) id(new PhabricatorRemarkupControl())
->setUser($user) ->setUser($viewer)
->setLabel(pht('Description')) ->setLabel(pht('Description'))
->setName('description') ->setName('description')
->setValue($v_description)) ->setValue($v_description))
@ -232,7 +225,7 @@ final class PhabricatorSlowvoteEditController
} }
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($user) ->setViewer($viewer)
->setObject($poll) ->setObject($poll)
->execute(); ->execute();
@ -253,7 +246,7 @@ final class PhabricatorSlowvoteEditController
$v_shuffle)) $v_shuffle))
->appendChild( ->appendChild(
id(new AphrontFormPolicyControl()) id(new AphrontFormPolicyControl())
->setUser($user) ->setUser($viewer)
->setName('viewPolicy') ->setName('viewPolicy')
->setPolicyObject($poll) ->setPolicyObject($poll)
->setPolicies($policies) ->setPolicies($policies)

View file

@ -3,19 +3,15 @@
final class PhabricatorSlowvoteListController final class PhabricatorSlowvoteListController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $queryKey;
public function shouldAllowPublic() { public function shouldAllowPublic() {
return true; return true;
} }
public function willProcessRequest(array $data) { public function handleRequest(AphrontRequest $request) {
$this->queryKey = idx($data, 'queryKey'); $querykey = $request->getURIData('queryKey');
}
public function processRequest() {
$controller = id(new PhabricatorApplicationSearchController()) $controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey) ->setQueryKey($querykey)
->setSearchEngine(new PhabricatorSlowvoteSearchEngine()) ->setSearchEngine(new PhabricatorSlowvoteSearchEngine())
->setNavigation($this->buildSideNavView()); ->setNavigation($this->buildSideNavView());

View file

@ -3,19 +3,13 @@
final class PhabricatorSlowvotePollController final class PhabricatorSlowvotePollController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$poll = id(new PhabricatorSlowvoteQuery()) $poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needOptions(true) ->needOptions(true)
->needChoices(true) ->needChoices(true)
->needViewerChoices(true) ->needViewerChoices(true)
@ -26,7 +20,7 @@ final class PhabricatorSlowvotePollController
$poll_view = id(new SlowvoteEmbedView()) $poll_view = id(new SlowvoteEmbedView())
->setHeadless(true) ->setHeadless(true)
->setUser($user) ->setUser($viewer)
->setPoll($poll); ->setPoll($poll);
if ($request->isAjax()) { if ($request->isAjax()) {
@ -44,7 +38,7 @@ final class PhabricatorSlowvotePollController
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
->setHeader($poll->getQuestion()) ->setHeader($poll->getQuestion())
->setUser($user) ->setUser($viewer)
->setStatus($header_icon, $header_color, $header_name) ->setStatus($header_icon, $header_color, $header_name)
->setPolicyObject($poll); ->setPolicyObject($poll);

View file

@ -3,19 +3,13 @@
final class PhabricatorSlowvoteVoteController final class PhabricatorSlowvoteVoteController
extends PhabricatorSlowvoteController { extends PhabricatorSlowvoteController {
private $id; public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
public function willProcessRequest(array $data) { $id = $request->getURIData('id');
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$poll = id(new PhabricatorSlowvoteQuery()) $poll = id(new PhabricatorSlowvoteQuery())
->setViewer($user) ->setViewer($viewer)
->withIDs(array($this->id)) ->withIDs(array($id))
->needOptions(true) ->needOptions(true)
->needViewerChoices(true) ->needViewerChoices(true)
->executeOne(); ->executeOne();
@ -27,9 +21,9 @@ final class PhabricatorSlowvoteVoteController
} }
$options = $poll->getOptions(); $options = $poll->getOptions();
$user_choices = $poll->getViewerChoices($user); $viewer_choices = $poll->getViewerChoices($viewer);
$old_votes = mpull($user_choices, null, 'getOptionID'); $old_votes = mpull($viewer_choices, null, 'getOptionID');
if ($request->isAjax()) { if ($request->isAjax()) {
$vote = $request->getInt('vote'); $vote = $request->getInt('vote');
@ -50,12 +44,12 @@ final class PhabricatorSlowvoteVoteController
} }
} }
$this->updateVotes($user, $poll, $old_votes, $votes); $this->updateVotes($viewer, $poll, $old_votes, $votes);
$updated_choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( $updated_choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
'pollID = %d AND authorPHID = %s', 'pollID = %d AND authorPHID = %s',
$poll->getID(), $poll->getID(),
$user->getPHID()); $viewer->getPHID());
$embed = id(new SlowvoteEmbedView()) $embed = id(new SlowvoteEmbedView())
->setPoll($poll) ->setPoll($poll)
@ -76,12 +70,12 @@ final class PhabricatorSlowvoteVoteController
$votes = $request->getArr('vote'); $votes = $request->getArr('vote');
$votes = array_fuse($votes, $votes); $votes = array_fuse($votes, $votes);
$this->updateVotes($user, $poll, $old_votes, $votes); $this->updateVotes($viewer, $poll, $old_votes, $votes);
return id(new AphrontRedirectResponse())->setURI('/V'.$poll->getID()); return id(new AphrontRedirectResponse())->setURI('/V'.$poll->getID());
} }
private function updateVotes($user, $poll, $old_votes, $votes) { private function updateVotes($viewer, $poll, $old_votes, $votes) {
if (!empty($votes) && count($votes) > 1 && if (!empty($votes) && count($votes) > 1 &&
$poll->getMethod() == PhabricatorSlowvotePoll::METHOD_PLURALITY) { $poll->getMethod() == PhabricatorSlowvotePoll::METHOD_PLURALITY) {
return id(new Aphront400Response()); return id(new Aphront400Response());
@ -99,7 +93,7 @@ final class PhabricatorSlowvoteVoteController
} }
id(new PhabricatorSlowvoteChoice()) id(new PhabricatorSlowvoteChoice())
->setAuthorPHID($user->getPHID()) ->setAuthorPHID($viewer->getPHID())
->setPollID($poll->getID()) ->setPollID($poll->getID())
->setOptionID($vote) ->setOptionID($vote)
->save(); ->save();