Page MenuHomePhabricator

D9206.id21868.diff
No OneTemporary

D9206.id21868.diff

diff --git a/resources/sql/autopatches/20140519.dashboardinstall.sql b/resources/sql/autopatches/20140519.dashboardinstall.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20140519.dashboardinstall.sql
@@ -0,0 +1,10 @@
+CREATE TABLE {$NAMESPACE}_dashboard.dashboard_install (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ installerPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ objectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ applicationClass VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ dashboardPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
+ dateCreated INT UNSIGNED NOT NULL,
+ dateModified INT UNSIGNED NOT NULL,
+ UNIQUE KEY (objectPHID, applicationClass)
+) ENGINE=InnoDB, COLLATE utf8_general_ci;
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
@@ -1463,6 +1463,8 @@
'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php',
'PhabricatorDashboardDAO' => 'applications/dashboard/storage/PhabricatorDashboardDAO.php',
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/PhabricatorDashboardEditController.php',
+ 'PhabricatorDashboardInstall' => 'applications/dashboard/storage/PhabricatorDashboardInstall.php',
+ 'PhabricatorDashboardInstallController' => 'applications/dashboard/controller/PhabricatorDashboardInstallController.php',
'PhabricatorDashboardLayoutConfig' => 'applications/dashboard/layoutconfig/PhabricatorDashboardLayoutConfig.php',
'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php',
'PhabricatorDashboardMovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardMovePanelController.php',
@@ -1493,6 +1495,7 @@
'PhabricatorDashboardTransaction' => 'applications/dashboard/storage/PhabricatorDashboardTransaction.php',
'PhabricatorDashboardTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardTransactionEditor.php',
'PhabricatorDashboardTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardTransactionQuery.php',
+ 'PhabricatorDashboardUninstallController' => 'applications/dashboard/controller/PhabricatorDashboardUninstallController.php',
'PhabricatorDashboardViewController' => 'applications/dashboard/controller/PhabricatorDashboardViewController.php',
'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php',
'PhabricatorDebugController' => 'applications/system/controller/PhabricatorDebugController.php',
@@ -4247,6 +4250,8 @@
'PhabricatorDashboardController' => 'PhabricatorController',
'PhabricatorDashboardDAO' => 'PhabricatorLiskDAO',
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
+ 'PhabricatorDashboardInstall' => 'PhabricatorDashboardDAO',
+ 'PhabricatorDashboardInstallController' => 'PhabricatorDashboardController',
'PhabricatorDashboardListController' => 'PhabricatorDashboardController',
'PhabricatorDashboardMovePanelController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPHIDTypeDashboard' => 'PhabricatorPHIDType',
@@ -4285,6 +4290,7 @@
'PhabricatorDashboardTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorDashboardTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorDashboardTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'PhabricatorDashboardUninstallController' => 'PhabricatorDashboardController',
'PhabricatorDashboardViewController' => 'PhabricatorDashboardController',
'PhabricatorDataNotAttachedException' => 'Exception',
'PhabricatorDebugController' => 'PhabricatorController',
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,8 @@
'arrange/(?P<id>\d+)/' => 'PhabricatorDashboardArrangeController',
'create/' => 'PhabricatorDashboardEditController',
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardEditController',
+ 'install/(?P<id>\d+)/' => 'PhabricatorDashboardInstallController',
+ 'uninstall/(?P<id>\d+)/' => 'PhabricatorDashboardUninstallController',
'addpanel/(?P<id>\d+)/' => 'PhabricatorDashboardAddPanelController',
'movepanel/(?P<id>\d+)/' => 'PhabricatorDashboardMovePanelController',
'removepanel/(?P<id>\d+)/'
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php b/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php
@@ -0,0 +1,131 @@
+<?php
+
+final class PhabricatorDashboardInstallController
+ 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))
+ ->executeOne();
+ if (!$dashboard) {
+ return new Aphront404Response();
+ }
+ $dashboard_phid = $dashboard->getPHID();
+
+ $object_phid = $request->getStr('objectPHID', $viewer->getPHID());
+ $object = id(new PhabricatorObjectQuery())
+ ->setViewer($viewer)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withPHIDs(array($object_phid))
+ ->executeOne();
+ if (!$object) {
+ return new Aphront404Response();
+ }
+
+ $installer_phid = $viewer->getPHID();
+ $application_class = $request->getStr(
+ 'applicationClass',
+ 'PhabricatorApplicationHome');
+
+ $handles = $this->loadHandles(array(
+ $object_phid,
+ $installer_phid));
+
+ if ($request->isFormPost()) {
+ $dashboard_install = id(new PhabricatorDashboardInstall())
+ ->setInstallerPHID($installer_phid)
+ ->setObjectPHID($object_phid)
+ ->setApplicationClass($application_class)
+ ->setDashboardPHID($dashboard_phid)
+ ->save();
+ return id(new AphrontRedirectResponse())
+ ->setURI($this->getRedirectURI($application_class, $object_phid));
+ }
+
+ $body = $this->getBodyContent(
+ $application_class,
+ $object_phid,
+ $installer_phid);
+
+ $form = id(new AphrontFormView())
+ ->setUser($viewer)
+ ->appendChild($body);
+
+ return $this->newDialog()
+ ->setTitle(pht('Install Dashboard'))
+ ->appendChild($form->buildLayoutView())
+ ->addCancelButton($this->getCancelURI(
+ $application_class, $object_phid))
+ ->addSubmitButton(pht('Install Dashboard'));
+ }
+
+ private function getBodyContent(
+ $application_class,
+ $object_phid,
+ $installer_phid) {
+
+ $body = array();
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ if ($installer_phid == $object_phid) {
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'Are you sure you want to install this dashboard as your '.
+ 'home page?'));
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'You will be re-directed to your spiffy new home page if you '.
+ 'choose to install this dashboard.'));
+ } else {
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'Are you sure you want to install this dashboard as the home '.
+ 'page for %s?',
+ $this->getHandle($object_phid)->getName()));
+ }
+ break;
+ }
+ return $body;
+ }
+
+ private function getCancelURI($application_class, $object_phid) {
+ $uri = null;
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ $uri = '/dashboard/view/'.$this->id.'/';
+ break;
+ }
+ return $uri;
+ }
+
+ private function getRedirectURI($application_class, $object_phid) {
+ $uri = null;
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ $uri = '/';
+ break;
+ }
+ return $uri;
+ }
+
+}
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardUninstallController.php b/src/applications/dashboard/controller/PhabricatorDashboardUninstallController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/controller/PhabricatorDashboardUninstallController.php
@@ -0,0 +1,136 @@
+<?php
+
+final class PhabricatorDashboardUninstallController
+ 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))
+ ->executeOne();
+ if (!$dashboard) {
+ return new Aphront404Response();
+ }
+ $dashboard_phid = $dashboard->getPHID();
+
+ $object_phid = $request->getStr('objectPHID', $viewer->getPHID());
+ $object = id(new PhabricatorObjectQuery())
+ ->setViewer($viewer)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->withPHIDs(array($object_phid))
+ ->executeOne();
+ if (!$object) {
+ return new Aphront404Response();
+ }
+
+ $application_class = $request->getStr(
+ 'applicationClass',
+ 'PhabricatorApplicationHome');
+
+ $dashboard_install = id(new PhabricatorDashboardInstall())
+ ->loadOneWhere(
+ 'objectPHID = %s AND applicationClass = %s',
+ $object_phid,
+ $application_class);
+ if (!$dashboard_install) {
+ return new Aphront404Response();
+ }
+ if ($dashboard_install->getDashboardPHID() != $dashboard_phid) {
+ return new Aphront404Response();
+ }
+
+ $installer_phid = $viewer->getPHID();
+ $handles = $this->loadHandles(array($object_phid, $installer_phid));
+
+ if ($request->isFormPost()) {
+ $dashboard_install->delete();
+ return id(new AphrontRedirectResponse())
+ ->setURI($this->getRedirectURI($application_class, $object_phid));
+ }
+
+ $body = $this->getBodyContent(
+ $application_class,
+ $object_phid,
+ $installer_phid);
+
+ $form = id(new AphrontFormView())
+ ->setUser($viewer)
+ ->appendChild($body);
+
+ return $this->newDialog()
+ ->setTitle(pht('Uninstall Dashboard'))
+ ->appendChild($form->buildLayoutView())
+ ->addCancelButton($this->getCancelURI(
+ $application_class, $object_phid))
+ ->addSubmitButton(pht('Uninstall Dashboard'));
+ }
+
+ private function getBodyContent(
+ $application_class,
+ $object_phid,
+ $installer_phid) {
+
+ $body = array();
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ if ($installer_phid == $object_phid) {
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'Are you sure you want to uninstall this dashboard as your '.
+ 'home page?'));
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'You will be re-directed to your bland, default home page if '.
+ 'you choose to uninstall this dashboard.'));
+ } else {
+ $body[] = phutil_tag(
+ 'p',
+ array(),
+ pht(
+ 'Are you sure you want to uninstall this dashboard as the home '.
+ 'page for %s?',
+ $this->getHandle($object_phid)->getName()));
+ }
+ break;
+ }
+ return $body;
+ }
+
+ private function getCancelURI($application_class, $object_phid) {
+ $uri = null;
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ $uri = '/dashboard/view/'.$this->id.'/';
+ break;
+ }
+ return $uri;
+ }
+
+ private function getRedirectURI($application_class, $object_phid) {
+ $uri = null;
+ switch ($application_class) {
+ case 'PhabricatorApplicationHome':
+ $uri = '/';
+ break;
+ }
+ return $uri;
+ }
+
+}
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardViewController.php b/src/applications/dashboard/controller/PhabricatorDashboardViewController.php
--- a/src/applications/dashboard/controller/PhabricatorDashboardViewController.php
+++ b/src/applications/dashboard/controller/PhabricatorDashboardViewController.php
@@ -92,6 +92,26 @@
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
+ $installed_dashboard = id(new PhabricatorDashboardInstall())
+ ->loadOneWhere(
+ 'objectPHID = %s AND applicationClass = %s',
+ $viewer->getPHID(),
+ 'PhabricatorApplicationHome');
+ if ($installed_dashboard &&
+ $installed_dashboard->getDashboardPHID() == $dashboard->getPHID()) {
+ $title_install = pht('Uninstall Dashboard');
+ $href_install = "uninstall/{$id}/";
+ } else {
+ $title_install = pht('Install Dashboard');
+ $href_install = "install/{$id}/";
+ }
+ $actions->addAction(
+ id(new PhabricatorActionView())
+ ->setName($title_install)
+ ->setIcon('fa-wrench')
+ ->setHref($this->getApplicationURI($href_install))
+ ->setWorkflow(true));
+
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Add Panel'))
diff --git a/src/applications/dashboard/storage/PhabricatorDashboardInstall.php b/src/applications/dashboard/storage/PhabricatorDashboardInstall.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/storage/PhabricatorDashboardInstall.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * An install of a dashboard. Examples might be
+ * - the home page for a user
+ * - the profile page for a user
+ * - the profile page for a project
+ */
+final class PhabricatorDashboardInstall
+ extends PhabricatorDashboardDAO {
+
+ protected $installerPHID;
+ protected $objectPHID;
+ protected $applicationClass;
+ protected $dashboardPHID;
+
+ public static function getDashboard(
+ PhabricatorUser $viewer,
+ $object_phid,
+ $application_class) {
+
+ $dashboard = null;
+ $dashboard_install = id(new PhabricatorDashboardInstall())
+ ->loadOneWhere(
+ 'objectPHID = %s AND applicationClass = %s',
+ $object_phid,
+ $application_class);
+ if ($dashboard_install) {
+ $dashboard = id(new PhabricatorDashboardQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($dashboard_install->getDashboardPHID()))
+ ->needPanels(true)
+ ->executeOne();
+ }
+
+ return $dashboard;
+ }
+}
diff --git a/src/applications/home/controller/PhabricatorHomeMainController.php b/src/applications/home/controller/PhabricatorHomeMainController.php
--- a/src/applications/home/controller/PhabricatorHomeMainController.php
+++ b/src/applications/home/controller/PhabricatorHomeMainController.php
@@ -20,15 +20,36 @@
if ($this->filter == 'jump') {
return $this->buildJumpResponse();
}
-
$nav = $this->buildNav();
- $project_query = new PhabricatorProjectQuery();
- $project_query->setViewer($user);
- $project_query->withMemberPHIDs(array($user->getPHID()));
- $projects = $project_query->execute();
+ $dashboard = PhabricatorDashboardInstall::getDashboard(
+ $user,
+ $user->getPHID(),
+ get_class($this->getCurrentApplication()));
+ if ($dashboard) {
+ $rendered_dashboard = id(new PhabricatorDashboardRenderingEngine())
+ ->setViewer($user)
+ ->setDashboard($dashboard)
+ ->renderDashboard();
+ $nav->appendChild($rendered_dashboard);
+ } else {
+ $project_query = new PhabricatorProjectQuery();
+ $project_query->setViewer($user);
+ $project_query->withMemberPHIDs(array($user->getPHID()));
+ $projects = $project_query->execute();
- return $this->buildMainResponse($nav, $projects);
+ $nav = $this->buildMainResponse($nav, $projects);
+ }
+
+ $nav->appendChild(id(new PhabricatorGlobalUploadTargetView())
+ ->setUser($user));
+
+ return $this->buildApplicationPage(
+ $nav,
+ array(
+ 'title' => 'Phabricator',
+ 'device' => true,
+ ));
}
private function buildMainResponse($nav, array $projects) {
@@ -91,17 +112,10 @@
$this->minipanels,
);
- $user = $this->getRequest()->getUser();
$nav->appendChild($content);
- $nav->appendChild(id(new PhabricatorGlobalUploadTargetView())
- ->setUser($user));
- return $this->buildApplicationPage(
- $nav,
- array(
- 'title' => 'Phabricator',
- 'device' => true,
- ));
+ return $nav;
+
}
private function buildJumpResponse() {

File Metadata

Mime Type
text/plain
Expires
Tue, Oct 15, 6:53 PM (4 w, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713970
Default Alt Text
D9206.id21868.diff (17 KB)

Event Timeline