From 18336f0b9a9808866e2a32fc910707cd6e169dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taavi=20V=C3=A4=C3=A4n=C3=A4nen?= Date: Sun, 8 Dec 2024 12:35:26 +0200 Subject: [PATCH] Allow customizing default Phurl view and edit policies Summary: | Before | After | |----------|----------| |{F2669862}|{F2669861}| Closes T15970 Test Plan: * Go to http://phorge.localhost/applications/view/PhabricatorPhurlApplication/ and see two additional settings "Default View Policy" and "Default Edit Policy" * Go to http://phorge.localhost/applications/view/PhabricatorPhurlApplication/ and select "Edit Policies" to see and set two additional settings * Go to http://phorge.localhost/phurl/url/edit/form/default/ and check the "Visible To" and "Editable By" fields now showing the default page * Check existing Phurls which did not have their policies changed as that's stored in the database * run `arc liberate` again and see that it's already updated Reviewers: O1 Blessed Committers, aklapper, valerio.bozzolan Reviewed By: O1 Blessed Committers, aklapper, valerio.bozzolan Subscribers: aklapper, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15970 Differential Revision: https://we.phorge.it/D25850 --- src/__phutil_library_map__.php | 4 ++++ .../application/PhabricatorPhurlApplication.php | 9 +++++++++ .../PhabricatorPhurlURLDefaultEditCapability.php | 12 ++++++++++++ .../PhabricatorPhurlURLDefaultViewCapability.php | 16 ++++++++++++++++ .../phurl/storage/PhabricatorPhurlURL.php | 9 +++++++-- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/applications/phurl/capability/PhabricatorPhurlURLDefaultEditCapability.php create mode 100644 src/applications/phurl/capability/PhabricatorPhurlURLDefaultViewCapability.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3169314815..e1b649ce36 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4262,6 +4262,8 @@ phutil_register_library_map(array( 'PhabricatorPhurlURLAliasTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLAliasTransaction.php', 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 'PhabricatorPhurlURLDatasource' => 'applications/phurl/typeahead/PhabricatorPhurlURLDatasource.php', + 'PhabricatorPhurlURLDefaultEditCapability' => 'applications/phurl/capability/PhabricatorPhurlURLDefaultEditCapability.php', + 'PhabricatorPhurlURLDefaultViewCapability' => 'applications/phurl/capability/PhabricatorPhurlURLDefaultViewCapability.php', 'PhabricatorPhurlURLDescriptionTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLDescriptionTransaction.php', 'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php', 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', @@ -10866,6 +10868,8 @@ phutil_register_library_map(array( 'PhabricatorPhurlURLAliasTransaction' => 'PhabricatorPhurlURLTransactionType', 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 'PhabricatorPhurlURLDatasource' => 'PhabricatorTypeaheadDatasource', + 'PhabricatorPhurlURLDefaultEditCapability' => 'PhabricatorPolicyCapability', + 'PhabricatorPhurlURLDefaultViewCapability' => 'PhabricatorPolicyCapability', 'PhabricatorPhurlURLDescriptionTransaction' => 'PhabricatorPhurlURLTransactionType', 'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php index 56290ef5e1..e7ffa0e744 100644 --- a/src/applications/phurl/application/PhabricatorPhurlApplication.php +++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php @@ -73,6 +73,15 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication { PhabricatorPhurlURLCreateCapability::CAPABILITY => array( 'default' => PhabricatorPolicies::POLICY_USER, ), + PhabricatorPhurlURLDefaultViewCapability::CAPABILITY => array( + 'template' => PhabricatorPhurlURLPHIDType::TYPECONST, + 'capability' => PhabricatorPolicyCapability::CAN_VIEW, + ), + PhabricatorPhurlURLDefaultEditCapability::CAPABILITY => array( + 'default' => PhabricatorPolicies::POLICY_USER, + 'template' => PhabricatorPhurlURLPHIDType::TYPECONST, + 'capability' => PhabricatorPolicyCapability::CAN_EDIT, + ), ); } diff --git a/src/applications/phurl/capability/PhabricatorPhurlURLDefaultEditCapability.php b/src/applications/phurl/capability/PhabricatorPhurlURLDefaultEditCapability.php new file mode 100644 index 0000000000..86ed740466 --- /dev/null +++ b/src/applications/phurl/capability/PhabricatorPhurlURLDefaultEditCapability.php @@ -0,0 +1,12 @@ +withClasses(array('PhabricatorPhurlApplication')) ->executeOne(); + $view_policy = $app->getPolicy( + PhabricatorPhurlURLDefaultViewCapability::CAPABILITY); + $edit_policy = $app->getPolicy( + PhabricatorPhurlURLDefaultEditCapability::CAPABILITY); + return id(new PhabricatorPhurlURL()) ->setAuthorPHID($actor->getPHID()) - ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) - ->setEditPolicy($actor->getPHID()) + ->setViewPolicy($view_policy) + ->setEditPolicy($edit_policy) ->setSpacePHID($actor->getDefaultSpacePHID()); }