1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Provide application and object level policy controls in Slowvote

Summary: Ref T603. Gives the create/edit interface a policy control, and adds an application-level default.

Test Plan: Created and edited polls.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7321
This commit is contained in:
epriestley 2013-10-16 10:36:00 -07:00
parent 8c1c6fec5a
commit e381022bc7
5 changed files with 64 additions and 3 deletions

View file

@ -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',

View file

@ -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.'),
),
);
}
}

View file

@ -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;
}
}

View file

@ -32,9 +32,7 @@ final class PhabricatorSlowvoteEditController
}
$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 @@ 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)

View file

@ -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,