Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15382585
D9508.id22784.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D9508.id22784.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1475,6 +1475,7 @@
'PhabricatorDashboard' => 'applications/dashboard/storage/PhabricatorDashboard.php',
'PhabricatorDashboardAddPanelController' => 'applications/dashboard/controller/PhabricatorDashboardAddPanelController.php',
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
+ 'PhabricatorDashboardCopyController' => 'applications/dashboard/controller/PhabricatorDashboardCopyController.php',
'PhabricatorDashboardDAO' => 'applications/dashboard/storage/PhabricatorDashboardDAO.php',
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/PhabricatorDashboardEditController.php',
'PhabricatorDashboardHistoryController' => 'applications/dashboard/controller/PhabricatorDashboardHistoryController.php',
@@ -4291,6 +4292,7 @@
),
'PhabricatorDashboardAddPanelController' => 'PhabricatorDashboardController',
'PhabricatorDashboardController' => 'PhabricatorController',
+ 'PhabricatorDashboardCopyController' => 'PhabricatorDashboardController',
'PhabricatorDashboardDAO' => 'PhabricatorLiskDAO',
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
'PhabricatorDashboardHistoryController' => 'PhabricatorDashboardController',
diff --git a/src/applications/dashboard/application/PhabricatorApplicationDashboard.php b/src/applications/dashboard/application/PhabricatorApplicationDashboard.php
--- a/src/applications/dashboard/application/PhabricatorApplicationDashboard.php
+++ b/src/applications/dashboard/application/PhabricatorApplicationDashboard.php
@@ -24,6 +24,7 @@
'manage/(?P<id>\d+)/' => 'PhabricatorDashboardManageController',
'history/(?P<id>\d+)/' => 'PhabricatorDashboardHistoryController',
'create/' => 'PhabricatorDashboardEditController',
+ 'copy/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardCopyController',
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardEditController',
'install/(?P<id>\d+)/' => 'PhabricatorDashboardInstallController',
'uninstall/(?P<id>\d+)/' => 'PhabricatorDashboardUninstallController',
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardCopyController.php b/src/applications/dashboard/controller/PhabricatorDashboardCopyController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/controller/PhabricatorDashboardCopyController.php
@@ -0,0 +1,68 @@
+<?php
+
+final class PhabricatorDashboardCopyController
+ extends PhabricatorDashboardController {
+
+ private $id;
+
+ public function willProcessRequest(array $data) {
+ $this->id = idx($data, 'id');
+ }
+
+ public function processRequest() {
+ $request = $this->getRequest();
+ $viewer = $request->getUser();
+
+ $dashboard = id(new PhabricatorDashboardQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($this->id))
+ ->needPanels(true)
+ ->executeOne();
+ if (!$dashboard) {
+ return new Aphront404Response();
+ }
+
+ $manage_uri = $this->getApplicationURI('manage/'.$dashboard->getID().'/');
+
+ if ($request->isFormPost()) {
+
+ $copy = PhabricatorDashboard::initializeNewDashboard($viewer);
+ $copy = PhabricatorDashboard::copyDashboard($copy, $dashboard);
+
+ $copy->setName(pht('Copy of %s', $copy->getName()));
+
+ // Set up all the edges for the new dashboard.
+
+ $xactions = array();
+ $xactions[] = id(new PhabricatorDashboardTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
+ ->setMetadataValue(
+ 'edge:type',
+ PhabricatorEdgeConfig::TYPE_DASHBOARD_HAS_PANEL)
+ ->setNewValue(
+ array(
+ '=' => array_fuse($dashboard->getPanelPHIDs()),
+ ));
+
+ $editor = id(new PhabricatorDashboardTransactionEditor())
+ ->setActor($viewer)
+ ->setContentSourceFromRequest($request)
+ ->setContinueOnMissingFields(true)
+ ->setContinueOnNoEffect(true)
+ ->applyTransactions($copy, $xactions);
+
+ $manage_uri = $this->getApplicationURI('edit/'.$copy->getID().'/');
+ return id(new AphrontRedirectResponse())->setURI($manage_uri);
+ }
+
+ return $this->newDialog()
+ ->setTitle(pht('Copy Dashboard'))
+ ->appendParagraph(
+ pht(
+ 'Create a copy of the dashboard "%s"?',
+ phutil_tag('strong', array(), $dashboard->getName())))
+ ->addCancelButton($manage_uri)
+ ->addSubmitButton(pht('Create Copy'));
+ }
+
+}
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardManageController.php b/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
--- a/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
+++ b/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
@@ -28,6 +28,11 @@
return new Aphront404Response();
}
+ $can_edit = PhabricatorPolicyFilter::hasCapability(
+ $viewer,
+ $dashboard,
+ PhabricatorPolicyCapability::CAN_EDIT);
+
$title = $dashboard->getName();
$crumbs = $this->buildApplicationCrumbs();
@@ -45,10 +50,21 @@
->setHeader($header)
->addPropertyList($properties);
+ if (!$can_edit) {
+ $no_edit = pht(
+ 'You do not have permission to edit this dashboard. If you want to '.
+ 'make changes, make a copy first.');
+
+ $box->setErrorView(
+ id(new AphrontErrorView())
+ ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
+ ->setErrors(array($no_edit)));
+ }
+
$rendered_dashboard = id(new PhabricatorDashboardRenderingEngine())
->setViewer($viewer)
->setDashboard($dashboard)
- ->setArrangeMode(true)
+ ->setArrangeMode($can_edit)
->renderDashboard();
return $this->buildApplicationPage(
@@ -93,6 +109,13 @@
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName(pht('Copy Dashboard'))
+ ->setIcon('fa-files-o')
+ ->setHref($this->getApplicationURI("copy/{$id}/"))
+ ->setWorkflow(true));
+
$installed_dashboard = id(new PhabricatorDashboardInstall())
->loadOneWhere(
'objectPHID = %s AND applicationClass = %s',
diff --git a/src/applications/dashboard/storage/PhabricatorDashboard.php b/src/applications/dashboard/storage/PhabricatorDashboard.php
--- a/src/applications/dashboard/storage/PhabricatorDashboard.php
+++ b/src/applications/dashboard/storage/PhabricatorDashboard.php
@@ -23,6 +23,16 @@
->attachPanelPHIDs(array());
}
+ public static function copyDashboard(
+ PhabricatorDashboard $dst,
+ PhabricatorDashboard $src) {
+
+ $dst->name = $src->name;
+ $dst->layoutConfig = $src->layoutConfig;
+
+ return $dst;
+ }
+
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
diff --git a/src/applications/dashboard/storage/PhabricatorDashboardPanel.php b/src/applications/dashboard/storage/PhabricatorDashboardPanel.php
--- a/src/applications/dashboard/storage/PhabricatorDashboardPanel.php
+++ b/src/applications/dashboard/storage/PhabricatorDashboardPanel.php
@@ -24,7 +24,10 @@
->setEditPolicy($actor->getPHID());
}
- public static function copyPanel($dst, $src) {
+ public static function copyPanel(
+ PhabricatorDashboardPanel $dst,
+ PhabricatorDashboardPanel $src) {
+
$dst->name = $src->name;
$dst->panelType = $src->panelType;
$dst->properties = $src->properties;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 1:17 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7694187
Default Alt Text
D9508.id22784.diff (7 KB)
Attached To
Mode
D9508: Allow entire dashboards to be copied
Attached
Detach File
Event Timeline
Log In to Comment