Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/oauthserver/controller/client/PhabricatorOAuthClientViewController.php
12242 views
1
<?php
2
3
final class PhabricatorOAuthClientViewController
4
extends PhabricatorOAuthClientController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
9
$client = id(new PhabricatorOAuthServerClientQuery())
10
->setViewer($viewer)
11
->withIDs(array($request->getURIData('id')))
12
->executeOne();
13
if (!$client) {
14
return new Aphront404Response();
15
}
16
17
$header = $this->buildHeaderView($client);
18
$properties = $this->buildPropertyListView($client);
19
20
$crumbs = $this->buildApplicationCrumbs()
21
->addTextCrumb($client->getName())
22
->setBorder(true);
23
24
$timeline = $this->buildTransactionTimeline(
25
$client,
26
new PhabricatorOAuthServerTransactionQuery());
27
$timeline->setShouldTerminate(true);
28
29
$box = id(new PHUIObjectBoxView())
30
->setHeaderText(pht('Details'))
31
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
32
->addPropertyList($properties);
33
34
$title = pht('OAuth Application: %s', $client->getName());
35
36
$curtain = $this->buildCurtain($client);
37
38
$columns = id(new PHUITwoColumnView())
39
->setHeader($header)
40
->setCurtain($curtain)
41
->setMainColumn(
42
array(
43
$box,
44
$timeline,
45
));
46
47
return $this->newPage()
48
->setCrumbs($crumbs)
49
->setTitle($title)
50
->appendChild($columns);
51
}
52
53
private function buildHeaderView(PhabricatorOAuthServerClient $client) {
54
$viewer = $this->getViewer();
55
56
$header = id(new PHUIHeaderView())
57
->setUser($viewer)
58
->setHeader(pht('OAuth Application: %s', $client->getName()))
59
->setPolicyObject($client);
60
61
if ($client->getIsDisabled()) {
62
$header->setStatus('fa-ban', 'indigo', pht('Disabled'));
63
} else {
64
$header->setStatus('fa-check', 'green', pht('Enabled'));
65
}
66
67
return $header;
68
}
69
70
private function buildCurtain(PhabricatorOAuthServerClient $client) {
71
$viewer = $this->getViewer();
72
$actions = array();
73
74
$can_edit = PhabricatorPolicyFilter::hasCapability(
75
$viewer,
76
$client,
77
PhabricatorPolicyCapability::CAN_EDIT);
78
79
$id = $client->getID();
80
81
$actions[] = id(new PhabricatorActionView())
82
->setName(pht('Edit Application'))
83
->setIcon('fa-pencil')
84
->setWorkflow(!$can_edit)
85
->setDisabled(!$can_edit)
86
->setHref($client->getEditURI());
87
88
$actions[] = id(new PhabricatorActionView())
89
->setName(pht('Show Application Secret'))
90
->setIcon('fa-eye')
91
->setHref($this->getApplicationURI("client/secret/{$id}/"))
92
->setDisabled(!$can_edit)
93
->setWorkflow(true);
94
95
$is_disabled = $client->getIsDisabled();
96
if ($is_disabled) {
97
$disable_text = pht('Enable Application');
98
$disable_icon = 'fa-check';
99
} else {
100
$disable_text = pht('Disable Application');
101
$disable_icon = 'fa-ban';
102
}
103
104
$disable_uri = $this->getApplicationURI("client/disable/{$id}/");
105
106
$actions[] = id(new PhabricatorActionView())
107
->setName($disable_text)
108
->setIcon($disable_icon)
109
->setWorkflow(true)
110
->setDisabled(!$can_edit)
111
->setHref($disable_uri);
112
113
$actions[] = id(new PhabricatorActionView())
114
->setName(pht('Generate Test Token'))
115
->setIcon('fa-plus')
116
->setWorkflow(true)
117
->setHref($this->getApplicationURI("client/test/{$id}/"));
118
119
$curtain = $this->newCurtainView($client);
120
121
foreach ($actions as $action) {
122
$curtain->addAction($action);
123
}
124
125
return $curtain;
126
}
127
128
private function buildPropertyListView(PhabricatorOAuthServerClient $client) {
129
$viewer = $this->getRequest()->getUser();
130
131
$view = id(new PHUIPropertyListView())
132
->setUser($viewer);
133
134
$view->addProperty(
135
pht('Client PHID'),
136
$client->getPHID());
137
138
$view->addProperty(
139
pht('Redirect URI'),
140
$client->getRedirectURI());
141
142
return $view;
143
}
144
}
145
146