mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-26 14:38:19 +01:00
Remove the actor itself from reviewer list in commandeering
Summary: When the commandeerer was a reviewer, after the commandeering, he stayed as a reviewer. He can no longer amend the diff. He has to go 'Edit Revision' to remove himself/herself. The fix is to remove it automatically. Test Plan: comamndeereded a revision and the behavior is correct now: - I was removed from the revision list - the comment transaction shows one more entry that I removed myself as a reviewer Reviewers: epriestley, vrana Reviewed By: vrana CC: nh, vrana, aran, Korvin Maniphest Tasks: T1225 Differential Revision: https://secure.phabricator.com/D2872
This commit is contained in:
parent
7ca3401d03
commit
89fd1204e2
3 changed files with 45 additions and 10 deletions
|
@ -26,6 +26,7 @@ final class DifferentialCommentEditor {
|
||||||
protected $message;
|
protected $message;
|
||||||
protected $changedByCommit;
|
protected $changedByCommit;
|
||||||
protected $addedReviewers = array();
|
protected $addedReviewers = array();
|
||||||
|
protected $removedReviewers = array();
|
||||||
private $addedCCs = array();
|
private $addedCCs = array();
|
||||||
|
|
||||||
private $parentMessageID;
|
private $parentMessageID;
|
||||||
|
@ -76,6 +77,15 @@ final class DifferentialCommentEditor {
|
||||||
return $this->addedReviewers;
|
return $this->addedReviewers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRemovedReviewers(array $removeded_reviewers) {
|
||||||
|
$this->removedReviewers = $removeded_reviewers;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemovedReviewers() {
|
||||||
|
return $this->removedReviewers;
|
||||||
|
}
|
||||||
|
|
||||||
public function setAddedCCs($added_ccs) {
|
public function setAddedCCs($added_ccs) {
|
||||||
$this->addedCCs = $added_ccs;
|
$this->addedCCs = $added_ccs;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -234,7 +244,7 @@ final class DifferentialCommentEditor {
|
||||||
"Unexpected revision state '{$revision_status}'!");
|
"Unexpected revision state '{$revision_status}'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$added_reviewers = $this->addReviewers();
|
list($added_reviewers, $ignored) = $this->alterReviewers();
|
||||||
if ($added_reviewers) {
|
if ($added_reviewers) {
|
||||||
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
||||||
$metadata[$key] = $added_reviewers;
|
$metadata[$key] = $added_reviewers;
|
||||||
|
@ -360,7 +370,7 @@ final class DifferentialCommentEditor {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DifferentialAction::ACTION_ADDREVIEWERS:
|
case DifferentialAction::ACTION_ADDREVIEWERS:
|
||||||
$added_reviewers = $this->addReviewers();
|
list($added_reviewers, $ignored) = $this->alterReviewers();
|
||||||
|
|
||||||
if ($added_reviewers) {
|
if ($added_reviewers) {
|
||||||
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
||||||
|
@ -430,17 +440,23 @@ final class DifferentialCommentEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAddedReviewers(array($revision->getAuthorPHID()));
|
$this->setAddedReviewers(array($revision->getAuthorPHID()));
|
||||||
|
$this->setRemovedReviewers(array($actor_phid));
|
||||||
|
|
||||||
// NOTE: Set the new author PHID before calling addReviewers(), since it
|
// NOTE: Set the new author PHID before calling addReviewers(), since it
|
||||||
// doesn't permit the author to become a reviewer.
|
// doesn't permit the author to become a reviewer.
|
||||||
$revision->setAuthorPHID($actor_phid);
|
$revision->setAuthorPHID($actor_phid);
|
||||||
|
|
||||||
$added_reviewers = $this->addReviewers();
|
list($added_reviewers, $removed_reviewers) = $this->alterReviewers();
|
||||||
if ($added_reviewers) {
|
if ($added_reviewers) {
|
||||||
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
$key = DifferentialComment::METADATA_ADDED_REVIEWERS;
|
||||||
$metadata[$key] = $added_reviewers;
|
$metadata[$key] = $added_reviewers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($removed_reviewers) {
|
||||||
|
$key = DifferentialComment::METADATA_REMOVED_REVIEWERS;
|
||||||
|
$metadata[$key] = $removed_reviewers;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception('Unsupported action.');
|
throw new Exception('Unsupported action.');
|
||||||
|
@ -613,32 +629,41 @@ final class DifferentialCommentEditor {
|
||||||
return $ccs;
|
return $ccs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addReviewers() {
|
private function alterReviewers() {
|
||||||
$revision = $this->revision;
|
$revision = $this->revision;
|
||||||
$added_reviewers = $this->getAddedReviewers();
|
$added_reviewers = $this->getAddedReviewers();
|
||||||
|
$removed_reviewers = $this->getRemovedReviewers();
|
||||||
$reviewer_phids = $revision->getReviewers();
|
$reviewer_phids = $revision->getReviewers();
|
||||||
|
|
||||||
|
$reviewer_phids_map = array_fill_keys($reviewer_phids, true);
|
||||||
foreach ($added_reviewers as $k => $user_phid) {
|
foreach ($added_reviewers as $k => $user_phid) {
|
||||||
if ($user_phid == $revision->getAuthorPHID()) {
|
if ($user_phid == $revision->getAuthorPHID()) {
|
||||||
unset($added_reviewers[$k]);
|
unset($added_reviewers[$k]);
|
||||||
}
|
}
|
||||||
if (!empty($reviewer_phids[$user_phid])) {
|
if (isset($reviewer_phids_map[$user_phid])) {
|
||||||
unset($added_reviewers[$k]);
|
unset($added_reviewers[$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($removed_reviewers as $k => $user_phid) {
|
||||||
|
if (!isset($reviewer_phids_map[$user_phid])) {
|
||||||
|
unset($removed_reviewers[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$added_reviewers = array_unique($added_reviewers);
|
$added_reviewers = array_unique($added_reviewers);
|
||||||
|
$removed_reviewers = array_unique($removed_reviewers);
|
||||||
|
|
||||||
if ($added_reviewers) {
|
if ($added_reviewers) {
|
||||||
DifferentialRevisionEditor::alterReviewers(
|
DifferentialRevisionEditor::alterReviewers(
|
||||||
$revision,
|
$revision,
|
||||||
$reviewer_phids,
|
$reviewer_phids,
|
||||||
$rem = array(),
|
$removed_reviewers,
|
||||||
$added_reviewers,
|
$added_reviewers,
|
||||||
$this->actorPHID);
|
$this->actorPHID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $added_reviewers;
|
return array($added_reviewers, $removed_reviewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
final class DifferentialComment extends DifferentialDAO {
|
final class DifferentialComment extends DifferentialDAO {
|
||||||
|
|
||||||
const METADATA_ADDED_REVIEWERS = 'added-reviewers';
|
const METADATA_ADDED_REVIEWERS = 'added-reviewers';
|
||||||
|
const METADATA_REMOVED_REVIEWERS = 'removed-reviewers';
|
||||||
const METADATA_ADDED_CCS = 'added-ccs';
|
const METADATA_ADDED_CCS = 'added-ccs';
|
||||||
const METADATA_DIFF_ID = 'diff-id';
|
const METADATA_DIFF_ID = 'diff-id';
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,10 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
$metadata,
|
$metadata,
|
||||||
DifferentialComment::METADATA_ADDED_REVIEWERS,
|
DifferentialComment::METADATA_ADDED_REVIEWERS,
|
||||||
array());
|
array());
|
||||||
|
$removed_reviewers = idx(
|
||||||
|
$metadata,
|
||||||
|
DifferentialComment::METADATA_REMOVED_REVIEWERS,
|
||||||
|
array());
|
||||||
$added_ccs = idx(
|
$added_ccs = idx(
|
||||||
$metadata,
|
$metadata,
|
||||||
DifferentialComment::METADATA_ADDED_CCS,
|
DifferentialComment::METADATA_ADDED_CCS,
|
||||||
|
@ -180,6 +184,11 @@ final class DifferentialRevisionCommentView extends AphrontView {
|
||||||
$this->renderHandleList($added_reviewers).".";
|
$this->renderHandleList($added_reviewers).".";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($removed_reviewers) {
|
||||||
|
$actions[] = "{$author_link} removed reviewers: ".
|
||||||
|
$this->renderHandleList($removed_reviewers).".";
|
||||||
|
}
|
||||||
|
|
||||||
if ($added_ccs) {
|
if ($added_ccs) {
|
||||||
$actions[] = "{$author_link} added CCs: ".
|
$actions[] = "{$author_link} added CCs: ".
|
||||||
$this->renderHandleList($added_ccs).".";
|
$this->renderHandleList($added_ccs).".";
|
||||||
|
|
Loading…
Add table
Reference in a new issue