1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

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
This commit is contained in:
Taavi Väänänen 2024-12-08 12:35:26 +02:00
parent 4accca8420
commit 18336f0b9a
No known key found for this signature in database
GPG key ID: EF242F709F912FBE
5 changed files with 48 additions and 2 deletions

View file

@ -4262,6 +4262,8 @@ phutil_register_library_map(array(
'PhabricatorPhurlURLAliasTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLAliasTransaction.php', 'PhabricatorPhurlURLAliasTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLAliasTransaction.php',
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
'PhabricatorPhurlURLDatasource' => 'applications/phurl/typeahead/PhabricatorPhurlURLDatasource.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', 'PhabricatorPhurlURLDescriptionTransaction' => 'applications/phurl/xaction/PhabricatorPhurlURLDescriptionTransaction.php',
'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php', 'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
@ -10866,6 +10868,8 @@ phutil_register_library_map(array(
'PhabricatorPhurlURLAliasTransaction' => 'PhabricatorPhurlURLTransactionType', 'PhabricatorPhurlURLAliasTransaction' => 'PhabricatorPhurlURLTransactionType',
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPhurlURLDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorPhurlURLDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorPhurlURLDefaultEditCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPhurlURLDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPhurlURLDescriptionTransaction' => 'PhabricatorPhurlURLTransactionType', 'PhabricatorPhurlURLDescriptionTransaction' => 'PhabricatorPhurlURLTransactionType',
'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',

View file

@ -73,6 +73,15 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication {
PhabricatorPhurlURLCreateCapability::CAPABILITY => array( PhabricatorPhurlURLCreateCapability::CAPABILITY => array(
'default' => PhabricatorPolicies::POLICY_USER, '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,
),
); );
} }

View file

@ -0,0 +1,12 @@
<?php
final class PhabricatorPhurlURLDefaultEditCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'phurl.url.default.edit';
public function getCapabilityName() {
return pht('Default Edit Policy');
}
}

View file

@ -0,0 +1,16 @@
<?php
final class PhabricatorPhurlURLDefaultViewCapability
extends PhabricatorPolicyCapability {
const CAPABILITY = 'phurl.url.default.view';
public function getCapabilityName() {
return pht('Default View Policy');
}
public function shouldAllowPublicPolicySetting() {
return true;
}
}

View file

@ -34,10 +34,15 @@ final class PhabricatorPhurlURL extends PhabricatorPhurlDAO
->withClasses(array('PhabricatorPhurlApplication')) ->withClasses(array('PhabricatorPhurlApplication'))
->executeOne(); ->executeOne();
$view_policy = $app->getPolicy(
PhabricatorPhurlURLDefaultViewCapability::CAPABILITY);
$edit_policy = $app->getPolicy(
PhabricatorPhurlURLDefaultEditCapability::CAPABILITY);
return id(new PhabricatorPhurlURL()) return id(new PhabricatorPhurlURL())
->setAuthorPHID($actor->getPHID()) ->setAuthorPHID($actor->getPHID())
->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) ->setViewPolicy($view_policy)
->setEditPolicy($actor->getPHID()) ->setEditPolicy($edit_policy)
->setSpacePHID($actor->getDefaultSpacePHID()); ->setSpacePHID($actor->getDefaultSpacePHID());
} }