Index: src/__phutil_library_map__.php =================================================================== --- src/__phutil_library_map__.php +++ 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', Index: src/applications/slowvote/application/PhabricatorApplicationSlowvote.php =================================================================== --- src/applications/slowvote/application/PhabricatorApplicationSlowvote.php +++ 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.'), + ), + ); + } + } Index: src/applications/slowvote/capability/PhabricatorSlowvoteCapabilityDefaultView.php =================================================================== --- /dev/null +++ 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 @@ $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)); Index: src/applications/slowvote/storage/PhabricatorSlowvotePoll.php =================================================================== --- src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ 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,