FIX: Remove action buttons if post has already been reviewed (#20126)
* FIX: Remove action buttons if post has already been reviewed * Change the approve to reject test to expect an error * Adds a controller spec to ensure you can't edit a non-pending review item * Remove unnessary conditional
This commit is contained in:
parent
ec4ac1465e
commit
c540167982
|
@ -32,7 +32,7 @@ class ReviewableQueuedPost < Reviewable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless rejected?
|
if pending?
|
||||||
actions.add(:reject_post) do |a|
|
actions.add(:reject_post) do |a|
|
||||||
a.icon = "times"
|
a.icon = "times"
|
||||||
a.label = "reviewables.actions.reject_post.title"
|
a.label = "reviewables.actions.reject_post.title"
|
||||||
|
@ -45,6 +45,7 @@ class ReviewableQueuedPost < Reviewable
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_editable_fields(fields, guardian, args)
|
def build_editable_fields(fields, guardian, args)
|
||||||
|
if pending?
|
||||||
# We can edit category / title if it's a new topic
|
# We can edit category / title if it's a new topic
|
||||||
if topic_id.blank?
|
if topic_id.blank?
|
||||||
# Only staff can edit category for now, since in theory a category group reviewer could
|
# Only staff can edit category for now, since in theory a category group reviewer could
|
||||||
|
@ -57,6 +58,7 @@ class ReviewableQueuedPost < Reviewable
|
||||||
|
|
||||||
fields.add("payload.raw", :editor)
|
fields.add("payload.raw", :editor)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_options
|
def create_options
|
||||||
result = payload.symbolize_keys
|
result = payload.symbolize_keys
|
||||||
|
|
|
@ -394,14 +394,15 @@ RSpec.describe Reviewable, type: :model do
|
||||||
it "triggers a notification on approve -> reject to update status" do
|
it "triggers a notification on approve -> reject to update status" do
|
||||||
reviewable = Fabricate(:reviewable_queued_post, status: Reviewable.statuses[:approved])
|
reviewable = Fabricate(:reviewable_queued_post, status: Reviewable.statuses[:approved])
|
||||||
|
|
||||||
expect do reviewable.perform(moderator, :reject_post) end.to change {
|
expect { reviewable.perform(moderator, :reject_post) }.to raise_error(
|
||||||
Jobs::NotifyReviewable.jobs.size
|
Reviewable::InvalidAction,
|
||||||
}.by(1)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
job = Jobs::NotifyReviewable.jobs.last
|
it "triggers a notification on approve -> edit to update status" do
|
||||||
|
reviewable = Fabricate(:reviewable_queued_post, status: Reviewable.statuses[:approved])
|
||||||
|
|
||||||
expect(job["args"].first["reviewable_id"]).to eq(reviewable.id)
|
expect { reviewable.perform(moderator, :edit_post) }.to raise_error(Reviewable::InvalidAction)
|
||||||
expect(job["args"].first["updated_reviewable_ids"]).to contain_exactly(reviewable.id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "triggers a notification on reject -> approve to update status" do
|
it "triggers a notification on reject -> approve to update status" do
|
||||||
|
|
|
@ -663,6 +663,9 @@ RSpec.describe ReviewablesController do
|
||||||
fab!(:reviewable_post) { Fabricate(:reviewable_queued_post) }
|
fab!(:reviewable_post) { Fabricate(:reviewable_queued_post) }
|
||||||
fab!(:reviewable_topic) { Fabricate(:reviewable_queued_post_topic) }
|
fab!(:reviewable_topic) { Fabricate(:reviewable_queued_post_topic) }
|
||||||
fab!(:moderator) { Fabricate(:moderator) }
|
fab!(:moderator) { Fabricate(:moderator) }
|
||||||
|
fab!(:reviewable_approved_post) do
|
||||||
|
Fabricate(:reviewable_queued_post, status: Reviewable.statuses[:approved])
|
||||||
|
end
|
||||||
|
|
||||||
before { sign_in(moderator) }
|
before { sign_in(moderator) }
|
||||||
|
|
||||||
|
@ -740,6 +743,19 @@ RSpec.describe ReviewablesController do
|
||||||
expect(json["version"] > 0).to eq(true)
|
expect(json["version"] > 0).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "prevents you from updating an approved post" do
|
||||||
|
put "/review/#{reviewable_approved_post.id}.json?version=#{reviewable_approved_post.version}",
|
||||||
|
params: {
|
||||||
|
reviewable: {
|
||||||
|
payload: {
|
||||||
|
raw: "new raw content",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.code).to eq("403")
|
||||||
|
end
|
||||||
|
|
||||||
it "allows you to update a queued post (for new topic)" do
|
it "allows you to update a queued post (for new topic)" do
|
||||||
new_category_id = Fabricate(:category).id
|
new_category_id = Fabricate(:category).id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue