mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 06:42:42 +01:00
Dashboards: add capability who can create Dashboards
Summary: Add a `dashboard.create` capability to allow limiting dashboard creation (and creation of related panels). This can reduce spam in open Phorge installations in which anyone can create an account while you still want anyone to be able to view existing dashboards. Closes T15438 Test Plan: 1. As an admin, go to `/applications/view/PhabricatorDashboardApplication/` 2. See only two options "Can Use Application: All Users" and "Can Configure Application: Administrators" 3. Apply patch 4. As an admin, go to `/applications/view/PhabricatorDashboardApplication/` and see the new option "Can Create Dashboards" set to "All Users" 5. As an average user, go to `/dashboard/` and successfully create a new Dashboard 6. As an admin, go to `/applications/edit/PhabricatorDashboardApplication/` and change "Can Create Dashboards" from "All Users" to "Administrators", select "Save Policies" button 7. As an average user, go to `/dashboard/` and see that "Create Dashboard" is disabled 8. As an average user, go to an existing dashboard not created by this user and see that selecting "Edit Dashboard" shows "You do not have permission to edit this object." 9. As an average user, go to the existing dashboard that you created yourself and see that the Edit Policy is set to this user. 10. As an average user, go to the existing dashboard that you created yourself and see that you can still create or add panels. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15438 Differential Revision: https://we.phorge.it/D25270
This commit is contained in:
parent
324470e39b
commit
1c59b65421
4 changed files with 31 additions and 0 deletions
|
@ -3081,6 +3081,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDashboardColumn' => 'applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php',
|
||||
'PhabricatorDashboardConsoleController' => 'applications/dashboard/controller/PhabricatorDashboardConsoleController.php',
|
||||
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
|
||||
'PhabricatorDashboardCreateCapability' => 'applications/countdown/capability/PhabricatorDashboardCreateCapability.php',
|
||||
'PhabricatorDashboardDAO' => 'applications/dashboard/storage/PhabricatorDashboardDAO.php',
|
||||
'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php',
|
||||
'PhabricatorDashboardDatasource' => 'applications/dashboard/typeahead/PhabricatorDashboardDatasource.php',
|
||||
|
@ -9496,6 +9497,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDashboardColumn' => 'Phobject',
|
||||
'PhabricatorDashboardConsoleController' => 'PhabricatorDashboardController',
|
||||
'PhabricatorDashboardController' => 'PhabricatorController',
|
||||
'PhabricatorDashboardCreateCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorDashboardDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorDashboardDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDashboardCreateCapability
|
||||
extends PhabricatorPolicyCapability {
|
||||
|
||||
const CAPABILITY = 'dashboard.create';
|
||||
|
||||
public function getCapabilityName() {
|
||||
return pht('Can Create Dashboards');
|
||||
}
|
||||
|
||||
public function describeCapabilityRejection() {
|
||||
return pht('You do not have permission to create a dashboard.');
|
||||
}
|
||||
|
||||
}
|
|
@ -83,4 +83,12 @@ final class PhabricatorDashboardApplication extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
protected function getCustomCapabilities() {
|
||||
return array(
|
||||
PhabricatorDashboardCreateCapability::CAPABILITY => array(
|
||||
'default' => PhabricatorPolicies::POLICY_USER,
|
||||
'caption' => pht('Default create policy for Dashboards.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,11 @@ final class PhabricatorDashboardEditEngine
|
|||
return $object->getURI();
|
||||
}
|
||||
|
||||
protected function getCreateNewObjectPolicy() {
|
||||
return $this->getApplication()->getPolicy(
|
||||
PhabricatorDashboardCreateCapability::CAPABILITY);
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
$layout_options = PhabricatorDashboardLayoutMode::getLayoutModeMap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue