mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +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:
parent
2d35d6053a
commit
7fa4e455b6
6 changed files with 47 additions and 82 deletions
|
@ -3,19 +3,13 @@
|
|||
final class PhabricatorSlowvoteCloseController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
|
@ -42,7 +36,7 @@ final class PhabricatorSlowvoteCloseController
|
|||
->setNewValue($new_status);
|
||||
|
||||
id(new PhabricatorSlowvoteEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
|
|
|
@ -3,23 +3,17 @@
|
|||
final class PhabricatorSlowvoteCommentController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$poll) {
|
||||
return new Aphront404Response();
|
||||
|
@ -38,7 +32,7 @@ final class PhabricatorSlowvoteCommentController
|
|||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = id(new PhabricatorSlowvoteEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
@ -57,7 +51,7 @@ final class PhabricatorSlowvoteCommentController
|
|||
|
||||
if ($request->isAjax() && $is_preview) {
|
||||
return id(new PhabricatorApplicationTransactionResponse())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->setTransactions($xactions)
|
||||
->setIsPreview($is_preview);
|
||||
} else {
|
||||
|
|
|
@ -3,21 +3,14 @@
|
|||
final class PhabricatorSlowvoteEditController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = idx($data, 'id');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
if ($this->id) {
|
||||
if ($id) {
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
|
@ -29,7 +22,7 @@ final class PhabricatorSlowvoteEditController
|
|||
}
|
||||
$is_new = false;
|
||||
} else {
|
||||
$poll = PhabricatorSlowvotePoll::initializeNewPoll($user);
|
||||
$poll = PhabricatorSlowvotePoll::initializeNewPoll($viewer);
|
||||
$is_new = true;
|
||||
}
|
||||
|
||||
|
@ -119,7 +112,7 @@ final class PhabricatorSlowvoteEditController
|
|||
->setNewValue(array('=' => array_fuse($v_projects)));
|
||||
|
||||
$editor = id(new PhabricatorSlowvoteEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
|
@ -153,7 +146,7 @@ final class PhabricatorSlowvoteEditController
|
|||
'protracted deliberation.'));
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->appendChild($instructions)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextAreaControl())
|
||||
|
@ -164,7 +157,7 @@ final class PhabricatorSlowvoteEditController
|
|||
->setError($e_question))
|
||||
->appendChild(
|
||||
id(new PhabricatorRemarkupControl())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setLabel(pht('Description'))
|
||||
->setName('description')
|
||||
->setValue($v_description))
|
||||
|
@ -232,7 +225,7 @@ final class PhabricatorSlowvoteEditController
|
|||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->setObject($poll)
|
||||
->execute();
|
||||
|
||||
|
@ -253,7 +246,7 @@ final class PhabricatorSlowvoteEditController
|
|||
$v_shuffle))
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setName('viewPolicy')
|
||||
->setPolicyObject($poll)
|
||||
->setPolicies($policies)
|
||||
|
|
|
@ -3,19 +3,15 @@
|
|||
final class PhabricatorSlowvoteListController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$querykey = $request->getURIData('queryKey');
|
||||
|
||||
public function processRequest() {
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($this->queryKey)
|
||||
->setQueryKey($querykey)
|
||||
->setSearchEngine(new PhabricatorSlowvoteSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
|
|
|
@ -3,19 +3,13 @@
|
|||
final class PhabricatorSlowvotePollController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needOptions(true)
|
||||
->needChoices(true)
|
||||
->needViewerChoices(true)
|
||||
|
@ -26,7 +20,7 @@ final class PhabricatorSlowvotePollController
|
|||
|
||||
$poll_view = id(new SlowvoteEmbedView())
|
||||
->setHeadless(true)
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setPoll($poll);
|
||||
|
||||
if ($request->isAjax()) {
|
||||
|
@ -44,7 +38,7 @@ final class PhabricatorSlowvotePollController
|
|||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader($poll->getQuestion())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setStatus($header_icon, $header_color, $header_name)
|
||||
->setPolicyObject($poll);
|
||||
|
||||
|
|
|
@ -3,19 +3,13 @@
|
|||
final class PhabricatorSlowvoteVoteController
|
||||
extends PhabricatorSlowvoteController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$poll = id(new PhabricatorSlowvoteQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->id))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needOptions(true)
|
||||
->needViewerChoices(true)
|
||||
->executeOne();
|
||||
|
@ -27,9 +21,9 @@ final class PhabricatorSlowvoteVoteController
|
|||
}
|
||||
|
||||
$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()) {
|
||||
$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(
|
||||
'pollID = %d AND authorPHID = %s',
|
||||
$poll->getID(),
|
||||
$user->getPHID());
|
||||
$viewer->getPHID());
|
||||
|
||||
$embed = id(new SlowvoteEmbedView())
|
||||
->setPoll($poll)
|
||||
|
@ -76,12 +70,12 @@ final class PhabricatorSlowvoteVoteController
|
|||
$votes = $request->getArr('vote');
|
||||
$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());
|
||||
}
|
||||
|
||||
private function updateVotes($user, $poll, $old_votes, $votes) {
|
||||
private function updateVotes($viewer, $poll, $old_votes, $votes) {
|
||||
if (!empty($votes) && count($votes) > 1 &&
|
||||
$poll->getMethod() == PhabricatorSlowvotePoll::METHOD_PLURALITY) {
|
||||
return id(new Aphront400Response());
|
||||
|
@ -99,7 +93,7 @@ final class PhabricatorSlowvoteVoteController
|
|||
}
|
||||
|
||||
id(new PhabricatorSlowvoteChoice())
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setAuthorPHID($viewer->getPHID())
|
||||
->setPollID($poll->getID())
|
||||
->setOptionID($vote)
|
||||
->save();
|
||||
|
|
Loading…
Reference in a new issue