Skip to content

Commit

Permalink
(#353) Introduce edit conflict detection for saving reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 17, 2024
1 parent c869e02 commit 03fbbba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@ private function _normalize_and_check($pj) {
// don't save if transaction required
if (isset($pj->status->if_unmodified_since)
&& $pj->status->if_unmodified_since < $this->prow->timeModified) {
$this->estop_at("status:if_unmodified_since", $this->_("<5><strong>Edit conflict</strong>: You were editing an old version of the {submission}, so your changes have not been saved."));
$this->estop_at("status:if_unmodified_since", $this->_("<5><strong>Edit conflict</strong>: The {submission} changed since you last loaded this page"));
$this->inform_at("status:if_unmodified_since", $this->_("<0>Your changes were not saved, but you can check the form and save again."));
}

// don't save if not allowed
Expand Down
3 changes: 2 additions & 1 deletion src/reviewform.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ function print_form(PaperInfo $prow, ?ReviewInfo $rrow_in, Contact $viewer,
]),
Ht::hidden_default_submit("default", "");
if ($rrow->reviewId) {
echo Ht::hidden("edit_version", ($rrow->reviewEditVersion ?? 0) + 1);
echo Ht::hidden("edit_version", ($rrow->reviewEditVersion ?? 0) + 1),
Ht::hidden("if_vtag_match", $rrow->reviewTime);
}
echo '<div class="revcard-head">';

Expand Down
11 changes: 8 additions & 3 deletions src/reviewvalues.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ function parse_json($j) {
if (is_string($v)) {
$this->req["reviewerAffiliation"] = $v;
}
} else if ($k === "first" || $k === "firstName") {
} else if ($k === "given_name" || $k === "first" || $k === "firstName") {
if (is_string($v)) {
$this->req["reviewerFirst"] = simplify_whitespace($v);
}
} else if ($k === "last" || $k === "lastName") {
} else if ($k === "family_name" || $k === "last" || $k === "lastName") {
if (is_string($v)) {
$this->req["reviewerLast"] = simplify_whitespace($v);
}
Expand Down Expand Up @@ -515,6 +515,10 @@ function parse_qreq(Qrequest $qreq) {
}
} else if ($k === "edit_version") {
$this->req[$k] = stoi($v) ?? -1;
} else if ($k === "if_vtag_match") {
if (ctype_digit($v)) {
$this->req[$k] = intval($v);
}
} else if (str_starts_with($k, "has_")) {
$hasreqs[] = substr($k, 4);
} else if (($f = $rf->field($k) ?? $this->conf->find_review_field($k))
Expand Down Expand Up @@ -723,7 +727,8 @@ 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>: You were editing an old version of the review, so your changes have not been saved", self::ERROR);
$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;
}

Expand Down

0 comments on commit 03fbbba

Please sign in to comment.