FIX: Make reviewable claiming work with deleted topics (#9040)

This fixes the case when the reviewed topic is deleted (for example, in
discourse-akismet).
This commit is contained in:
Dan Ungureanu 2020-02-25 15:49:23 +02:00 committed by GitHub
parent 5905930c32
commit 514c22e64b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 6 deletions

View File

@ -22,9 +22,14 @@ export default Component.extend({
return type.dasherize(); return type.dasherize();
}, },
@discourseComputed("siteSettings.reviewable_claiming", "reviewable.topic") @discourseComputed("reviewable.topic_id", "reviewable.removed_topic_id")
claimEnabled(claimMode, topic) { topicId(topicId, removedTopicId) {
return claimMode !== "disabled" && !!topic; return topicId || removedTopicId;
},
@discourseComputed("siteSettings.reviewable_claiming", "topicId")
claimEnabled(claimMode, topicId) {
return claimMode !== "disabled" && !!topicId;
}, },
@discourseComputed( @discourseComputed(

View File

@ -47,7 +47,7 @@
{{#if claimEnabled}} {{#if claimEnabled}}
<div class='claimed-actions'> <div class='claimed-actions'>
<span class='help'>{{{claimHelp}}}</span> <span class='help'>{{{claimHelp}}}</span>
{{reviewable-claimed-topic topicId=reviewable.topic.id claimedBy=reviewable.claimed_by}} {{reviewable-claimed-topic topicId=topicId claimedBy=reviewable.claimed_by}}
</div> </div>
{{/if}} {{/if}}

View File

@ -4,7 +4,7 @@ class ReviewableClaimedTopicsController < ApplicationController
requires_login requires_login
def create def create
topic = Topic.find_by(id: params[:reviewable_claimed_topic][:topic_id]) topic = Topic.with_deleted.find_by(id: params[:reviewable_claimed_topic][:topic_id])
guardian.ensure_can_claim_reviewable_topic!(topic) guardian.ensure_can_claim_reviewable_topic!(topic)
begin begin
@ -22,7 +22,7 @@ class ReviewableClaimedTopicsController < ApplicationController
end end
def destroy def destroy
topic = Topic.find_by(id: params[:id]) topic = Topic.with_deleted.find_by(id: params[:id])
raise Discourse::NotFound if topic.blank? raise Discourse::NotFound if topic.blank?
guardian.ensure_can_claim_reviewable_topic!(topic) guardian.ensure_can_claim_reviewable_topic!(topic)

View File

@ -36,6 +36,17 @@ describe ReviewableClaimedTopicsController do
expect(messages[0].data[:user][:id]).to eq(moderator.id) expect(messages[0].data[:user][:id]).to eq(moderator.id)
end end
it "works with deleted topics" do
SiteSetting.reviewable_claiming = 'optional'
first_post = topic.first_post || Fabricate(:post, topic: topic)
PostDestroyer.new(Discourse.system_user, first_post).destroy
post "/reviewable_claimed_topics.json", params: params
expect(response.status).to eq(200)
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(true)
end
it "raises an error if user cannot claim the topic" do it "raises an error if user cannot claim the topic" do
post "/reviewable_claimed_topics.json", params: params post "/reviewable_claimed_topics.json", params: params
@ -75,6 +86,17 @@ describe ReviewableClaimedTopicsController do
expect(messages[0].data[:user]).to eq(nil) expect(messages[0].data[:user]).to eq(nil)
end end
it "works with deleted topics" do
SiteSetting.reviewable_claiming = 'optional'
first_post = topic.first_post || Fabricate(:post, topic: topic)
PostDestroyer.new(Discourse.system_user, first_post).destroy
delete "/reviewable_claimed_topics/#{claimed.topic_id}.json"
expect(response.status).to eq(200)
expect(ReviewableClaimedTopic.where(user_id: moderator.id, topic_id: topic.id).exists?).to eq(false)
end
it "raises an error if topic is missing" do it "raises an error if topic is missing" do
delete "/reviewable_claimed_topics/111111111.json" delete "/reviewable_claimed_topics/111111111.json"