1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +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:
epriestley 2013-07-15 11:07:37 -07:00
parent aa2e6d1e5a
commit 84d157f16a
5 changed files with 129 additions and 37 deletions

View file

@ -43,6 +43,7 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication {
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorSlowvoteListController',
'create/' => 'PhabricatorSlowvoteEditController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteEditController',
'(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteVoteController',
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorSlowvoteCommentController',
),

View file

@ -17,11 +17,26 @@ final class PhabricatorSlowvoteEditController
$request = $this->getRequest();
$user = $request->getUser();
$poll = new PhabricatorSlowvotePoll();
$poll->setAuthorPHID($user->getPHID());
$poll->setViewPolicy(PhabricatorPolicies::POLICY_USER);
if ($this->id) {
$poll = id(new PhabricatorSlowvoteQuery())
->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;
}
$e_question = true;
$e_response = true;
@ -50,6 +65,7 @@ final class PhabricatorSlowvoteEditController
$e_question = null;
}
if ($is_new) {
$responses = array_filter($responses);
if (empty($responses)) {
$errors[] = pht('You must offer at least one response.');
@ -57,6 +73,7 @@ final class PhabricatorSlowvoteEditController
} else {
$e_response = null;
}
}
$xactions = array();
$template = id(new PhabricatorSlowvoteTransaction());
@ -81,9 +98,11 @@ final class PhabricatorSlowvoteEditController
$editor = id(new PhabricatorSlowvoteEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->applyTransactions($poll, $xactions);
->setContentSourceFromRequest($request);
$xactions = $editor->applyTransactions($poll, $xactions);
if ($is_new) {
$poll->save();
foreach ($responses as $response) {
@ -92,6 +111,7 @@ final class PhabricatorSlowvoteEditController
$option->setPollID($poll->getID());
$option->save();
}
}
return id(new AphrontRedirectResponse())
->setURI('/V'.$poll->getID());
@ -131,6 +151,7 @@ final class PhabricatorSlowvoteEditController
->setName('description')
->setValue($v_description));
if ($is_new) {
for ($ii = 0; $ii < 10; $ii++) {
$n = ($ii + 1);
$response = id(new AphrontFormTextControl())
@ -144,6 +165,7 @@ final class PhabricatorSlowvoteEditController
$form->appendChild($response);
}
}
$poll_type_options = array(
PhabricatorSlowvotePoll::METHOD_PLURALITY =>
@ -161,13 +183,31 @@ final class PhabricatorSlowvoteEditController
=> pht('Only I can see the responses'),
);
$form
->appendChild(
if ($is_new) {
$form->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Vote Type'))
->setName('method')
->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(
id(new AphrontFormSelectControl())
->setLabel(pht('Responses'))
@ -184,14 +224,13 @@ final class PhabricatorSlowvoteEditController
$v_shuffle))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Create Slowvote'))
->addCancelButton('/vote/'));
->setValue($button)
->addCancelButton($cancel_uri));
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Create Slowvote'))
->setHref($this->getApplicationURI().'create/'));
->setName($title));
return $this->buildApplicationPage(
array(
@ -200,7 +239,7 @@ final class PhabricatorSlowvoteEditController
$form,
),
array(
'title' => pht('Create Slowvote'),
'title' => $title,
'device' => true,
'dust' => true,
));

View file

@ -370,6 +370,19 @@ final class PhabricatorSlowvotePollController
->setUser($viewer)
->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;
}

View file

@ -17,6 +17,24 @@ final class PhabricatorSlowvoteEditor
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(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {

View file

@ -114,5 +114,26 @@ final class PhabricatorSlowvoteTransaction
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();
}
}