Skip to content

Commit

Permalink
Remove '$action' argument from prepare_save_paper_web; use status:phase.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Nov 1, 2023
1 parent f062878 commit abec2d1
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 88 deletions.
3 changes: 2 additions & 1 deletion etc/msgs.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
["<5>{round} external review hard deadline", "<5>External review hard deadline", ["!{round}"]],

["<0>Updated {submission} (changed {:list})", "<0>Updated {submission}", ["#{0}=0"]],
["<0>Updated final version (changed {:list})", "<0>Updated final version", ["#{0}=0"]],
["<0>Updated {submission} (changed {:list})", "<0>Updated final version (changed {:list})", ["{phase}=final"]],
["<0>Updated {submission} (changed {:list})", "<0>Updated final version", ["{phase}=final", "#{0}=0"]],
["{:list} were changed.", "The {:list} field was changed.", ["#{0}=1"]],
["<0>At least {min} selections required", "<0>Exactly one selection required", ["{min}=1", "{max}=1"]],
["<0>At most {max} selections allowed", "<0>Exactly one selection required", ["{min}=1", "{max}=1"]],
Expand Down
37 changes: 20 additions & 17 deletions src/pages/p_paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ private function time_note($t, $future_msg, $past_msg) {
return $msg;
}

/** @param 'update'|'final' $action */
private function handle_if_unmodified_since($action) {
$stripfields = $this->ps->strip_unchanged_fields_qreq($this->qreq, $this->prow, $action);
$fields = $this->ps->changed_fields_qreq($this->qreq, $this->prow, $action);
private function handle_if_unmodified_since() {
$stripfields = $this->ps->strip_unchanged_fields_qreq($this->qreq, $this->prow);
$fields = $this->ps->changed_fields_qreq($this->qreq, $this->prow);
if (empty($fields) && $this->prow->paperId) {
$this->conf->redirect_self($this->qreq, ["p" => $this->prow->paperId, "m" => "edit"]);
} else {
Expand All @@ -166,24 +165,25 @@ private function handle_if_unmodified_since($action) {
}
}

/** @param 'update'|'final' $action */
function handle_update($action) {
function handle_update() {
$conf = $this->conf;
// XXX lock tables
$is_new = $this->prow->paperId <= 0;
$was_submitted = $this->prow->timeSubmitted > 0;
$is_final = $this->prow->phase() === PaperInfo::PHASE_FINAL
&& $this->qreq["status:phase"] === "final";
$this->useRequest = true;

$this->ps = new PaperStatus($this->user);
$prepared = $this->ps->prepare_save_paper_web($this->qreq, $this->prow, $action);
$prepared = $this->ps->prepare_save_paper_web($this->qreq, $this->prow);

if (!$prepared) {
if ($is_new && $this->qreq->has_files()) {
// XXX save uploaded files
$this->ps->prepend_msg("<5><strong>Your uploaded files were ignored.</strong>", 2);
}
if ($this->ps->has_error_at("status:if_unmodified_since")) {
$this->handle_if_unmodified_since($action);
$this->handle_if_unmodified_since();
} else {
$this->ps->prepend_msg("<0>Changes not saved; please correct these errors and try again.", 2);
}
Expand All @@ -192,14 +192,14 @@ function handle_update($action) {
}

// check deadlines
// NB At this point, PaperStatus also checks deadlines.
// NB PaperStatus also checks deadlines now; this is likely redundant.
if ($is_new) {
// we know that can_start_paper implies can_finalize_paper
$whynot = $this->user->perm_start_paper($this->prow);
} else {
$whynot = $this->user->perm_edit_paper($this->prow);
if ($whynot
&& $action === "update"
&& !$is_final
&& !count(array_diff($this->ps->changed_keys(), ["contacts", "status"]))) {
$whynot = $this->user->perm_finalize_paper($this->prow);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ function handle_update($action) {
$sr = $new_prow->submission_round();

// confirmation message
if ($action === "final") {
if ($is_final) {
$template = "@submitfinalpaper";
} else if ($newsubmit) {
$template = "@submitpaper";
Expand All @@ -252,7 +252,7 @@ function handle_update($action) {
$note_status = MessageSet::PLAIN;
if ($this->ps->has_error()) {
// only print save error message; to do otherwise is confusing
} else if ($action == "final") {
} else if ($is_final) {
if ($new_prow->timeFinalSubmitted <= 0) {
$notes[] = $conf->_("<0>The final version has not yet been submitted.");
}
Expand Down Expand Up @@ -294,9 +294,8 @@ function handle_update($action) {
} else if ($is_new) {
$this->ps->splice_msg($msgpos++, $conf->_("<0>Registered {submission} as #{}", $new_prow->paperId), MessageSet::SUCCESS);
} else {
$t = $action === "final" ? "<0>Updated final version (changed {:list})" : "<0>Updated {submission} (changed {:list})";
$chf = array_map(function ($f) { return $f->edit_title(); }, $this->ps->changed_fields());
$this->ps->splice_msg($msgpos++, $conf->_($t, $chf), MessageSet::SUCCESS);
$this->ps->splice_msg($msgpos++, $conf->_("<0>Updated {submission} (changed {:list})", $chf, new FmtArg("phase", $is_final ? "final" : "review")), MessageSet::SUCCESS);
}
if ($this->ps->has_error()) {
if (!$this->ps->has_change()) {
Expand Down Expand Up @@ -339,7 +338,7 @@ function handle_update($action) {
}

// other mail confirmations
if ($action === "final" && $new_prow->timeFinalSubmitted > 0) {
if ($is_final && $new_prow->timeFinalSubmitted > 0) {
$followers = $new_prow->final_update_followers();
$template = "@finalsubmitnotify";
} else if ($is_new || $newsubmit) {
Expand Down Expand Up @@ -372,7 +371,8 @@ function handle_updatecontacts() {
}

$this->ps = new PaperStatus($this->user);
if (!$this->ps->prepare_save_paper_web($this->qreq, $this->prow, "updatecontacts")) {
$this->qreq["status:phase"] = "contacts";
if (!$this->ps->prepare_save_paper_web($this->qreq, $this->prow)) {
$conf->feedback_msg($this->ps);
return;
}
Expand Down Expand Up @@ -538,7 +538,10 @@ static function go(Contact $user, Qrequest $qreq) {
if ($qreq->cancel) {
$pp->handle_cancel();
} else if ($qreq->update && $qreq->valid_post()) {
$pp->handle_update($qreq->submitfinal ? "final" : "update");
if (!isset($qreq["status:phase"])) {
$qreq["status:phase"] = $qreq->submitfinal ? "final" : "review"; /* XXX backward compat */
}
$pp->handle_update();
} else if ($qreq->updatecontacts && $qreq->valid_post()) {
$pp->handle_updatecontacts();
} else if ($qreq->withdraw && $qreq->valid_post()) {
Expand Down
42 changes: 20 additions & 22 deletions src/paperstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,8 @@ private function _reset(PaperInfo $prow) {
}

/** @param ?PaperInfo $prow
* @param 'submit'|'update'|'final'|'updatecontacts' $action
* @return bool */
function prepare_save_paper_web(Qrequest $qreq, $prow, $action) {
function prepare_save_paper_web(Qrequest $qreq, $prow) {
$this->_reset($prow ?? PaperInfo::make_new($this->user, $qreq->sclass));
$pj = (object) [];

Expand All @@ -905,15 +904,17 @@ function prepare_save_paper_web(Qrequest $qreq, $prow, $action) {

// Status
$pjs = $pj->status = (object) [];
$updatecontacts = $action === "updatecontacts";
if ($action === "submit"
|| ($action === "update" && $qreq["status:submit"])) {
$pjs->submitted = true;
$pjs->draft = false;
} else if ($action === "final") {
$phase = $qreq["status:phase"];
if ($phase === "contacts") {
// do not change submitted/draft state
} else if ($phase === "final") {
$pjs->phase = "final";
$pjs->final_submitted = $pjs->submitted = true;
$pjs->draft = false;
} else if (!$updatecontacts && $qreq["has_status:submit"]) {
} else if ($qreq["status:submit"]) {
$pjs->submitted = true;
$pjs->draft = false;
} else if ($qreq["has_status:submit"]) {
$pjs->submitted = false;
$pjs->draft = true;
}
Expand All @@ -925,8 +926,8 @@ function prepare_save_paper_web(Qrequest $qreq, $prow, $action) {
// Fields
foreach ($this->prow->form_fields() as $o) {
if (($qreq["has_{$o->formid}"] || isset($qreq[$o->formid]))
&& (!$o->is_final() || $action === "final")
&& (!$updatecontacts || $o->id === PaperOption::CONTACTSID)) {
&& (!$o->is_final() || $phase === "final")
&& ($o->id === PaperOption::CONTACTSID || $phase !== "contacts")) {
// XXX test_editable
$pj->{$o->json_key()} = $o->parse_qreq($this->prow, $qreq);
}
Expand Down Expand Up @@ -1419,26 +1420,24 @@ function save_paper_json($pj) {
}

/** @param ?PaperInfo $prow
* @param 'submit'|'update'|'final'|'updatecontacts' $action
* @return int|false */
function save_paper_web(Qrequest $qreq, $prow, $action) {
if ($this->prepare_save_paper_web($qreq, $prow, $action)) {
function save_paper_web(Qrequest $qreq, $prow) {
if ($this->prepare_save_paper_web($qreq, $prow)) {
$this->execute_save();
return $this->paperId;
} else {
return false;
}
}

/** @param 'update'|'final' $action
* @return list<PaperOption> */
function strip_unchanged_fields_qreq(Qrequest $qreq, PaperInfo $prow, $action) {
/** @return list<PaperOption> */
function strip_unchanged_fields_qreq(Qrequest $qreq, PaperInfo $prow) {
$fcs = (new FieldChangeSet)->mark_unchanged($qreq["status:unchanged"])
->mark_changed($qreq["status:changed"])
->mark_synonym("pc_conflicts", "pcconf"); /* XXX special case */
$fl = [];
foreach ($prow->form_fields() as $o) {
if ($o->is_final() && $action !== "final") {
if ($o->is_final() && $qreq["status:phase"] !== "final") {
continue;
}
// if option appears completely unchanged from save time, reset
Expand All @@ -1453,14 +1452,13 @@ function strip_unchanged_fields_qreq(Qrequest $qreq, PaperInfo $prow, $action) {
return $fl;
}

/** @param 'update'|'final' $action
* @return list<PaperOption> */
function changed_fields_qreq(Qrequest $qreq, PaperInfo $prow, $action) {
/** @return list<PaperOption> */
function changed_fields_qreq(Qrequest $qreq, PaperInfo $prow) {
$fl = [];
foreach ($prow->form_fields() as $o) {
if ($this->has_change_at($o)
&& (isset($qreq["has_{$o->formid}"]) || isset($qreq[$o->formid]))
&& (!$o->is_final() || $action === "final")) {
&& (!$o->is_final() || $qreq["status:phase"] === "final")) {
$fl[] = $o;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/papertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ private function need_autoready() {
}

private function print_editable_complete() {
echo Ht::hidden("status:if_unmodified_since", $this->prow->timeModified);
echo Ht::hidden("status:phase", $this->allow_edit_final ? "final" : "review"),
Ht::hidden("status:if_unmodified_since", $this->prow->timeModified);
if ($this->allow_edit_final) {
echo Ht::hidden("status:submit", 1);
return;
Expand Down Expand Up @@ -2125,9 +2126,6 @@ private function print_actions() {
Ht::entry("status:notify_reason", $v, ["size" => 30, "placeholder" => "Optional explanation", "class" => "ignore-diff js-autosubmit", "aria-label" => "Explanation for update"]),
"</div>";
}
if ($this->mode === "edit" && $this->allow_edit_final) {
echo Ht::hidden("submitfinal", 1);
}

$buttons = $this->_collect_actions();
if ($this->admin && $this->prow->paperId) {
Expand Down
Loading

0 comments on commit abec2d1

Please sign in to comment.