From 180b5feba092db1339f7bb3217e91f0b22239bc5 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 27 Jul 2026 02:53:21 +0200 Subject: Surface held locks in the dashboard's work-in-progress widget A lock with no draft or autosave behind it was invisible to everyone including its holder, until the next editor collided with it. work_in_progress now admits those nodes, and the widget names the holder rather than the last editor on any locked row. Also flips the ordering to stalest-first, so a backlog reads as a queue rather than a feed, and gives the heading a real total: the count came from the already-limited relation and could never exceed five. --- app/models/node.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'app/models/node.rb') diff --git a/app/models/node.rb b/app/models/node.rb index 02502f6c..1e61f9fe 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -593,12 +593,15 @@ class Node < ApplicationRecord .distinct end - def self.drafts_and_autosaves(current_user_id: nil) - scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL").not_in_trash - return scope.order("updated_at DESC") unless current_user_id + # Nodes carrying unfinished work: a draft, an autosave, or a lock with + # neither behind it + def self.work_in_progress(current_user_id: nil) + scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL OR locking_user_id IS NOT NULL") + .not_in_trash + return scope.order("nodes.updated_at ASC") unless current_user_id scope.order( - Arel.sql(sanitize_sql_array(["CASE WHEN locking_user_id = ? THEN 0 ELSE 1 END, updated_at DESC", current_user_id])) + Arel.sql(sanitize_sql_array(["CASE WHEN locking_user_id = ? THEN 0 ELSE 1 END, nodes.updated_at ASC", current_user_id])) ) end -- cgit v1.3