diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9e5f9ace9d..222ad69b4d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1665,6 +1665,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 4256495c4a..a38519fdb9 100644 --- a/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php +++ b/src/applications/slowvote/application/PhabricatorApplicationSlowvote.php @@ -50,4 +50,12 @@ final class PhabricatorApplicationSlowvote extends PhabricatorApplication { ); } + 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 index 0000000000..4c5b1975df --- /dev/null +++ b/src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php @@ -0,0 +1,20 @@ +setAuthorPHID($user->getPHID()) - ->setViewPolicy(PhabricatorPolicies::POLICY_USER); + $poll = PhabricatorSlowvotePoll::initializeNewPoll($user); $is_new = true; } @@ -53,6 +51,7 @@ final class PhabricatorSlowvoteEditController $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 @@ final class PhabricatorSlowvoteEditController ->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 @@ final class PhabricatorSlowvoteEditController return id(new AphrontRedirectResponse()) ->setURI('/V'.$poll->getID()); + } else { + $poll->setViewPolicy($v_view_policy); } } @@ -206,6 +211,11 @@ final class PhabricatorSlowvoteEditController $cancel_uri = '/V'.$poll->getID(); } + $policies = id(new PhabricatorPolicyQuery()) + ->setViewer($user) + ->setObject($poll) + ->execute(); + $form ->appendChild( id(new AphrontFormSelectControl()) @@ -221,6 +231,13 @@ final class PhabricatorSlowvoteEditController 1, 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) diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php index 24700fd9c7..cd360de5e5 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -28,6 +28,20 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO 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,