Allow projects to be set as policies
Summary: - Renames `PhabricatorPolicyQuery` to `PhabricatorPolicyAwareQuery` (a query which respects policy settings). - Introduces `PhabricatorPolicyQuery`, which loads available policies (e.g., "member of project X"). - Introduces `PhabricatorPolicy`, which describes a policy. - Allows projects to be set as policies. - Allows Paste policies to be edited. - Covers crazy cases where you make projects depend on themselves or each other because you are a dastardly villan. Test Plan: Set paste and project policies, including crazy policies like A -> B -> A, A -> A, etc. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D3476
This commit is contained in:
@@ -87,6 +87,10 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||
|
||||
$paste->setTitle($request->getStr('title'));
|
||||
$paste->setLanguage($request->getStr('language'));
|
||||
$paste->setViewPolicy($request->getStr('can_view'));
|
||||
|
||||
// NOTE: The author is the only editor and can always view the paste,
|
||||
// so it's impossible for them to choose an invalid policy.
|
||||
|
||||
if (!$errors) {
|
||||
if ($is_create) {
|
||||
@@ -139,6 +143,19 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||
->setValue($paste->getLanguage())
|
||||
->setOptions($langs));
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($user)
|
||||
->setObject($paste)
|
||||
->execute();
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setUser($user)
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($paste)
|
||||
->setPolicies($policies)
|
||||
->setName('can_view'));
|
||||
|
||||
if ($is_create) {
|
||||
$form
|
||||
->appendChild(
|
||||
@@ -151,16 +168,6 @@ final class PhabricatorPasteEditController extends PhabricatorPasteController {
|
||||
->setName('text'));
|
||||
}
|
||||
|
||||
/* TODO: Doesn't have any useful options yet.
|
||||
->appendChild(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setLabel('Visible To')
|
||||
->setUser($user)
|
||||
->setValue(
|
||||
$new_paste->getPolicy(PhabricatorPolicyCapability::CAN_VIEW))
|
||||
->setName('policy'))
|
||||
*/
|
||||
|
||||
$submit = new AphrontFormSubmitControl();
|
||||
|
||||
if (!$is_create) {
|
||||
|
||||
Reference in New Issue
Block a user