diff options
Diffstat (limited to 'src/review/approve.rs')
| -rw-r--r-- | src/review/approve.rs | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/src/review/approve.rs b/src/review/approve.rs index e5f446f..c8cd99d 100644 --- a/src/review/approve.rs +++ b/src/review/approve.rs @@ -1,10 +1,3 @@ -//! Approval semantics (§7.1, §7.1a, §7.2, §7.4). -//! -//! Rule of the system: **we build exactly what was displayed, or nothing.** -//! The approve POST carries the `identity_hash` and `diff_digest` that were -//! rendered; if either has moved under the reviewer, the approval is refused -//! with a conflict (HTTP 409) and a re-render, never silently retargeted. - use crate::db::{self, approvals, candidates, CandidateState, *}; use crate::error::{Error, Result}; use crate::time; @@ -36,20 +29,16 @@ pub struct Approval { /// Why a decision did not happen (§7.1a, §6 M-3). /// -/// Two families, and the difference is the whole point. `Stale` means the -/// reviewer's screen no longer matches the database: the answer is to look -/// again, and the UI says so with a 409 and a fresh diff. `System` means the -/// database itself refused: looking again changes nothing, and the operator has -/// a broken thing to fix. They used to be the same variant — every failure, -/// SQLite included, arrived as "review is no longer pending (state: sqlite: -/// …)", which told a reviewer their eyes were wrong when the truth was that -/// the write failed. +/// Two families, and the difference is the whole point: `Stale` means the +/// reviewer's screen no longer matches the database, so the answer is to look +/// again; `System` means the database itself refused, and looking again changes +/// nothing. #[derive(Debug, thiserror::Error)] pub enum ApproveError { /// What is stored is not what was displayed. #[error(transparent)] Stale(#[from] Stale), - /// The write itself failed. Nothing about the review is at fault. + /// The write itself failed; nothing about the review is at fault. #[error("the decision could not be recorded: {0}")] System(#[from] Error), } @@ -77,19 +66,16 @@ pub fn approve( let base = subject.base_release_id; let current_base = subject.current_base_release_id; - // 1. still open if !subject.state.is_open() { return Ok(Err(ApproveError::Stale(Stale::NotPending { state: subject.state.to_string() }))); } - // 2. same candidate bytes if subject.identity_hash != ih { return Ok(Err(ApproveError::Stale(Stale::Identity { expected: ih.clone(), actual: subject.identity_hash }))); } - // 3. same rendered diff if subject.diff_digest != dd { return Ok(Err(ApproveError::Stale(Stale::Diff { expected: dd.clone(), actual: subject.diff_digest }))); } - // 4. base is still the accepted release (I2, end to end) + // Base is still the accepted release (I2, end to end). if base != current_base { return Ok(Err(ApproveError::Stale(Stale::Base { expected: base, actual: current_base }))); } @@ -128,7 +114,7 @@ pub fn approve( identity_hash: ih, })) }) - // A failure of the transaction is a system failure, never a stale review. + // A failed transaction is a system failure, never a stale review. .map_err(ApproveError::System)? } @@ -156,9 +142,6 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> "reject", "candidate", &candidate_id.to_string(), - // The identity hash, not only the note: "why was this rejected" - // is unanswerable if the row does not say which bytes were on - // screen (§11). serde_json::json!({"identity": identity, "note": note}), ), )?; @@ -169,15 +152,13 @@ pub fn reject(db: &Db, actor: &str, candidate_id: i64, note: &str) -> Result<()> /// One item of a bulk decision, and what happened to it (§7.4). #[derive(Debug)] pub struct BulkItem { - /// The review this outcome is about; `None` when the id matched nothing — - /// which is exactly the case a caller must be able to report, so the row - /// cannot be the key. + /// `None` when the id matched nothing — which a caller must be able to + /// report, so the row cannot be the key. pub candidate: Option<CandidateRow>, pub outcome: BulkOutcome, } impl BulkItem { - /// The pkgbase to name in a summary line. pub fn pkgbase(&self) -> &str { self.candidate.as_ref().map(|c| c.pkgbase.as_str()).unwrap_or("(gone)") } @@ -188,21 +169,14 @@ impl BulkItem { pub enum BulkOutcome { /// Approved; the approval row is here so the caller can queue the build. Approved(Approval), - /// Rejected. A rejection records no approval, so there is no row to hand - /// back — the old code fabricated `Approval { id: 0 }`, which a caller - /// could not tell from a real one (§6 M-3). + /// A rejection records no approval, so there is no row to hand back. Rejected, /// Not decided, and why. Refused(BulkRefusal), } -/// Why a bulk decision skipped one of its items (§7.4). -/// -/// Each reason is its own variant because they are different answers to give a -/// human: one wants a confirmation click, one is a form bug, one means the -/// review moved while the page was open, one means the database is broken. They -/// used to all be `Stale::NotPending`, which made the flash message the only -/// place the truth survived. +/// Why a bulk decision skipped one of its items (§7.4). Each reason is its own +/// variant because they are different answers to give a human. #[derive(Debug, thiserror::Error)] pub enum BulkRefusal { /// High-risk items need their own confirmation, per item (§7.4). @@ -222,11 +196,11 @@ pub enum BulkRefusal { System(Error), } -/// §7.4 bulk decision. High-risk items are refused unless confirmed individually, -/// and one refused item never rolls back the ones that were decided. -/// -/// `items` carries the identity and diff each review was displayed with, so the -/// approval-echo rule applies to bulk exactly as it does to a single approval. +/// §7.4 bulk decision. High-risk items are refused unless confirmed +/// individually, and one refused item never rolls back the ones that were +/// decided. `items` carries the identity and diff each review was displayed +/// with, so the approval-echo rule applies to bulk exactly as to a single +/// approval. pub fn bulk( db: &Db, actor: &str, @@ -262,7 +236,6 @@ pub fn bulk( Ok(out) } -/// The approval behind a candidate, if any. pub fn approval_for(db: &Db, candidate_id: i64) -> Result<Option<(i64, String)>> { approvals::for_candidate(db, candidate_id) } @@ -290,7 +263,6 @@ pub fn withdraw(db: &Db, actor: &str, release_id: i64, reason: &str) -> Result<( }) } -/// The pkgbase's accepted release pointer, exposed for callers that need it. pub fn current_accepted(db: &Db, pkgbase: &str) -> Result<Option<ReleaseRow>> { db::accepted_release(db, pkgbase) } |
