From d90ba22e5eb5a7884235d062a7d1bb4f2a6bb04f Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 18 Jul 2026 03:42:22 +0200 Subject: Keep the Trash out of the drafts surfaces --- app/models/node.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/models/node.rb') diff --git a/app/models/node.rb b/app/models/node.rb index 8d0756a..19669ca 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -35,6 +35,14 @@ class Node < ApplicationRecord :allow_nil => true, :if => :default_template_name_changed? + # Everything outside the Trash subtree, the Trash node included. + # Relies on unique_name being authoritative for tree position -- + # the same trust public routing places in it. + scope :not_in_trash, -> { + where.not(:unique_name => CccConventions::TRASH_SLUG) + .where("unique_name NOT LIKE ?", "#{CccConventions::TRASH_SLUG}/%") + } + # Class methods # Returns a page for a given node. If no revision is supplied, it returns @@ -504,7 +512,7 @@ class Node < ApplicationRecord end def self.drafts_and_autosaves(current_user_id: nil) - scope = where("draft_id IS NOT NULL OR autosave_id IS NOT NULL") + 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 scope.order( -- cgit v1.3