Staff can enter and view deleted topics

This commit is contained in:
Robin Ward
2013-07-11 16:38:46 -04:00
parent eba662b988
commit 19c169540c
24 changed files with 176 additions and 83 deletions

View File

@@ -242,7 +242,11 @@ class Guardian
end
def can_create_post_on_topic?(topic)
is_staff? || (not(topic.closed? || topic.archived?) && can_create_post?(topic))
# No users can create posts on deleted topics
return false if topic.trashed?
is_staff? || (not(topic.closed? || topic.archived? || topic.trashed?) && can_create_post?(topic))
end
# Editing Methods
@@ -283,7 +287,9 @@ class Guardian
end
def can_delete_topic?(topic)
is_staff? && not(Category.exists?(topic_id: topic.id))
!topic.trashed? &&
is_staff? &&
!(Category.exists?(topic_id: topic.id))
end
def can_delete_post_action?(post_action)

View File

@@ -8,17 +8,18 @@ class TopicView
attr_accessor :draft, :draft_key, :draft_sequence
def initialize(topic_id, user=nil, options={})
@user = user
@topic = find_topic(topic_id)
raise Discourse::NotFound if @topic.blank?
@guardian = Guardian.new(user)
@guardian = Guardian.new(@user)
# Special case: If the topic is private and the user isn't logged in, ask them
# to log in!
if @topic.present? && @topic.private_message? && user.blank?
if @topic.present? && @topic.private_message? && @user.blank?
raise Discourse::NotLoggedIn.new
end
guardian.ensure_can_see!(@topic)
@post_number, @page = options[:post_number], options[:page].to_i
@@ -36,14 +37,13 @@ class TopicView
@filtered_posts = @filtered_posts.where('post_number = 1 or user_id in (select u.id from users u where username_lower in (?))', usernames)
end
@user = user
@initial_load = true
@index_reverse = false
filter_posts(options)
@draft_key = @topic.draft_key
@draft_sequence = DraftSequence.current(user, @draft_key)
@draft_sequence = DraftSequence.current(@user, @draft_key)
end
def canonical_path
@@ -317,6 +317,8 @@ class TopicView
end
def find_topic(topic_id)
Topic.where(id: topic_id).includes(:category).first
finder = Topic.where(id: topic_id).includes(:category)
finder = finder.with_deleted if @user.try(:staff?)
finder.first
end
end

View File

@@ -5,7 +5,6 @@ module Trashable
default_scope where(with_deleted_scope_sql)
# scope unscoped does not work
belongs_to :deleted_by, class_name: 'User'
end
@@ -26,6 +25,10 @@ module Trashable
end
end
def trashed?
deleted_at.present?
end
def trash!(trashed_by=nil)
# note, an argument could be made that the column should probably called trashed_at
# however, deleted_at is the terminology used in the UI