mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40:57 +01:00
Allow users to resign if they have authority over any reviewer
Summary: Ref T11050. The old rule was "you can only resign if you're a reviewer". With the new behavior of "resign", the rule should be "you can resign if you're a reviewer, or you have authority over any reviewer". Make it so. Also fixes T12446. I don't know how to reproduce that but I'm pretty sure this'll fix it? Test Plan: - Could not resign from a revision with no authority/reviewer. - Resigned from a revision with myself as a reviewer. - Resigned from a revision with a package I owned as a reviewer. - Could not resign from a revision I had already resigned from. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12446, T11050 Differential Revision: https://secure.phabricator.com/D17558
This commit is contained in:
parent
daeb94561f
commit
24b6c7d718
3 changed files with 30 additions and 4 deletions
|
@ -44,7 +44,9 @@ final class DifferentialRevisionResignTransaction
|
|||
|
||||
public function generateOldValue($object) {
|
||||
$actor = $this->getActor();
|
||||
return !$this->isViewerAnyReviewer($object, $actor);
|
||||
$resigned = DifferentialReviewerStatus::STATUS_RESIGNED;
|
||||
|
||||
return ($this->getViewerReviewerStatus($object, $actor) == $resigned);
|
||||
}
|
||||
|
||||
public function applyExternalEffects($object, $value) {
|
||||
|
@ -61,12 +63,19 @@ final class DifferentialRevisionResignTransaction
|
|||
'been closed. You can only resign from open revisions.'));
|
||||
}
|
||||
|
||||
if (!$this->isViewerAnyReviewer($object, $viewer)) {
|
||||
$resigned = DifferentialReviewerStatus::STATUS_RESIGNED;
|
||||
if ($this->getViewerReviewerStatus($object, $viewer) == $resigned) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'You can not resign from this revision because you have already '.
|
||||
'resigned.'));
|
||||
}
|
||||
|
||||
if (!$this->isViewerAnyAuthority($object, $viewer)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'You can not resign from this revision because you are not a '.
|
||||
'reviewer. You can only resign from revisions where you are a '.
|
||||
'reviewer.'));
|
||||
'reviewer, and do not have authority over any reviewer.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,20 @@ abstract class DifferentialRevisionReviewTransaction
|
|||
return ($this->getViewerReviewerStatus($revision, $viewer) !== null);
|
||||
}
|
||||
|
||||
protected function isViewerAnyAuthority(
|
||||
DifferentialRevision $revision,
|
||||
PhabricatorUser $viewer) {
|
||||
|
||||
$reviewers = $revision->getReviewers();
|
||||
foreach ($revision->getReviewers() as $reviewer) {
|
||||
if ($reviewer->hasAuthority($viewer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function isViewerFullyAccepted(
|
||||
DifferentialRevision $revision,
|
||||
PhabricatorUser $viewer) {
|
||||
|
|
|
@ -60,6 +60,9 @@ abstract class DifferentialRevisionTransactionType
|
|||
protected function getActiveDiffPHID(DifferentialRevision $revision) {
|
||||
try {
|
||||
$diff = $revision->getActiveDiff();
|
||||
if (!$diff) {
|
||||
return null;
|
||||
}
|
||||
return $diff->getPHID();
|
||||
} catch (Exception $ex) {
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue