FIX: Staff can create and edit posts even if a topic is in slow mode. (#11057)

Additionally, ninja edits are no longer restricted.
This commit is contained in:
Roman Rizzi
2020-10-28 16:47:50 -03:00
committed by GitHub
parent e3de45359f
commit 2f32336081
8 changed files with 73 additions and 6 deletions

View File

@@ -219,4 +219,8 @@ module TopicGuardian
can_perform_action_available_to_group_moderators?(topic)
end
def affected_by_slow_mode?(topic)
topic&.slow_mode_seconds.to_i > 0 && @user.human? && !is_staff?
end
end

View File

@@ -159,7 +159,7 @@ class PostCreator
return false
end
if @topic&.slow_mode_seconds.to_i > 0
if guardian.affected_by_slow_mode?(@topic)
tu = TopicUser.find_by(user: @user, topic: @topic)
if tu&.last_posted_at

View File

@@ -144,6 +144,11 @@ class PostRevisor
@revised_at = @opts[:revised_at] || Time.now
@last_version_at = @post.last_version_at || Time.now
if guardian.affected_by_slow_mode?(@topic) && !ninja_edit?
@post.errors.add(:base, I18n.t("cannot_edit_on_slow_mode"))
return false
end
@version_changed = false
@post_successfully_saved = true
@@ -194,7 +199,7 @@ class PostRevisor
# We log staff/group moderator edits to posts
if (
(@editor.staff? || (@post.is_category_description? && Guardian.new(@editor).can_edit_category_description?(@post.topic.category))) &&
(@editor.staff? || (@post.is_category_description? && guardian.can_edit_category_description?(@post.topic.category))) &&
@editor.id != @post.user_id &&
@fields.has_key?('raw') &&
!@opts[:skip_staff_log]
@@ -639,4 +644,8 @@ class PostRevisor
@post_successfully_saved && !@topic_changes.errored?
end
def guardian
@guardian ||= Guardian.new(@editor)
end
end