mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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
This commit is contained in:
parent
aa2e6d1e5a
commit
84d157f16a
5 changed files with 129 additions and 37 deletions
|
@ -43,6 +43,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication {
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
=> 'PhabricatorSlowvoteListController',
|
=> 'PhabricatorSlowvoteListController',
|
||||||
'create/' => 'PhabricatorSlowvoteEditController',
|
'create/' => 'PhabricatorSlowvoteEditController',
|
||||||
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteEditController',
|
||||||
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
|
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
|
||||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
|
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
|
||||||
),
|
),
|
||||||
|
|
|
@ -17,11 +17,26 @@ final class PhabricatorSlowvoteEditController
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$poll = new PhabricatorSlowvotePoll();
|
if ($this->id) {
|
||||||
$poll->setAuthorPHID($user->getPHID());
|
$poll = id(new PhabricatorSlowvoteQuery())
|
||||||
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
->setViewer($user)
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
|
if (!$poll) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
$is_new = false;
|
||||||
|
} else {
|
||||||
|
$poll = id(new PhabricatorSlowvotePoll())
|
||||||
|
->setAuthorPHID($user->getPHID())
|
||||||
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER);
|
||||||
$is_new = true;
|
$is_new = true;
|
||||||
|
}
|
||||||
|
|
||||||
$e_question = true;
|
$e_question = true;
|
||||||
$e_response = true;
|
$e_response = true;
|
||||||
|
@ -50,6 +65,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
$e_question = null;
|
$e_question = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($is_new) {
|
||||||
$responses = array_filter($responses);
|
$responses = array_filter($responses);
|
||||||
if (empty($responses)) {
|
if (empty($responses)) {
|
||||||
$errors[] = pht('You must offer at least one response.');
|
$errors[] = pht('You must offer at least one response.');
|
||||||
|
@ -57,6 +73,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
} else {
|
} else {
|
||||||
$e_response = null;
|
$e_response = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
$template = id(new PhabricatorSlowvoteTransaction());
|
$template = id(new PhabricatorSlowvoteTransaction());
|
||||||
|
@ -81,9 +98,11 @@ final class PhabricatorSlowvoteEditController
|
||||||
$editor = id(new PhabricatorSlowvoteEditor())
|
$editor = id(new PhabricatorSlowvoteEditor())
|
||||||
->setActor($user)
|
->setActor($user)
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContentSourceFromRequest($request)
|
->setContentSourceFromRequest($request);
|
||||||
->applyTransactions($poll, $xactions);
|
|
||||||
|
|
||||||
|
$xactions = $editor->applyTransactions($poll, $xactions);
|
||||||
|
|
||||||
|
if ($is_new) {
|
||||||
$poll->save();
|
$poll->save();
|
||||||
|
|
||||||
foreach ($responses as $response) {
|
foreach ($responses as $response) {
|
||||||
|
@ -92,6 +111,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
$option->setPollID($poll->getID());
|
$option->setPollID($poll->getID());
|
||||||
$option->save();
|
$option->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/V'.$poll->getID());
|
->setURI('/V'.$poll->getID());
|
||||||
|
@ -131,6 +151,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
->setName('description')
|
->setName('description')
|
||||||
->setValue($v_description));
|
->setValue($v_description));
|
||||||
|
|
||||||
|
if ($is_new) {
|
||||||
for ($ii = 0; $ii < 10; $ii++) {
|
for ($ii = 0; $ii < 10; $ii++) {
|
||||||
$n = ($ii + 1);
|
$n = ($ii + 1);
|
||||||
$response = id(new AphrontFormTextControl())
|
$response = id(new AphrontFormTextControl())
|
||||||
|
@ -144,6 +165,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
|
|
||||||
$form->appendChild($response);
|
$form->appendChild($response);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$poll_type_options = array(
|
$poll_type_options = array(
|
||||||
PhabricatorSlowvotePoll::METHOD_PLURALITY =>
|
PhabricatorSlowvotePoll::METHOD_PLURALITY =>
|
||||||
|
@ -161,13 +183,31 @@ final class PhabricatorSlowvoteEditController
|
||||||
=> pht('Only I can see the responses'),
|
=> pht('Only I can see the responses'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$form
|
if ($is_new) {
|
||||||
->appendChild(
|
$form->appendChild(
|
||||||
id(new AphrontFormSelectControl())
|
id(new AphrontFormSelectControl())
|
||||||
->setLabel(pht('Vote Type'))
|
->setLabel(pht('Vote Type'))
|
||||||
->setName('method')
|
->setName('method')
|
||||||
->setValue($poll->getMethod())
|
->setValue($poll->getMethod())
|
||||||
->setOptions($poll_type_options))
|
->setOptions($poll_type_options));
|
||||||
|
} else {
|
||||||
|
$form->appendChild(
|
||||||
|
id(new AphrontFormStaticControl())
|
||||||
|
->setLabel(pht('Vote Type'))
|
||||||
|
->setValue(idx($poll_type_options, $poll->getMethod())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_new) {
|
||||||
|
$title = pht('Create Slowvote');
|
||||||
|
$button = pht('Create');
|
||||||
|
$cancel_uri = $this->getApplicationURI();
|
||||||
|
} else {
|
||||||
|
$title = pht('Edit %s', 'V'.$poll->getID());
|
||||||
|
$button = pht('Save Changes');
|
||||||
|
$cancel_uri = '/V'.$poll->getID();
|
||||||
|
}
|
||||||
|
|
||||||
|
$form
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSelectControl())
|
id(new AphrontFormSelectControl())
|
||||||
->setLabel(pht('Responses'))
|
->setLabel(pht('Responses'))
|
||||||
|
@ -184,14 +224,13 @@ final class PhabricatorSlowvoteEditController
|
||||||
$v_shuffle))
|
$v_shuffle))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Create Slowvote'))
|
->setValue($button)
|
||||||
->addCancelButton('/vote/'));
|
->addCancelButton($cancel_uri));
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
|
||||||
$crumbs->addCrumb(
|
$crumbs->addCrumb(
|
||||||
id(new PhabricatorCrumbView())
|
id(new PhabricatorCrumbView())
|
||||||
->setName(pht('Create Slowvote'))
|
->setName($title));
|
||||||
->setHref($this->getApplicationURI().'create/'));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
array(
|
array(
|
||||||
|
@ -200,7 +239,7 @@ final class PhabricatorSlowvoteEditController
|
||||||
$form,
|
$form,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'title' => pht('Create Slowvote'),
|
'title' => $title,
|
||||||
'device' => true,
|
'device' => true,
|
||||||
'dust' => true,
|
'dust' => true,
|
||||||
));
|
));
|
||||||
|
|
|
@ -370,6 +370,19 @@ final class PhabricatorSlowvotePollController
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
->setObject($poll);
|
->setObject($poll);
|
||||||
|
|
||||||
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
|
$viewer,
|
||||||
|
$poll,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT);
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setName(pht('Edit Poll'))
|
||||||
|
->setIcon('edit')
|
||||||
|
->setHref($this->getApplicationURI('edit/'.$poll->getID().'/'))
|
||||||
|
->setDisabled(!$can_edit)
|
||||||
|
->setWorkflow(!$can_edit));
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,24 @@ final class PhabricatorSlowvoteEditor
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function transactionHasEffect(
|
||||||
|
PhabricatorLiskDAO $object,
|
||||||
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
|
$old = $xaction->getOldValue();
|
||||||
|
$new = $xaction->getNewValue();
|
||||||
|
|
||||||
|
switch ($xaction->getTransactionType()) {
|
||||||
|
case PhabricatorSlowvoteTransaction::TYPE_RESPONSES:
|
||||||
|
return ((int)$old !== (int)$new);
|
||||||
|
case PhabricatorSlowvoteTransaction::TYPE_SHUFFLE:
|
||||||
|
return ((bool)$old !== (bool)$new);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::transactionHasEffect($object, $xaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function getCustomTransactionOldValue(
|
protected function getCustomTransactionOldValue(
|
||||||
PhabricatorLiskDAO $object,
|
PhabricatorLiskDAO $object,
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
|
@ -114,5 +114,26 @@ final class PhabricatorSlowvoteTransaction
|
||||||
return parent::getColor();
|
return parent::getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasChangeDetails() {
|
||||||
|
switch ($this->getTransactionType()) {
|
||||||
|
case PhabricatorSlowvoteTransaction::TYPE_DESCRIPTION:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return parent::hasChangeDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderChangeDetails(PhabricatorUser $viewer) {
|
||||||
|
$old = $this->getOldValue();
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
$view = id(new PhabricatorApplicationTransactionTextDiffDetailView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->setOldText($old)
|
||||||
|
->setNewText($new);
|
||||||
|
|
||||||
|
return $view->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue