Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/view/DifferentialReviewersView.php
12256 views
1
<?php
2
3
final class DifferentialReviewersView extends AphrontView {
4
5
private $reviewers;
6
private $handles;
7
private $diff;
8
9
public function setReviewers(array $reviewers) {
10
assert_instances_of($reviewers, 'DifferentialReviewer');
11
$this->reviewers = $reviewers;
12
return $this;
13
}
14
15
public function setHandles(array $handles) {
16
assert_instances_of($handles, 'PhabricatorObjectHandle');
17
$this->handles = $handles;
18
return $this;
19
}
20
21
public function setActiveDiff(DifferentialDiff $diff) {
22
$this->diff = $diff;
23
return $this;
24
}
25
26
public function render() {
27
$viewer = $this->getUser();
28
$reviewers = $this->reviewers;
29
$diff = $this->diff;
30
$handles = $this->handles;
31
32
$view = new PHUIStatusListView();
33
34
// Move resigned reviewers to the bottom.
35
$head = array();
36
$tail = array();
37
foreach ($reviewers as $key => $reviewer) {
38
if ($reviewer->isResigned()) {
39
$tail[$key] = $reviewer;
40
} else {
41
$head[$key] = $reviewer;
42
}
43
}
44
45
PhabricatorPolicyFilterSet::loadHandleViewCapabilities(
46
$viewer,
47
$handles,
48
array($diff));
49
50
$reviewers = $head + $tail;
51
foreach ($reviewers as $reviewer) {
52
$phid = $reviewer->getReviewerPHID();
53
$handle = $handles[$phid];
54
55
$action_phid = $reviewer->getLastActionDiffPHID();
56
$is_current_action = $this->isCurrent($action_phid);
57
$is_voided = (bool)$reviewer->getVoidedPHID();
58
59
$comment_phid = $reviewer->getLastCommentDiffPHID();
60
$is_current_comment = $this->isCurrent($comment_phid);
61
62
$item = new PHUIStatusItemView();
63
64
$item->setHighlighted($reviewer->hasAuthority($viewer));
65
66
// If someone other than the reviewer acted on the reviewer's behalf,
67
// show who is responsible for the current state. This is usually a
68
// user accepting for a package or project.
69
$authority_phid = $reviewer->getLastActorPHID();
70
if ($authority_phid && ($authority_phid !== $phid)) {
71
$authority_name = $viewer->renderHandle($authority_phid)
72
->setAsText(true);
73
} else {
74
$authority_name = null;
75
}
76
77
switch ($reviewer->getReviewerStatus()) {
78
case DifferentialReviewerStatus::STATUS_ADDED:
79
if ($comment_phid) {
80
if ($is_current_comment) {
81
$icon = 'fa-comment';
82
$color = 'blue';
83
$label = pht('Commented');
84
} else {
85
$icon = 'fa-comment-o';
86
$color = 'bluegrey';
87
$label = pht('Commented Previously');
88
}
89
} else {
90
$icon = PHUIStatusItemView::ICON_OPEN;
91
$color = 'bluegrey';
92
$label = pht('Review Requested');
93
}
94
break;
95
96
case DifferentialReviewerStatus::STATUS_ACCEPTED:
97
if ($is_current_action && !$is_voided) {
98
$icon = PHUIStatusItemView::ICON_ACCEPT;
99
$color = 'green';
100
if ($authority_name !== null) {
101
$label = pht('Accepted (by %s)', $authority_name);
102
} else {
103
$label = pht('Accepted');
104
}
105
} else {
106
$icon = 'fa-check-circle-o';
107
$color = 'bluegrey';
108
109
if (!$is_current_action && $is_voided) {
110
// The reviewer accepted the revision, but later the author
111
// used "Request Review" to request an updated review.
112
$label = pht('Accepted Earlier');
113
} else if ($authority_name !== null) {
114
$label = pht('Accepted Prior Diff (by %s)', $authority_name);
115
} else {
116
$label = pht('Accepted Prior Diff');
117
}
118
}
119
break;
120
121
case DifferentialReviewerStatus::STATUS_REJECTED:
122
if ($is_current_action) {
123
$icon = PHUIStatusItemView::ICON_REJECT;
124
$color = 'red';
125
if ($authority_name !== null) {
126
$label = pht('Requested Changes (by %s)', $authority_name);
127
} else {
128
$label = pht('Requested Changes');
129
}
130
} else {
131
$icon = 'fa-times-circle-o';
132
$color = 'red';
133
if ($authority_name !== null) {
134
$label = pht(
135
'Requested Changes to Prior Diff (by %s)',
136
$authority_name);
137
} else {
138
$label = pht('Requested Changes to Prior Diff');
139
}
140
}
141
break;
142
143
case DifferentialReviewerStatus::STATUS_BLOCKING:
144
$icon = PHUIStatusItemView::ICON_MINUS;
145
$color = 'red';
146
$label = pht('Blocking Review');
147
break;
148
149
case DifferentialReviewerStatus::STATUS_RESIGNED:
150
$icon = 'fa-times';
151
$color = 'grey';
152
$label = pht('Resigned');
153
break;
154
155
default:
156
$icon = PHUIStatusItemView::ICON_QUESTION;
157
$color = 'bluegrey';
158
$label = pht('Unknown ("%s")', $reviewer->getReviewerStatus());
159
break;
160
161
}
162
163
$item->setIcon($icon, $color, $label);
164
$item->setTarget(
165
$handle->renderHovercardLink(
166
null,
167
$diff->getPHID()));
168
169
if ($reviewer->isPackage()) {
170
if (!$reviewer->getChangesets()) {
171
$item->setNote(pht('(Owns No Changed Paths)'));
172
}
173
}
174
175
if ($handle->hasCapabilities()) {
176
if (!$handle->hasViewCapability($diff)) {
177
$item
178
->setIcon('fa-eye-slash', 'red')
179
->setNote(pht('No View Permission'))
180
->setIsExiled(true);
181
}
182
}
183
184
$view->addItem($item);
185
}
186
187
return $view;
188
}
189
190
private function isCurrent($action_phid) {
191
if (!$this->diff) {
192
return true;
193
}
194
195
if (!$action_phid) {
196
return true;
197
}
198
199
$diff_phid = $this->diff->getPHID();
200
if (!$diff_phid) {
201
return true;
202
}
203
204
if ($diff_phid == $action_phid) {
205
return true;
206
}
207
208
return false;
209
}
210
211
}
212
213