summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/node.rb11
1 files changed, 7 insertions, 4 deletions
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
593 .distinct 593 .distinct
594 end 594 end
595 595
596 def self.drafts_and_autosaves(current_user_id: nil) 596 # Nodes carrying unfinished work: a draft, an autosave, or a lock with
597 scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL").not_in_trash 597 # neither behind it
598 return scope.order("updated_at DESC") unless current_user_id 598 def self.work_in_progress(current_user_id: nil)
599 scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL OR locking_user_id IS NOT NULL")
600 .not_in_trash
601 return scope.order("nodes.updated_at ASC") unless current_user_id
599 602
600 scope.order( 603 scope.order(
601 Arel.sql(sanitize_sql_array(["CASE WHEN locking_user_id = ? THEN 0 ELSE 1 END, updated_at DESC", current_user_id])) 604 Arel.sql(sanitize_sql_array(["CASE WHEN locking_user_id = ? THEN 0 ELSE 1 END, nodes.updated_at ASC", current_user_id]))
602 ) 605 )
603 end 606 end
604 607