mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user