A merged ticket is read-only on the server, not just on the page (#920)
The Show page announced "This ticket has been merged and is read-only.",
hid the reply composer and withheld the Merge button — and that was the
whole guard. It was presentation, on one page.
The Edit link and the Split button were still rendered, `edit()` still
served the form (with its Status select blank, because `merged` was not
one of the five slugs the form hard-coded), and `update()` took the save
with `errors: {}`: status went back to `open` while `merged_into_id` kept
pointing at the merge target. The row that came out was live and
assignable in the All Open queue AND merged into another ticket, holding
none of its own messages because the merge had moved them — an empty
shell that reads as a real duplicate of the ticket it was folded into.
So the rule now lives on the server, once — `Ticket::isMerged()` and
`refuseIfMerged()` — and every write the page presents as unavailable
calls it: update, edit, split, participants add/remove, and a reply or an
attachment (both hidden by the banner, neither refused by its route).
Two deliberate choices:
- the guard reads `status === 'merged'`, NOT `merged_into_id !== null`.
Reading the pointer would look stricter and would freeze every row
this bug already minted (`status = open, merged_into_id = 56`), so
the only way to correct one would be SQL.
- it refuses with a redirect carrying the reason, not `abort(403)`.
The realistic way to arrive here is a page that was already open when
somebody else merged the ticket, and that operator is better served
by the sentence than by an error screen.
The blank Status select was the report's second symptom, and it was the
same defect one layer up: the five hard-coded options meant any ticket
whose status was not among them — `merged`, or any status added on the
Statuses settings tab — rendered with nothing selected, and the first
save silently rewrote the status to whatever happened to be showing. The
options now come from the same table `update()` validates against.
This commit is contained in:
@@ -8,6 +8,16 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Ticket extends Model
|
||||
{
|
||||
/** Set only by TicketController::merge(); never offered by any form. */
|
||||
public const STATUS_MERGED = 'merged';
|
||||
|
||||
/**
|
||||
* What every surface says when a write to a merged ticket is refused. The Show
|
||||
* page has displayed this sentence since merge shipped; #920 was that it was
|
||||
* only ever a sentence, with no server-side guard behind it.
|
||||
*/
|
||||
public const READ_ONLY_REASON = 'This ticket has been merged and is read-only.';
|
||||
|
||||
protected $fillable = [
|
||||
'number', 'group_id', 'submitter_id', 'assigned_to', 'project_id',
|
||||
'title', 'description', 'status', 'priority_id', 'due_date', 'merged_into_id',
|
||||
@@ -70,4 +80,20 @@ class Ticket extends Model
|
||||
{
|
||||
return $this->belongsTo(Ticket::class, 'merged_into_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* A merged ticket is read-only — its messages and attachments now live on the
|
||||
* ticket it was merged into, so it is a stub kept for its reference number and
|
||||
* the audit trail, not a ticket anyone can still work.
|
||||
*
|
||||
* `status === 'merged'` and NOT `merged_into_id !== null`, deliberately. #920
|
||||
* minted rows with `status = 'open', merged_into_id = 56` — the very rows this
|
||||
* guard exists to prevent — and reading the id would make each of those
|
||||
* permanently uneditable, i.e. a row the product will not let anyone correct.
|
||||
* The status is the state; the id is the pointer that goes with it.
|
||||
*/
|
||||
public function isMerged(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_MERGED;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user