Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/storage/DifferentialReviewer.php
12256 views
1
<?php
2
3
final class DifferentialReviewer
4
extends DifferentialDAO {
5
6
protected $revisionPHID;
7
protected $reviewerPHID;
8
protected $reviewerStatus;
9
protected $lastActionDiffPHID;
10
protected $lastCommentDiffPHID;
11
protected $lastActorPHID;
12
protected $voidedPHID;
13
protected $options = array();
14
15
private $authority = array();
16
private $changesets = self::ATTACHABLE;
17
18
protected function getConfiguration() {
19
return array(
20
self::CONFIG_SERIALIZATION => array(
21
'options' => self::SERIALIZATION_JSON,
22
),
23
self::CONFIG_COLUMN_SCHEMA => array(
24
'reviewerStatus' => 'text64',
25
'lastActionDiffPHID' => 'phid?',
26
'lastCommentDiffPHID' => 'phid?',
27
'lastActorPHID' => 'phid?',
28
'voidedPHID' => 'phid?',
29
),
30
self::CONFIG_KEY_SCHEMA => array(
31
'key_revision' => array(
32
'columns' => array('revisionPHID', 'reviewerPHID'),
33
'unique' => true,
34
),
35
'key_reviewer' => array(
36
'columns' => array('reviewerPHID', 'revisionPHID'),
37
),
38
),
39
) + parent::getConfiguration();
40
}
41
42
public function isUser() {
43
$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;
44
return (phid_get_type($this->getReviewerPHID()) == $user_type);
45
}
46
47
public function isPackage() {
48
$package_type = PhabricatorOwnersPackagePHIDType::TYPECONST;
49
return (phid_get_type($this->getReviewerPHID()) == $package_type);
50
}
51
52
public function attachAuthority(PhabricatorUser $user, $has_authority) {
53
$this->authority[$user->getCacheFragment()] = $has_authority;
54
return $this;
55
}
56
57
public function hasAuthority(PhabricatorUser $viewer) {
58
$cache_fragment = $viewer->getCacheFragment();
59
return $this->assertAttachedKey($this->authority, $cache_fragment);
60
}
61
62
public function attachChangesets(array $changesets) {
63
$this->changesets = $changesets;
64
return $this;
65
}
66
67
public function getChangesets() {
68
return $this->assertAttached($this->changesets);
69
}
70
71
public function setOption($key, $value) {
72
$this->options[$key] = $value;
73
return $this;
74
}
75
76
public function getOption($key, $default = null) {
77
return idx($this->options, $key, $default);
78
}
79
80
public function isResigned() {
81
$status_resigned = DifferentialReviewerStatus::STATUS_RESIGNED;
82
return ($this->getReviewerStatus() == $status_resigned);
83
}
84
85
public function isBlocking() {
86
$status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING;
87
return ($this->getReviewerStatus() == $status_blocking);
88
}
89
90
public function isRejected($diff_phid) {
91
$status_rejected = DifferentialReviewerStatus::STATUS_REJECTED;
92
93
if ($this->getReviewerStatus() != $status_rejected) {
94
return false;
95
}
96
97
if ($this->getVoidedPHID()) {
98
return false;
99
}
100
101
if ($this->isCurrentAction($diff_phid)) {
102
return true;
103
}
104
105
return false;
106
}
107
108
109
public function isAccepted($diff_phid) {
110
$status_accepted = DifferentialReviewerStatus::STATUS_ACCEPTED;
111
112
if ($this->getReviewerStatus() != $status_accepted) {
113
return false;
114
}
115
116
// If this accept has been voided (for example, but a reviewer using
117
// "Request Review"), don't count it as a real "Accept" even if it is
118
// against the current diff PHID.
119
if ($this->getVoidedPHID()) {
120
return false;
121
}
122
123
if ($this->isCurrentAction($diff_phid)) {
124
return true;
125
}
126
127
$sticky_key = 'differential.sticky-accept';
128
$is_sticky = PhabricatorEnv::getEnvConfig($sticky_key);
129
130
if ($is_sticky) {
131
return true;
132
}
133
134
return false;
135
}
136
137
private function isCurrentAction($diff_phid) {
138
if (!$diff_phid) {
139
return true;
140
}
141
142
$action_phid = $this->getLastActionDiffPHID();
143
144
if (!$action_phid) {
145
return true;
146
}
147
148
if ($action_phid == $diff_phid) {
149
return true;
150
}
151
152
return false;
153
}
154
155
}
156
157