FEATURE: Add logging when claiming and unclaiming reviewable flagged posts (#8920)

This commit is contained in:
Jeff Wong 2020-02-10 15:40:01 -08:00 committed by GitHub
parent d7ae6b28e7
commit 1a1bb7a2c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,9 @@ class ReviewableClaimedTopicsController < ApplicationController
topic = Topic.find_by(id: params[:reviewable_claimed_topic][:topic_id])
guardian.ensure_can_claim_reviewable_topic!(topic)
ReviewableClaimedTopic.create(user_id: current_user.id, topic_id: topic.id)
topic.reviewables.find_each do |reviewable|
reviewable.log_history(:claimed, current_user)
end
render json: success_json
rescue ActiveRecord::RecordNotUnique
# This is just in case the validation fails under concurrency
@ -19,6 +22,9 @@ class ReviewableClaimedTopicsController < ApplicationController
guardian.ensure_can_claim_reviewable_topic!(topic)
ReviewableClaimedTopic.where(topic_id: topic.id).delete_all
topic.reviewables.find_each do |reviewable|
reviewable.log_history(:unclaimed, current_user)
end
render json: success_json
end

View File

@ -8,7 +8,9 @@ class ReviewableHistory < ActiveRecord::Base
@types ||= Enum.new(
created: 0,
transitioned: 1,
edited: 2
edited: 2,
claimed: 3,
unclaimed: 4
)
end

View File

@ -7,6 +7,7 @@ describe ReviewableClaimedTopicsController do
describe '#create' do
fab!(:topic) { Fabricate(:topic) }
fab!(:reviewable) { Fabricate(:reviewable_flagged_post, topic: topic) }
let(:params) do
{ reviewable_claimed_topic: { topic_id: topic.id } }
end
@ -32,6 +33,7 @@ describe ReviewableClaimedTopicsController do
post "/reviewable_claimed_topics.json", params: params
expect(response.code).to eq("200")
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(true)
expect(topic.reviewables.first.history.where(reviewable_history_type: ReviewableHistory.types[:claimed]).size).to eq(1)
end
it "won't an error if you claim twice" do
@ -45,7 +47,9 @@ describe ReviewableClaimedTopicsController do
end
describe '#destroy' do
fab!(:claimed) { Fabricate(:reviewable_claimed_topic) }
fab!(:topic) { Fabricate(:topic) }
fab!(:reviewable) { Fabricate(:reviewable_flagged_post, topic: topic) }
fab!(:claimed) { Fabricate(:reviewable_claimed_topic, topic: topic) }
before do
sign_in(moderator)
@ -66,6 +70,7 @@ describe ReviewableClaimedTopicsController do
delete "/reviewable_claimed_topics/#{claimed.topic_id}.json"
expect(response.code).to eq("200")
expect(ReviewableClaimedTopic.where(topic_id: claimed.topic_id).exists?).to eq(false)
expect(topic.reviewables.first.history.where(reviewable_history_type: ReviewableHistory.types[:unclaimed]).size).to eq(1)
end
end
end