2019-05-13 09:55:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-08 22:20:51 +08:00
|
|
|
class ReviewableClaimedTopicsController < ApplicationController
|
|
|
|
requires_login
|
|
|
|
|
|
|
|
def create
|
|
|
|
topic = Topic.find_by(id: params[:reviewable_claimed_topic][:topic_id])
|
|
|
|
guardian.ensure_can_claim_reviewable_topic!(topic)
|
2020-01-10 01:32:05 +08:00
|
|
|
ReviewableClaimedTopic.create(user_id: current_user.id, topic_id: topic.id)
|
|
|
|
render json: success_json
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
# This is just in case the validation fails under concurrency
|
2019-05-08 22:20:51 +08:00
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
topic = Topic.find_by(id: params[:id])
|
|
|
|
raise Discourse::NotFound if topic.blank?
|
|
|
|
|
|
|
|
guardian.ensure_can_claim_reviewable_topic!(topic)
|
|
|
|
ReviewableClaimedTopic.where(topic_id: topic.id).delete_all
|
|
|
|
|
|
|
|
render json: success_json
|
|
|
|
end
|
|
|
|
end
|