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 +++++++++- test/models/node_trash_test.rb | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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( diff --git a/test/models/node_trash_test.rb b/test/models/node_trash_test.rb index 07e5bc6..52069d7 100644 --- a/test/models/node_trash_test.rb +++ b/test/models/node_trash_test.rb @@ -155,4 +155,14 @@ class NodeTrashTest < ActiveSupport::TestCase assert_equal Node.root, node.reload.suggested_restore_parent end + + test "trashed nodes and the Trash itself stay out of the drafts surfaces" do + Node.trash + node = create_node_with_published_page + node.trash!(@user1) + + ids = Node.drafts_and_autosaves.pluck(:id) + assert_not_includes ids, Node.trash.id + assert_not_includes ids, node.id + end end -- cgit v1.3