Skip to content

Commit

Permalink
Fix adopt edit conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 4, 2024
1 parent 33c1f4f commit 4fe5095
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/pages/p_review.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ function handle_adopt() {

$rv = new ReviewValues($this->conf);
$my_rrow = $this->prow->review_by_user($this->user);
$my_rid = ($my_rrow ?? $this->rrow)->unparse_ordinal_id();
if ($rv->parse_qreq($this->qreq)) {
$want_rid = $this->rrow->unparse_ordinal_id();
if ($rv->parse_qreq($this->qreq)
&& $rv->check_vtag($this->rrow)) {
$rv->set_req_ready(!!$this->qreq->adoptsubmit);
// Be careful about if_vtag_match, since vtag corresponds to
// *subreview*, not $my_rrow
$rv->clear_req_vtag();
if ($rv->check_and_save($this->user, $this->prow, $my_rrow)) {
$my_rid = $rv->review_ordinal_id;
$want_rid = $rv->review_ordinal_id;
if (!$rv->has_problem_at("ready")) {
// approve the source review
$rvx = new ReviewValues($this->conf);
Expand All @@ -225,7 +229,7 @@ function handle_adopt() {
}
}
$rv->report();
$this->conf->redirect_self($this->qreq, ["r" => $my_rid]);
$this->conf->redirect_self($this->qreq, ["r" => $want_rid]);
}

function handle_delete() {
Expand Down
23 changes: 19 additions & 4 deletions src/reviewvalues.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ function set_req_approval($x) {
return $this;
}

/** @return $this */
function clear_req_vtag() {
unset($this->req["if_vtag_match"]);
return $this;
}

/** @param int|string $field
* @param string $msg
* @param int $status
Expand Down Expand Up @@ -540,6 +546,18 @@ private function reviewer_error($msg) {
$this->rmsg("reviewerEmail", $msg, self::ERROR);
}

/** @param ReviewInfo $rrow
* @return bool */
function check_vtag(ReviewInfo $rrow) {
if (!isset($this->req["if_vtag_match"])
|| $this->req["if_vtag_match"] === $rrow->reviewTime) {
return true;
}
$this->rmsg("if_vtag_match", "<5><strong>Edit conflict</strong>: The review changed since you last loaded this page", self::ERROR);
$this->rmsg("if_vtag_match", "<0>Your changes were not saved, but you can check the form and save again.", self::INFORM);
return false;
}

/** @return bool */
function check_and_save(Contact $user, ?PaperInfo $prow, ?ReviewInfo $rrow = null) {
assert(!$rrow || $rrow->paperId === $prow->paperId);
Expand Down Expand Up @@ -725,10 +743,7 @@ private function _apply_req(Contact $user, PaperInfo $prow, ReviewInfo $rrow, $n
}

// version tag must match if provided
if (isset($this->req["if_vtag_match"])
&& $this->req["if_vtag_match"] !== $rrow->reviewTime) {
$this->rmsg("if_vtag_match", "<5><strong>Edit conflict</strong>: The review changed since you last loaded this page", self::ERROR);
$this->rmsg("if_vtag_match", "<0>Your changes were not saved, but you can check the form and save again.", self::INFORM);
if (!$this->check_vtag($rrow)) {
return false;
}

Expand Down

0 comments on commit 4fe5095

Please sign in to comment.