mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:21:19 +08:00
FIX: Staff should be able to updates polls when edit window expires.
https://meta.discourse.org/t/moderators-cannot-remove-polls-from-posts/81804/7?u=tgxworld
This commit is contained in:
@ -18,8 +18,10 @@ module DiscoursePoll
|
|||||||
poll_edit_window_mins = SiteSetting.poll_edit_window_mins
|
poll_edit_window_mins = SiteSetting.poll_edit_window_mins
|
||||||
|
|
||||||
if post.created_at < poll_edit_window_mins.minutes.ago && has_votes
|
if post.created_at < poll_edit_window_mins.minutes.ago && has_votes
|
||||||
# cannot add/remove/rename polls
|
is_staff = User.staff.where(id: post.last_editor_id).exists?
|
||||||
if polls.keys.sort != previous_polls.keys.sort
|
|
||||||
|
# non staff users cannot add/remove/rename polls
|
||||||
|
if !is_staff && (polls.keys.sort != previous_polls.keys.sort)
|
||||||
post.errors.add(:base, I18n.t(
|
post.errors.add(:base, I18n.t(
|
||||||
"poll.edit_window_expired.cannot_change_polls", minutes: poll_edit_window_mins
|
"poll.edit_window_expired.cannot_change_polls", minutes: poll_edit_window_mins
|
||||||
))
|
))
|
||||||
@ -28,10 +30,10 @@ module DiscoursePoll
|
|||||||
end
|
end
|
||||||
|
|
||||||
# deal with option changes
|
# deal with option changes
|
||||||
if User.staff.where(id: post.last_editor_id).exists?
|
if is_staff
|
||||||
# staff can only edit options
|
# staff can edit options
|
||||||
polls.each_key do |poll_name|
|
polls.each_key do |poll_name|
|
||||||
if polls[poll_name]["options"].size != previous_polls[poll_name]["options"].size && previous_polls[poll_name]["voters"].to_i > 0
|
if polls.dig(poll_name, "options")&.size != previous_polls.dig(poll_name, "options")&.size && previous_polls.dig(poll_name, "voters").to_i > 0
|
||||||
post.errors.add(:base, I18n.t(
|
post.errors.add(:base, I18n.t(
|
||||||
"poll.edit_window_expired.staff_cannot_add_or_remove_options",
|
"poll.edit_window_expired.staff_cannot_add_or_remove_options",
|
||||||
minutes: poll_edit_window_mins
|
minutes: poll_edit_window_mins
|
||||||
|
@ -297,6 +297,21 @@ describe DiscoursePoll::PollsUpdater do
|
|||||||
context "staff" do
|
context "staff" do
|
||||||
let(:another_user) { Fabricate(:user) }
|
let(:another_user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
another_post.update_attributes!(last_editor_id: User.staff.first.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should allow staff to add polls" do
|
||||||
|
message = MessageBus.track_publish do
|
||||||
|
described_class.update(another_post, two_polls)
|
||||||
|
end.first
|
||||||
|
|
||||||
|
expect(another_post.errors.full_messages).to eq([])
|
||||||
|
|
||||||
|
expect(message.data[:post_id]).to eq(another_post.id)
|
||||||
|
expect(message.data[:polls]).to eq(two_polls)
|
||||||
|
end
|
||||||
|
|
||||||
it "should not allow staff to add options if votes have been casted" do
|
it "should not allow staff to add options if votes have been casted" do
|
||||||
another_post.update_attributes!(last_editor_id: User.staff.first.id)
|
another_post.update_attributes!(last_editor_id: User.staff.first.id)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user