mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
Move Slowvote response visibility to a separate object
Summary: Ref T13682. This change supports modifying these constants to be sensible strings instead of opaque integers. Test Plan: Created and edited polls. Maniphest Tasks: T13682 Differential Revision: https://secure.phabricator.com/D21843
This commit is contained in:
parent
b1533e5468
commit
23094b4950
6 changed files with 126 additions and 32 deletions
|
@ -5872,6 +5872,7 @@ phutil_register_library_map(array(
|
|||
'SlowvoteConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteConduitAPIMethod.php',
|
||||
'SlowvoteEmbedView' => 'applications/slowvote/view/SlowvoteEmbedView.php',
|
||||
'SlowvoteInfoConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteInfoConduitAPIMethod.php',
|
||||
'SlowvotePollResponseVisibility' => 'applications/slowvote/constants/SlowvotePollResponseVisibility.php',
|
||||
'SlowvoteRemarkupRule' => 'applications/slowvote/remarkup/SlowvoteRemarkupRule.php',
|
||||
'SlowvoteSearchConduitAPIMethod' => 'applications/slowvote/conduit/SlowvoteSearchConduitAPIMethod.php',
|
||||
'SubscriptionListDialogBuilder' => 'applications/subscriptions/view/SubscriptionListDialogBuilder.php',
|
||||
|
@ -12773,6 +12774,7 @@ phutil_register_library_map(array(
|
|||
'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod',
|
||||
'SlowvoteEmbedView' => 'AphrontView',
|
||||
'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod',
|
||||
'SlowvotePollResponseVisibility' => 'Phobject',
|
||||
'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||
'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'SubscriptionListDialogBuilder' => 'Phobject',
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
final class SlowvotePollResponseVisibility
|
||||
extends Phobject {
|
||||
|
||||
const RESPONSES_VISIBLE = 0;
|
||||
const RESPONSES_VOTERS = 1;
|
||||
const RESPONSES_OWNER = 2;
|
||||
|
||||
private $key;
|
||||
|
||||
public static function newResponseVisibilityObject($key) {
|
||||
$object = new self();
|
||||
$object->key = $key;
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getKey() {
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$map = self::getMap();
|
||||
|
||||
$result = array();
|
||||
foreach ($map as $key => $spec) {
|
||||
$result[$key] = self::newResponseVisibilityObject($key);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
$name = $this->getProperty('name');
|
||||
|
||||
if ($name === null) {
|
||||
$name = pht('Unknown ("%s")', $this->getKey());
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
public function getNameForEdit() {
|
||||
$name = $this->getProperty('name.edit');
|
||||
|
||||
if ($name === null) {
|
||||
$name = pht('Unknown ("%s")', $this->getKey());
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
private function getProperty($key, $default = null) {
|
||||
$spec = idx(self::getMap(), $this->getKey());
|
||||
return idx($spec, $key, $default);
|
||||
}
|
||||
|
||||
private static function getMap() {
|
||||
return array(
|
||||
self::RESPONSES_VISIBLE => array(
|
||||
'name' => pht('Always Visible'),
|
||||
'name.edit' => pht('Anyone can see the responses'),
|
||||
),
|
||||
self::RESPONSES_VOTERS => array(
|
||||
'name' => pht('Voters'),
|
||||
'name.edit' => pht('Require a vote to see the responses'),
|
||||
),
|
||||
self::RESPONSES_OWNER => array(
|
||||
'name' => pht('Owner'),
|
||||
'name.edit' => pht('Only the poll owner can see the responses'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ final class PhabricatorSlowvoteEditController
|
|||
if ($request->isFormPost()) {
|
||||
$v_question = $request->getStr('question');
|
||||
$v_description = $request->getStr('description');
|
||||
$v_responses = (int)$request->getInt('responses');
|
||||
$v_responses = $request->getStr('responses');
|
||||
$v_shuffle = (int)$request->getBool('shuffle');
|
||||
$v_view_policy = $request->getStr('viewPolicy');
|
||||
$v_projects = $request->getArr('projects');
|
||||
|
@ -196,14 +196,8 @@ final class PhabricatorSlowvoteEditController
|
|||
pht('Approval (Multiple Choice)'),
|
||||
);
|
||||
|
||||
$response_type_options = array(
|
||||
PhabricatorSlowvotePoll::RESPONSES_VISIBLE
|
||||
=> pht('Allow anyone to see the responses'),
|
||||
PhabricatorSlowvotePoll::RESPONSES_VOTERS
|
||||
=> pht('Require a vote to see the responses'),
|
||||
PhabricatorSlowvotePoll::RESPONSES_OWNER
|
||||
=> pht('Only I can see the responses'),
|
||||
);
|
||||
$response_type_map = SlowvotePollResponseVisibility::getAll();
|
||||
$response_type_options = mpull($response_type_map, 'getNameForEdit');
|
||||
|
||||
if ($is_new) {
|
||||
$form->appendChild(
|
||||
|
|
|
@ -13,17 +13,13 @@ final class PhabricatorSlowvotePoll
|
|||
PhabricatorSpacesInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
|
||||
const RESPONSES_VISIBLE = 0;
|
||||
const RESPONSES_VOTERS = 1;
|
||||
const RESPONSES_OWNER = 2;
|
||||
|
||||
const METHOD_PLURALITY = 0;
|
||||
const METHOD_APPROVAL = 1;
|
||||
|
||||
protected $question;
|
||||
protected $description;
|
||||
protected $authorPHID;
|
||||
protected $responseVisibility = 0;
|
||||
protected $responseVisibility;
|
||||
protected $shuffle = 0;
|
||||
protected $method;
|
||||
protected $viewPolicy;
|
||||
|
@ -43,10 +39,13 @@ final class PhabricatorSlowvotePoll
|
|||
$view_policy = $app->getPolicy(
|
||||
PhabricatorSlowvoteDefaultViewCapability::CAPABILITY);
|
||||
|
||||
$default_responses = SlowvotePollResponseVisibility::RESPONSES_VISIBLE;
|
||||
|
||||
return id(new PhabricatorSlowvotePoll())
|
||||
->setAuthorPHID($actor->getPHID())
|
||||
->setViewPolicy($view_policy)
|
||||
->setSpacePHID($actor->getDefaultSpacePHID());
|
||||
->setSpacePHID($actor->getDefaultSpacePHID())
|
||||
->setResponseVisibility($default_responses);
|
||||
}
|
||||
|
||||
protected function getConfiguration() {
|
||||
|
|
|
@ -77,14 +77,14 @@ final class SlowvoteEmbedView extends AphrontView {
|
|||
|
||||
$vis = $poll->getResponseVisibility();
|
||||
if ($this->areResultsVisible()) {
|
||||
if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) {
|
||||
if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
|
||||
$quip = pht('Only you can see the results.');
|
||||
} else {
|
||||
$quip = pht('Voting improves cardiovascular endurance.');
|
||||
}
|
||||
} else if ($vis == PhabricatorSlowvotePoll::RESPONSES_VOTERS) {
|
||||
} else if ($vis == SlowvotePollResponseVisibility::RESPONSES_VOTERS) {
|
||||
$quip = pht('You must vote to see the results.');
|
||||
} else if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) {
|
||||
} else if ($vis == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
|
||||
$quip = pht('Only the author can see the results.');
|
||||
}
|
||||
|
||||
|
@ -321,15 +321,19 @@ final class SlowvoteEmbedView extends AphrontView {
|
|||
private function areResultsVisible() {
|
||||
$poll = $this->getPoll();
|
||||
|
||||
$vis = $poll->getResponseVisibility();
|
||||
if ($vis == PhabricatorSlowvotePoll::RESPONSES_VISIBLE) {
|
||||
$visibility = $poll->getResponseVisibility();
|
||||
if ($visibility == SlowvotePollResponseVisibility::RESPONSES_VISIBLE) {
|
||||
return true;
|
||||
} else if ($vis == PhabricatorSlowvotePoll::RESPONSES_OWNER) {
|
||||
return ($poll->getAuthorPHID() == $this->getUser()->getPHID());
|
||||
} else {
|
||||
$choices = mgroup($poll->getChoices(), 'getAuthorPHID');
|
||||
return (bool)idx($choices, $this->getUser()->getPHID());
|
||||
}
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
if ($visibility == SlowvotePollResponseVisibility::RESPONSES_OWNER) {
|
||||
return ($poll->getAuthorPHID() === $viewer->getPHID());
|
||||
}
|
||||
|
||||
$choices = mgroup($poll->getChoices(), 'getAuthorPHID');
|
||||
return (bool)idx($choices, $viewer->getPHID());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ final class PhabricatorSlowvoteResponsesTransaction
|
|||
const TRANSACTIONTYPE = 'vote:responses';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return (int)$object->getResponseVisibility();
|
||||
return $object->getResponseVisibility();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
|
@ -14,18 +14,38 @@ final class PhabricatorSlowvoteResponsesTransaction
|
|||
}
|
||||
|
||||
public function getTitle() {
|
||||
// TODO: This could be more detailed
|
||||
$old_name = $this->getOldResponseVisibilityObject()->getName();
|
||||
$new_name = $this->getNewResponseVisibilityObject()->getName();
|
||||
|
||||
return pht(
|
||||
'%s changed who can see the responses.',
|
||||
$this->renderAuthor());
|
||||
'%s changed who can see the responses from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderValue($old_name),
|
||||
$this->renderValue($new_name));
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
// TODO: This could be more detailed
|
||||
$old_name = $this->getOldResponseVisibilityObject()->getName();
|
||||
$new_name = $this->getNewResponseVisibilityObject()->getName();
|
||||
|
||||
return pht(
|
||||
'%s changed who can see the responses of %s.',
|
||||
'%s changed who can see the responses of %s from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
$this->renderObject(),
|
||||
$this->renderValue($old_name),
|
||||
$this->renderValue($new_name));
|
||||
}
|
||||
|
||||
private function getOldResponseVisibilityObject() {
|
||||
return $this->newResponseVisibilityObject($this->getOldValue());
|
||||
}
|
||||
|
||||
private function getNewResponseVisibilityObject() {
|
||||
return $this->newResponseVisibilityObject($this->getNewValue());
|
||||
}
|
||||
|
||||
private function newResponseVisibilityObject($value) {
|
||||
return SlowvotePollResponseVisibility::newResponseVisibilityObject($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue