forum: fix mods not being able to lock forum topics.
This commit is contained in:
@@ -18,7 +18,6 @@ class ForumPost < ApplicationRecord
|
|||||||
validates_presence_of :body
|
validates_presence_of :body
|
||||||
validate :validate_topic_is_unlocked
|
validate :validate_topic_is_unlocked
|
||||||
validate :topic_is_not_restricted, :on => :create
|
validate :topic_is_not_restricted, :on => :create
|
||||||
before_destroy :validate_topic_is_unlocked
|
|
||||||
after_save :delete_topic_if_original_post
|
after_save :delete_topic_if_original_post
|
||||||
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}", :forum_post_update)
|
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}", :forum_post_update)
|
||||||
@@ -103,12 +102,8 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_topic_is_unlocked
|
def validate_topic_is_unlocked
|
||||||
return if creator.is_moderator?
|
if topic.is_locked? && !updater.is_moderator?
|
||||||
return if topic.nil?
|
|
||||||
|
|
||||||
if topic.is_locked?
|
|
||||||
errors[:topic] << "is locked"
|
errors[:topic] << "is locked"
|
||||||
throw :abort
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,15 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
should "allow mods to lock forum topics" do
|
||||||
|
put_auth forum_topic_path(@forum_topic), @mod, params: { forum_topic: { is_locked: true }}
|
||||||
|
|
||||||
|
assert_redirected_to forum_topic_path(@forum_topic)
|
||||||
|
assert_equal(true, @forum_topic.reload.is_locked)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "destroy action" do
|
context "destroy action" do
|
||||||
setup do
|
setup do
|
||||||
as_user do
|
as_user do
|
||||||
|
|||||||
@@ -104,21 +104,20 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "belonging to a locked topic" do
|
context "belonging to a locked topic" do
|
||||||
setup do
|
setup do
|
||||||
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
|
@post = create(:forum_post, topic: @topic, body: "zzz")
|
||||||
@topic.update_attribute(:is_locked, true)
|
@topic.update(is_locked: true)
|
||||||
@post.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not be updateable" do
|
should "not be updateable" do
|
||||||
@post.update(body: "xxx")
|
@post.update(body: "xxx")
|
||||||
@post.reload
|
assert_equal(true, @post.invalid?)
|
||||||
assert_equal("zzz", @post.body)
|
assert_equal("zzz", @post.reload.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not be deletable" do
|
should "not be deletable" do
|
||||||
assert_difference("ForumPost.count", 0) do
|
@post.delete!
|
||||||
@post.destroy
|
assert_equal(true, @post.invalid?)
|
||||||
end
|
assert_equal(false, @post.reload.is_deleted)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user