Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/controller/PhabricatorPeopleProfileManageController.php
12262 views
1
<?php
2
3
final class PhabricatorPeopleProfileManageController
4
extends PhabricatorPeopleProfileController {
5
6
public function shouldAllowPublic() {
7
return true;
8
}
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $this->getViewer();
12
$id = $request->getURIData('id');
13
14
$user = id(new PhabricatorPeopleQuery())
15
->setViewer($viewer)
16
->withIDs(array($id))
17
->needProfile(true)
18
->needProfileImage(true)
19
->needAvailability(true)
20
->executeOne();
21
if (!$user) {
22
return new Aphront404Response();
23
}
24
25
$this->setUser($user);
26
$header = $this->buildProfileHeader();
27
28
$curtain = $this->buildCurtain($user);
29
$properties = $this->buildPropertyView($user);
30
$name = $user->getUsername();
31
32
$nav = $this->newNavigation(
33
$user,
34
PhabricatorPeopleProfileMenuEngine::ITEM_MANAGE);
35
36
$crumbs = $this->buildApplicationCrumbs();
37
$crumbs->addTextCrumb(pht('Manage'));
38
$crumbs->setBorder(true);
39
40
$timeline = $this->buildTransactionTimeline(
41
$user,
42
new PhabricatorPeopleTransactionQuery());
43
$timeline->setShouldTerminate(true);
44
45
$manage = id(new PHUITwoColumnView())
46
->setHeader($header)
47
->addClass('project-view-home')
48
->addClass('project-view-people-home')
49
->setCurtain($curtain)
50
->addPropertySection(pht('Details'), $properties)
51
->setMainColumn($timeline);
52
53
return $this->newPage()
54
->setTitle(
55
array(
56
pht('Manage User'),
57
$user->getUsername(),
58
))
59
->setNavigation($nav)
60
->setCrumbs($crumbs)
61
->appendChild($manage);
62
}
63
64
private function buildPropertyView(PhabricatorUser $user) {
65
66
$viewer = $this->getRequest()->getUser();
67
$view = id(new PHUIPropertyListView())
68
->setUser($viewer)
69
->setObject($user);
70
71
$field_list = PhabricatorCustomField::getObjectFields(
72
$user,
73
PhabricatorCustomField::ROLE_VIEW);
74
$field_list->appendFieldsToPropertyList($user, $viewer, $view);
75
76
return $view;
77
}
78
79
private function buildCurtain(PhabricatorUser $user) {
80
$viewer = $this->getViewer();
81
82
$is_self = ($user->getPHID() === $viewer->getPHID());
83
84
$can_edit = PhabricatorPolicyFilter::hasCapability(
85
$viewer,
86
$user,
87
PhabricatorPolicyCapability::CAN_EDIT);
88
89
$is_admin = $viewer->getIsAdmin();
90
$can_admin = ($is_admin && !$is_self);
91
92
$has_disable = $this->hasApplicationCapability(
93
PeopleDisableUsersCapability::CAPABILITY);
94
$can_disable = ($has_disable && !$is_self);
95
96
$id = $user->getID();
97
98
$welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine())
99
->setSender($viewer)
100
->setRecipient($user);
101
102
$can_welcome = $welcome_engine->canSendMail();
103
$curtain = $this->newCurtainView($user);
104
105
$curtain->addAction(
106
id(new PhabricatorActionView())
107
->setIcon('fa-pencil')
108
->setName(pht('Edit Profile'))
109
->setHref($this->getApplicationURI('editprofile/'.$id.'/'))
110
->setDisabled(!$can_edit)
111
->setWorkflow(!$can_edit));
112
113
$curtain->addAction(
114
id(new PhabricatorActionView())
115
->setIcon('fa-picture-o')
116
->setName(pht('Edit Profile Picture'))
117
->setHref($this->getApplicationURI('picture/'.$id.'/'))
118
->setDisabled(!$can_edit)
119
->setWorkflow(!$can_edit));
120
121
$curtain->addAction(
122
id(new PhabricatorActionView())
123
->setIcon('fa-wrench')
124
->setName(pht('Edit Settings'))
125
->setDisabled(!$can_edit)
126
->setWorkflow(!$can_edit)
127
->setHref('/settings/user/'.$user->getUsername().'/'));
128
129
if ($user->getIsAdmin()) {
130
$empower_icon = 'fa-arrow-circle-o-down';
131
$empower_name = pht('Remove Administrator');
132
} else {
133
$empower_icon = 'fa-arrow-circle-o-up';
134
$empower_name = pht('Make Administrator');
135
}
136
137
$curtain->addAction(
138
id(new PhabricatorActionView())
139
->setIcon($empower_icon)
140
->setName($empower_name)
141
->setDisabled(!$can_admin)
142
->setWorkflow(true)
143
->setHref($this->getApplicationURI('empower/'.$id.'/')));
144
145
$curtain->addAction(
146
id(new PhabricatorActionView())
147
->setIcon('fa-tag')
148
->setName(pht('Change Username'))
149
->setDisabled(!$is_admin)
150
->setWorkflow(true)
151
->setHref($this->getApplicationURI('rename/'.$id.'/')));
152
153
if ($user->getIsDisabled()) {
154
$disable_icon = 'fa-check-circle-o';
155
$disable_name = pht('Enable User');
156
} else {
157
$disable_icon = 'fa-ban';
158
$disable_name = pht('Disable User');
159
}
160
161
$curtain->addAction(
162
id(new PhabricatorActionView())
163
->setIcon('fa-envelope')
164
->setName(pht('Send Welcome Email'))
165
->setWorkflow(true)
166
->setDisabled(!$can_welcome)
167
->setHref($this->getApplicationURI('welcome/'.$id.'/')));
168
169
$curtain->addAction(
170
id(new PhabricatorActionView())
171
->setType(PhabricatorActionView::TYPE_DIVIDER));
172
173
if (!$user->getIsApproved()) {
174
$approve_action = id(new PhabricatorActionView())
175
->setIcon('fa-thumbs-up')
176
->setName(pht('Approve User'))
177
->setWorkflow(true)
178
->setDisabled(!$is_admin)
179
->setHref("/people/approve/{$id}/via/profile/");
180
181
if ($is_admin) {
182
$approve_action->setColor(PhabricatorActionView::GREEN);
183
}
184
185
$curtain->addAction($approve_action);
186
}
187
188
$curtain->addAction(
189
id(new PhabricatorActionView())
190
->setIcon($disable_icon)
191
->setName($disable_name)
192
->setDisabled(!$can_disable)
193
->setWorkflow(true)
194
->setHref($this->getApplicationURI('disable/'.$id.'/')));
195
196
$curtain->addAction(
197
id(new PhabricatorActionView())
198
->setIcon('fa-times')
199
->setName(pht('Delete User'))
200
->setDisabled(!$can_admin)
201
->setWorkflow(true)
202
->setHref($this->getApplicationURI('delete/'.$id.'/')));
203
204
$curtain->addAction(
205
id(new PhabricatorActionView())
206
->setType(PhabricatorActionView::TYPE_DIVIDER));
207
208
return $curtain;
209
}
210
211
212
}
213
214