Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/dashboard/install/PhabricatorDashboardObjectInstallWorkflow.php
12242 views
1
<?php
2
3
abstract class PhabricatorDashboardObjectInstallWorkflow
4
extends PhabricatorDashboardInstallWorkflow {
5
6
abstract protected function newQuery();
7
abstract protected function newConfirmDialog($object);
8
abstract protected function newObjectSelectionForm($object);
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $this->getViewer();
12
13
$target_identifier = null;
14
15
$target_tokens = $request->getArr('target');
16
if ($target_tokens) {
17
$target_identifier = head($target_tokens);
18
}
19
20
if (!strlen($target_identifier)) {
21
$target_identifier = $request->getStr('target');
22
}
23
24
if (!strlen($target_identifier)) {
25
$target_identifier = $this->getMode();
26
}
27
28
$target = null;
29
if (strlen($target_identifier)) {
30
$targets = array();
31
32
if (ctype_digit($target_identifier)) {
33
$targets = $this->newQuery()
34
->setViewer($viewer)
35
->withIDs(array((int)$target_identifier))
36
->execute();
37
}
38
39
if (!$targets) {
40
$targets = $this->newQuery()
41
->setViewer($viewer)
42
->withPHIDs(array($target_identifier))
43
->execute();
44
}
45
46
if ($targets) {
47
$target = head($targets);
48
}
49
}
50
51
if ($target) {
52
$target_phid = $target->getPHID();
53
} else {
54
$target_phid = null;
55
}
56
57
if ($target) {
58
$can_edit = PhabricatorPolicyFilter::hasCapability(
59
$viewer,
60
$target,
61
PhabricatorPolicyCapability::CAN_EDIT);
62
} else {
63
$can_edit = null;
64
}
65
66
if ($request->isFormPost() && $target && $can_edit) {
67
if ($request->getBool('confirm')) {
68
return $this->installDashboard($target, null);
69
} else {
70
return $this->newConfirmDialog($target)
71
->addHiddenInput('confirm', 1)
72
->addHiddenInput('target', $target_phid);
73
}
74
}
75
76
$errors = array();
77
if (strlen($target_identifier)) {
78
if (!$target) {
79
$errors[] = pht('Choose a valid object.');
80
} else if (!$can_edit) {
81
$errors[] = pht(
82
'You do not have permission to edit the selected object. '.
83
'You can only install dashboards on objects you can edit.');
84
}
85
} else if ($request->getBool('pick')) {
86
$errors[] = pht(
87
'Choose an object to install this dashboard on.');
88
}
89
90
$form = $this->newObjectSelectionForm($target)
91
->addHiddenInput('pick', 1);
92
93
return $this->newDialog()
94
->setTitle(pht('Add Dashboard to Project Menu'))
95
->setErrors($errors)
96
->appendForm($form)
97
->addSubmitButton(pht('Continue'));
98
}
99
}
100
101