From abcd3efa5a2f31336afa3c4ffb5b9433d9438b31 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 23 Jun 2014 15:14:38 -0700 Subject: [PATCH] Allow administrators to set a dashboard as a global default Summary: Ref T4883. - When an administrator installs a dashbord, give them the option to install it as a global default. - On the home page, if a user does not have a dashboard installed, check for a global default. - On the Admin NUX/Welcome page, check for a global dashboard. Test Plan: - Installed a global dashboard, checked homepage, saw it. - Installed a personal dashboard over it. - Checked non-admin flow. - Checked Admin NUX page for quest completion. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T4883 Differential Revision: https://secure.phabricator.com/D9670 --- src/__phutil_library_map__.php | 1 + .../PhabricatorConfigWelcomeController.php | 5 +- .../PhabricatorDashboardInstallController.php | 120 ++++++++++-------- .../PhabricatorApplicationHome.php | 2 + .../PhabricatorHomeMainController.php | 8 ++ 5 files changed, 84 insertions(+), 52 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f56eb0c140..0eabe46719 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4876,6 +4876,7 @@ phutil_register_library_map(array( 2 => 'PhabricatorFlaggableInterface', 3 => 'PhabricatorMarkupInterface', 4 => 'PhabricatorDestructableInterface', + 5 => 'PhabricatorProjectInterface', ), 'PhabricatorRepositoryArcanistProject' => array( diff --git a/src/applications/config/controller/PhabricatorConfigWelcomeController.php b/src/applications/config/controller/PhabricatorConfigWelcomeController.php index 9f0b343ba2..f7b88e0bbc 100644 --- a/src/applications/config/controller/PhabricatorConfigWelcomeController.php +++ b/src/applications/config/controller/PhabricatorConfigWelcomeController.php @@ -156,7 +156,10 @@ final class PhabricatorConfigWelcomeController $content); $dashboard_href = PhabricatorEnv::getURI('/dashboard/'); - $have_dashboard = false; + $have_dashboard = (bool)PhabricatorDashboardInstall::getDashboard( + $viewer, + PhabricatorApplicationHome::DASHBOARD_DEFAULT, + 'PhabricatorApplicationHome'); if ($have_dashboard) { $content = pht( "You've installed a default dashboard to replace this welcome screen ". diff --git a/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php b/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php index 1c4da16dd8..47e492a305 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardInstallController.php @@ -23,17 +23,26 @@ final class PhabricatorDashboardInstallController $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(); + switch ($object_phid) { + case PhabricatorApplicationHome::DASHBOARD_DEFAULT: + if (!$viewer->getIsAdmin()) { + return new Aphront404Response(); + } + break; + default: + $object = id(new PhabricatorObjectQuery()) + ->setViewer($viewer) + ->requireCapabilities( + array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + )) + ->withPHIDs(array($object_phid)) + ->executeOne(); + if (!$object) { + return new Aphront404Response(); + } + break; } $installer_phid = $viewer->getPHID(); @@ -64,58 +73,67 @@ final class PhabricatorDashboardInstallController ->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() + $dialog = $this->newDialog() ->setTitle(pht('Install Dashboard')) - ->appendChild($form->buildLayoutView()) - ->addCancelButton($this->getCancelURI( - $application_class, $object_phid)) + ->addHiddenInput('objectPHID', $object_phid) + ->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.')); + if ($viewer->getPHID() == $object_phid) { + if ($viewer->getIsAdmin()) { + $dialog->setWidth(AphrontDialogView::WIDTH_FORM); + + $form = id(new AphrontFormView()) + ->setUser($viewer) + ->appendRemarkupInstructions( + pht('Choose where to install this dashboard.')) + ->appendChild( + id(new AphrontFormRadioButtonControl()) + ->setName('objectPHID') + ->setValue(PhabricatorApplicationHome::DASHBOARD_DEFAULT) + ->addButton( + PhabricatorApplicationHome::DASHBOARD_DEFAULT, + pht('Default Dashboard for All Users'), + pht( + 'Install this dashboard as the global default dashboard '. + 'for all users. Users can install a personal dashboard '. + 'to replace it. All users who have not configured '. + 'a personal dashboard will be affected by this change.')) + ->addButton( + $viewer->getPHID(), + pht('Personal Home Page Dashboard'), + pht( + 'Install this dashboard as your personal home page '. + 'dashboard. Only you will be affected by this change.'))); + + $dialog->appendChild($form->buildLayoutView()); + } else { + $dialog->appendParagraph( + pht('Install this dashboard on your home page?')); + } } else { - $body[] = phutil_tag( - 'p', - array(), + $dialog->appendParagraph( pht( - 'Are you sure you want to install this dashboard as the home '. - 'page for %s?', - $this->getHandle($object_phid)->getName())); + 'Install this dashboard as the home page dashboard for %s?', + phutil_tag( + 'strong', + array(), + $this->getHandle($object_phid)->getName()))); } break; + default: + throw new Exception( + pht( + 'Unknown dashboard application class "%s"!', + $application_class)); } - return $body; + + return $dialog; } + private function getCancelURI($application_class, $object_phid) { $uri = null; switch ($application_class) { diff --git a/src/applications/home/application/PhabricatorApplicationHome.php b/src/applications/home/application/PhabricatorApplicationHome.php index d9edbb094a..bfcdd6c01f 100644 --- a/src/applications/home/application/PhabricatorApplicationHome.php +++ b/src/applications/home/application/PhabricatorApplicationHome.php @@ -2,6 +2,8 @@ final class PhabricatorApplicationHome extends PhabricatorApplication { + const DASHBOARD_DEFAULT = 'dashboard:default'; + public function getBaseURI() { return '/home/'; } diff --git a/src/applications/home/controller/PhabricatorHomeMainController.php b/src/applications/home/controller/PhabricatorHomeMainController.php index 30a63fbd09..dafb729634 100644 --- a/src/applications/home/controller/PhabricatorHomeMainController.php +++ b/src/applications/home/controller/PhabricatorHomeMainController.php @@ -21,6 +21,14 @@ final class PhabricatorHomeMainController $user, $user->getPHID(), get_class($this->getCurrentApplication())); + + if (!$dashboard) { + $dashboard = PhabricatorDashboardInstall::getDashboard( + $user, + PhabricatorApplicationHome::DASHBOARD_DEFAULT, + get_class($this->getCurrentApplication())); + } + if ($dashboard) { $content = id(new PhabricatorDashboardRenderingEngine()) ->setViewer($user)