From 953f95054f6049cb93b6561dce4347203dc09a18 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Wed, 21 May 2014 10:48:30 -0700 Subject: [PATCH] Allow dashboard panel policies to be edited Summary: Fixes T4982, expose dashboard panel policy editing to UI Test Plan: Create panel, verify that user can edit who can see and who can edit panel Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T4982 Differential Revision: https://secure.phabricator.com/D9238 --- ...habricatorDashboardPanelEditController.php | 38 ++++++++++++++++++- ...ricatorDashboardPanelTransactionEditor.php | 2 + 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php b/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php index 154f6f55df..1458cde0ad 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php @@ -66,16 +66,30 @@ final class PhabricatorDashboardPanelEditController ->readFieldsFromStorage($panel); $validation_exception = null; + if ($request->isFormPost()) { $v_name = $request->getStr('name'); + $v_view_policy = $request->getStr('viewPolicy'); + $v_edit_policy = $request->getStr('editPolicy'); + + $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; + $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; + $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; $xactions = array(); - $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; $xactions[] = id(new PhabricatorDashboardPanelTransaction()) ->setTransactionType($type_name) ->setNewValue($v_name); + $xactions[] = id(new PhabricatorDashboardPanelTransaction()) + ->setTransactionType($type_view_policy) + ->setNewValue($v_view_policy); + + $xactions[] = id(new PhabricatorDashboardPanelTransaction()) + ->setTransactionType($type_edit_policy) + ->setNewValue($v_edit_policy); + $field_xactions = $field_list->buildFieldTransactionsFromRequest( new PhabricatorDashboardPanelTransaction(), $request); @@ -94,9 +108,17 @@ final class PhabricatorDashboardPanelEditController $validation_exception = $ex; $e_name = $validation_exception->getShortMessage($type_name); + + $panel->setViewPolicy($v_view_policy); + $panel->setEditPolicy($v_edit_policy); } } + $policies = id(new PhabricatorPolicyQuery()) + ->setViewer($viewer) + ->setObject($panel) + ->execute(); + $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( @@ -104,7 +126,19 @@ final class PhabricatorDashboardPanelEditController ->setLabel(pht('Name')) ->setName('name') ->setValue($v_name) - ->setError($e_name)); + ->setError($e_name)) + ->appendChild( + id(new AphrontFormPolicyControl()) + ->setName('viewPolicy') + ->setPolicyObject($panel) + ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) + ->setPolicies($policies)) + ->appendChild( + id(new AphrontFormPolicyControl()) + ->setName('editPolicy') + ->setPolicyObject($panel) + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) + ->setPolicies($policies)); $field_list->appendFieldsToForm($form); diff --git a/src/applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php b/src/applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php index 15b32cedb0..de1299024d 100644 --- a/src/applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php +++ b/src/applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php @@ -63,6 +63,8 @@ final class PhabricatorDashboardPanelTransactionEditor switch ($xaction->getTransactionType()) { case PhabricatorDashboardPanelTransaction::TYPE_NAME: + case PhabricatorTransactions::TYPE_VIEW_POLICY: + case PhabricatorTransactions::TYPE_EDIT_POLICY: return; }