Page MenuHomePhabricator

D7321.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
@@ -1665,6 +1665,7 @@
'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php',
'PhabricatorSetupIssueExample' => 'applications/uiexample/examples/PhabricatorSetupIssueExample.php',
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
+ 'PhabricatorSlowvoteCapabilityDefaultView' => 'applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php',
'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php',
'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php',
'PhabricatorSlowvoteCommentController' => 'applications/slowvote/controller/PhabricatorSlowvoteCommentController.php',
@@ -3876,6 +3877,7 @@
'PhabricatorSetupCheckTimezone' => 'PhabricatorSetupCheck',
'PhabricatorSetupIssueExample' => 'PhabricatorUIExample',
'PhabricatorSetupIssueView' => 'AphrontView',
+ 'PhabricatorSlowvoteCapabilityDefaultView' => 'PhabricatorPolicyCapability',
'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteCommentController' => 'PhabricatorSlowvoteController',
diff --git a/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php b/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
--- a/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
+++ b/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php
@@ -50,4 +50,12 @@
);
}
+ public function getCustomCapabilities() {
+ return array(
+ PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY => array(
+ 'caption' => pht('Default view policy for new polls.'),
+ ),
+ );
+ }
+
}
diff --git a/src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php b/src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php
new file mode 100644
--- /dev/null
+++ b/src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php
@@ -0,0 +1,20 @@
+<?php
+
+final class PhabricatorSlowvoteCapabilityDefaultView
+ extends PhabricatorPolicyCapability {
+
+ const CAPABILITY = 'slowvote.default.view';
+
+ public function getCapabilityKey() {
+ return self::CAPABILITY;
+ }
+
+ public function getCapabilityName() {
+ return pht('Default View Policy');
+ }
+
+ public function shouldAllowPublicPolicySetting() {
+ return true;
+ }
+
+}
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
@@ -32,9 +32,7 @@
}
$is_new = false;
} else {
- $poll = id(new PhabricatorSlowvotePoll())
- ->setAuthorPHID($user->getPHID())
- ->setViewPolicy(PhabricatorPolicies::POLICY_USER);
+ $poll = PhabricatorSlowvotePoll::initializeNewPoll($user);
$is_new = true;
}
@@ -53,6 +51,7 @@
$v_description = $request->getStr('description');
$v_responses = (int)$request->getInt('responses');
$v_shuffle = (int)$request->getBool('shuffle');
+ $v_view_policy = $request->getStr('viewPolicy');
if ($is_new) {
$poll->setMethod($request->getInt('method'));
@@ -94,6 +93,10 @@
->setTransactionType(PhabricatorSlowvoteTransaction::TYPE_SHUFFLE)
->setNewValue($v_shuffle);
+ $xactions[] = id(clone $template)
+ ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
+ ->setNewValue($v_view_policy);
+
if (empty($errors)) {
$editor = id(new PhabricatorSlowvoteEditor())
->setActor($user)
@@ -115,6 +118,8 @@
return id(new AphrontRedirectResponse())
->setURI('/V'.$poll->getID());
+ } else {
+ $poll->setViewPolicy($v_view_policy);
}
}
@@ -206,6 +211,11 @@
$cancel_uri = '/V'.$poll->getID();
}
+ $policies = id(new PhabricatorPolicyQuery())
+ ->setViewer($user)
+ ->setObject($poll)
+ ->execute();
+
$form
->appendChild(
id(new AphrontFormSelectControl())
@@ -222,6 +232,13 @@
pht('Show choices in random order.'),
$v_shuffle))
->appendChild(
+ id(new AphrontFormPolicyControl())
+ ->setUser($user)
+ ->setName('viewPolicy')
+ ->setPolicyObject($poll)
+ ->setPolicies($policies)
+ ->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
+ ->appendChild(
id(new AphrontFormSubmitControl())
->setValue($button)
->addCancelButton($cancel_uri));
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
@@ -28,6 +28,20 @@
private $choices = self::ATTACHABLE;
private $viewerChoices = self::ATTACHABLE;
+ public static function initializeNewPoll(PhabricatorUser $actor) {
+ $app = id(new PhabricatorApplicationQuery())
+ ->setViewer($actor)
+ ->withClasses(array('PhabricatorApplicationSlowvote'))
+ ->executeOne();
+
+ $view_policy = $app->getPolicy(
+ PhabricatorSlowvoteCapabilityDefaultView::CAPABILITY);
+
+ return id(new PhabricatorSlowvotePoll())
+ ->setAuthorPHID($actor->getPHID())
+ ->setViewPolicy($view_policy);
+ }
+
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/az/bt/htikawcndhfqegj4
Default Alt Text
D7321.diff (5 KB)

Event Timeline