1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-28 22:49:16 +01:00
phorge-phorge/src/applications/dashboard/install/PhabricatorDashboardObjectInstallWorkflow.php
epriestley 12b9224387 Make the "Install Dashboard" flow smoother
Summary:
Depends on D20362. Ref T13272. Currently, Dashboards have an "Install Dashboard" flow which is pretty janky and only allows you to install things to the home page.

Instead, allow users to install things to any valid target (home, favorites, portals, projects). This also provides URIs like `dashboard/install/1/home/personal/` which allow you to link users to an "install a dashboard" page; this may or may not get used.

Test Plan: Installed dashboards on home, favorites, projects, and portals.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13272

Differential Revision: https://secure.phabricator.com/D20364
2019-04-09 13:34:09 -07:00

99 lines
2.6 KiB
PHP

<?php
abstract class PhabricatorDashboardObjectInstallWorkflow
extends PhabricatorDashboardInstallWorkflow {
abstract protected function newQuery();
abstract protected function newConfirmDialog($object);
abstract protected function newObjectSelectionForm($object);
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$target_identifier = null;
$target_tokens = $request->getArr('target');
if ($target_tokens) {
$target_identifier = head($target_tokens);
}
if (!strlen($target_identifier)) {
$target_identifier = $request->getStr('target');
}
if (!strlen($target_identifier)) {
$target_identifier = $this->getMode();
}
$target = null;
if (strlen($target_identifier)) {
$targets = array();
if (ctype_digit($target_identifier)) {
$targets = $this->newQuery()
->setViewer($viewer)
->withIDs(array((int)$target_identifier))
->execute();
}
if (!$targets) {
$targets = $this->newQuery()
->setViewer($viewer)
->withPHIDs(array($target_identifier))
->execute();
}
if ($targets) {
$target = head($targets);
}
}
if ($target) {
$target_phid = $target->getPHID();
} else {
$target_phid = null;
}
if ($target) {
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$target,
PhabricatorPolicyCapability::CAN_EDIT);
} else {
$can_edit = null;
}
if ($request->isFormPost() && $target && $can_edit) {
if ($request->getBool('confirm')) {
return $this->installDashboard($target, null);
} else {
return $this->newConfirmDialog($target)
->addHiddenInput('confirm', 1)
->addHiddenInput('target', $target_phid);
}
}
$errors = array();
if (strlen($target_identifier)) {
if (!$target) {
$errors[] = pht('Choose a valid object.');
} else if (!$can_edit) {
$errors[] = pht(
'You do not have permission to edit the selected object. '.
'You can only install dashboards on objects you can edit.');
}
} else if ($request->getBool('pick')) {
$errors[] = pht(
'Choose an object to install this dashboard on.');
}
$form = $this->newObjectSelectionForm($target)
->addHiddenInput('pick', 1);
return $this->newDialog()
->setTitle(pht('Add Dashboard to Project Menu'))
->setErrors($errors)
->appendForm($form)
->addSubmitButton(pht('Continue'));
}
}