From 868ff166b109fb8d9eddd5aec2c226e3bf6170d9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 15 Jun 2014 10:28:16 -0700 Subject: [PATCH] Give Pholio mocks a configurable edit policy Summary: Ref T4566. Currently, mocks have a conservative (author only), immutable default edit policy. Instead: - Let the edit policy be changed. - Default the edit policy to "all users", similar to other applications. - Add an application-level setting for it. - Migrate existing edit policies to be consistent with the old policy (just the author). This stops short of adding a separate "owner" and letting that be changed, since Pholio doesn't really have any review/approve type features (at least, so far). We can look at doing this if we get more feedback about it, or if we make owners more meaningful (e.g., add more "review-like" process to mocks). Test Plan: - Ran migration scripts. - Confirmed existing mocks retained their effective policies (author only). - Created a new mock, saw edit policy. - Changed edit policy. - Changed global edit policy default. - Tried to edit a mock I couldn't edit. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T4566 Differential Revision: https://secure.phabricator.com/D9550 --- resources/celerity/map.php | 4 ++-- .../sql/autopatches/20140615.pholioedit.1.sql | 2 ++ .../sql/autopatches/20140615.pholioedit.2.sql | 2 ++ src/__phutil_library_map__.php | 2 ++ .../application/PhabricatorApplicationPholio.php | 4 ++-- .../capability/PholioCapabilityDefaultEdit.php | 16 ++++++++++++++++ .../controller/PholioMockEditController.php | 12 ++++++++++++ src/applications/pholio/storage/PholioMock.php | 7 +++++-- 8 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 resources/sql/autopatches/20140615.pholioedit.1.sql create mode 100644 resources/sql/autopatches/20140615.pholioedit.2.sql create mode 100644 src/applications/pholio/capability/PholioCapabilityDefaultEdit.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 6becec866f..0a7bec4047 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -81,7 +81,7 @@ return array( 'rsrc/css/application/phame/phame.css' => '19ecc703', 'rsrc/css/application/pholio/pholio-edit.css' => '90616955', 'rsrc/css/application/pholio/pholio-inline-comments.css' => '3d5a5590', - 'rsrc/css/application/pholio/pholio.css' => '5bd4c882', + 'rsrc/css/application/pholio/pholio.css' => 'e94312dd', 'rsrc/css/application/phortune/phortune-credit-card-form.css' => 'b25b4beb', 'rsrc/css/application/phrequent/phrequent.css' => 'ffc185ad', 'rsrc/css/application/phriction/phriction-document-css.css' => '7d7f0071', @@ -748,7 +748,7 @@ return array( 'phabricator-uiexample-reactor-sendproperties' => '551add57', 'phabricator-zindex-css' => 'efb673ac', 'phame-css' => '19ecc703', - 'pholio-css' => '5bd4c882', + 'pholio-css' => 'e94312dd', 'pholio-edit-css' => '90616955', 'pholio-inline-comments-css' => '3d5a5590', 'phortune-credit-card-form' => '2290aeef', diff --git a/resources/sql/autopatches/20140615.pholioedit.1.sql b/resources/sql/autopatches/20140615.pholioedit.1.sql new file mode 100644 index 0000000000..a3bcfe3e07 --- /dev/null +++ b/resources/sql/autopatches/20140615.pholioedit.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_pholio.pholio_mock + ADD editPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin; diff --git a/resources/sql/autopatches/20140615.pholioedit.2.sql b/resources/sql/autopatches/20140615.pholioedit.2.sql new file mode 100644 index 0000000000..42824467ba --- /dev/null +++ b/resources/sql/autopatches/20140615.pholioedit.2.sql @@ -0,0 +1,2 @@ +UPDATE {$NAMESPACE}_pholio.pholio_mock + SET editPolicy = authorPHID WHERE editPolicy = ''; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 629b852cb0..93b2bc9d19 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2405,6 +2405,7 @@ phutil_register_library_map(array( 'PhluxVariableQuery' => 'applications/phlux/query/PhluxVariableQuery.php', 'PhluxViewController' => 'applications/phlux/controller/PhluxViewController.php', 'PholioActionMenuEventListener' => 'applications/pholio/event/PholioActionMenuEventListener.php', + 'PholioCapabilityDefaultEdit' => 'applications/pholio/capability/PholioCapabilityDefaultEdit.php', 'PholioCapabilityDefaultView' => 'applications/pholio/capability/PholioCapabilityDefaultView.php', 'PholioConstants' => 'applications/pholio/constants/PholioConstants.php', 'PholioController' => 'applications/pholio/controller/PholioController.php', @@ -5303,6 +5304,7 @@ phutil_register_library_map(array( 'PhluxVariableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhluxViewController' => 'PhluxController', 'PholioActionMenuEventListener' => 'PhabricatorEventListener', + 'PholioCapabilityDefaultEdit' => 'PhabricatorPolicyCapability', 'PholioCapabilityDefaultView' => 'PhabricatorPolicyCapability', 'PholioController' => 'PhabricatorController', 'PholioDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/pholio/application/PhabricatorApplicationPholio.php b/src/applications/pholio/application/PhabricatorApplicationPholio.php index 9c7bdbdd96..51a3736f0b 100644 --- a/src/applications/pholio/application/PhabricatorApplicationPholio.php +++ b/src/applications/pholio/application/PhabricatorApplicationPholio.php @@ -72,8 +72,8 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication { protected function getCustomCapabilities() { return array( - PholioCapabilityDefaultView::CAPABILITY => array( - ), + PholioCapabilityDefaultView::CAPABILITY => array(), + PholioCapabilityDefaultEdit::CAPABILITY => array(), ); } diff --git a/src/applications/pholio/capability/PholioCapabilityDefaultEdit.php b/src/applications/pholio/capability/PholioCapabilityDefaultEdit.php new file mode 100644 index 0000000000..039892b40e --- /dev/null +++ b/src/applications/pholio/capability/PholioCapabilityDefaultEdit.php @@ -0,0 +1,16 @@ +getDescription(); $v_status = $mock->getStatus(); $v_view = $mock->getViewPolicy(); + $v_edit = $mock->getEditPolicy(); $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID( $mock->getPHID()); @@ -75,12 +76,14 @@ final class PholioMockEditController extends PholioController { $type_desc = PholioTransactionType::TYPE_DESCRIPTION; $type_status = PholioTransactionType::TYPE_STATUS; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; + $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; $type_cc = PhabricatorTransactions::TYPE_SUBSCRIBERS; $v_name = $request->getStr('name'); $v_desc = $request->getStr('description'); $v_status = $request->getStr('status'); $v_view = $request->getStr('can_view'); + $v_edit = $request->getStr('can_edit'); $v_cc = $request->getArr('cc'); $v_projects = $request->getArr('projects'); @@ -89,6 +92,7 @@ final class PholioMockEditController extends PholioController { $mock_xactions[$type_desc] = $v_desc; $mock_xactions[$type_status] = $v_status; $mock_xactions[$type_view] = $v_view; + $mock_xactions[$type_edit] = $v_edit; $mock_xactions[$type_cc] = array('=' => $v_cc); if (!strlen($request->getStr('name'))) { @@ -242,6 +246,7 @@ final class PholioMockEditController extends PholioController { // NOTE: Make this show up correctly on the rendered form. $mock->setViewPolicy($v_view); + $mock->setEditPolicy($v_edit); $handles = id(new PhabricatorHandleQuery()) ->setViewer($user) @@ -359,6 +364,13 @@ final class PholioMockEditController extends PholioController { ->setPolicyObject($mock) ->setPolicies($policies) ->setName('can_view')) + ->appendChild( + id(new AphrontFormPolicyControl()) + ->setUser($user) + ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) + ->setPolicyObject($mock) + ->setPolicies($policies) + ->setName('can_edit')) ->appendChild( id(new AphrontFormMarkupControl()) ->setValue($list_control)) diff --git a/src/applications/pholio/storage/PholioMock.php b/src/applications/pholio/storage/PholioMock.php index 02b2d3f103..e362341af2 100644 --- a/src/applications/pholio/storage/PholioMock.php +++ b/src/applications/pholio/storage/PholioMock.php @@ -14,6 +14,7 @@ final class PholioMock extends PholioDAO protected $authorPHID; protected $viewPolicy; + protected $editPolicy; protected $name; protected $originalName; @@ -34,11 +35,13 @@ final class PholioMock extends PholioDAO ->executeOne(); $view_policy = $app->getPolicy(PholioCapabilityDefaultView::CAPABILITY); + $edit_policy = $app->getPolicy(PholioCapabilityDefaultEdit::CAPABILITY); return id(new PholioMock()) ->setAuthorPHID($actor->getPHID()) ->attachImages(array()) - ->setViewPolicy($view_policy); + ->setViewPolicy($view_policy) + ->setEditPolicy($edit_policy); } public function getMonogram() { @@ -178,7 +181,7 @@ final class PholioMock extends PholioDAO case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: - return PhabricatorPolicies::POLICY_NOONE; + return $this->getEditPolicy(); } }