Page MenuHomePhabricator

D21843.diff
No OneTemporary

D21843.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -5872,6 +5872,7 @@
'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 @@
'SlowvoteConduitAPIMethod' => 'ConduitAPIMethod',
'SlowvoteEmbedView' => 'AphrontView',
'SlowvoteInfoConduitAPIMethod' => 'SlowvoteConduitAPIMethod',
+ 'SlowvotePollResponseVisibility' => 'Phobject',
'SlowvoteRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'SlowvoteSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'SubscriptionListDialogBuilder' => 'Phobject',
diff --git a/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
new file mode 100644
--- /dev/null
+++ b/src/applications/slowvote/constants/SlowvotePollResponseVisibility.php
@@ -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'),
+ ),
+ );
+ }
+
+}
diff --git a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
--- a/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
+++ b/src/applications/slowvote/controller/PhabricatorSlowvoteEditController.php
@@ -49,7 +49,7 @@
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 @@
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(
diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
--- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
+++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
@@ -13,17 +13,13 @@
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 @@
$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() {
diff --git a/src/applications/slowvote/view/SlowvoteEmbedView.php b/src/applications/slowvote/view/SlowvoteEmbedView.php
--- a/src/applications/slowvote/view/SlowvoteEmbedView.php
+++ b/src/applications/slowvote/view/SlowvoteEmbedView.php
@@ -77,14 +77,14 @@
$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 @@
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());
}
}
diff --git a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
--- a/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
+++ b/src/applications/slowvote/xaction/PhabricatorSlowvoteResponsesTransaction.php
@@ -6,7 +6,7 @@
const TRANSACTIONTYPE = 'vote:responses';
public function generateOldValue($object) {
- return (int)$object->getResponseVisibility();
+ return $object->getResponseVisibility();
}
public function applyInternalEffects($object, $value) {
@@ -14,18 +14,38 @@
}
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);
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, May 11, 6:16 AM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6284961
Default Alt Text
D21843.diff (9 KB)

Event Timeline