mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
Previously, claiming a topic recorded a history entry on every reviewable it contained, including ones resolved long ago, and the transient lock taken whenever a moderator opens a confirmation dialog or an action modal was recorded the same way — even on the sites where claiming is disabled, which is the default. A flag that stayed open therefore accumulated an endless list of claim/unclaim pairs, most of them recording activity on other flags entirely. This change records only deliberate claims, and only against reviewables that are still pending, so a resolved item's timeline stops changing and the entries that remain correspond to real moderation decisions.
60 lines
1.8 KiB
Ruby
Vendored
60 lines
1.8 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class ReviewableClaimedTopicsController < ApplicationController
|
|
requires_login
|
|
|
|
def create
|
|
topic = Topic.with_deleted.find_by(id: params[:reviewable_claimed_topic][:topic_id])
|
|
automatic = params[:reviewable_claimed_topic][:automatic] == "true"
|
|
guardian.ensure_can_claim_reviewable_topic!(topic, automatic)
|
|
|
|
begin
|
|
claim =
|
|
ReviewableClaimedTopic.create!(user_id: current_user.id, topic_id: topic.id, automatic:)
|
|
rescue ActiveRecord::RecordInvalid
|
|
return render_json_error(I18n.t("reviewables.conflict"), status: 409)
|
|
end
|
|
|
|
claim.log_topic_history(:claimed, current_user)
|
|
|
|
notify_users(topic, current_user, automatic)
|
|
render json: success_json
|
|
end
|
|
|
|
def destroy
|
|
topic = Topic.with_deleted.find_by(id: params[:id])
|
|
automatic = params[:automatic] == "true"
|
|
if topic.blank? || !guardian.can_claim_reviewable_topic?(topic, automatic)
|
|
raise Discourse::NotFound
|
|
end
|
|
|
|
if claim = ReviewableClaimedTopic.find_by(topic_id: topic.id)
|
|
claim.delete
|
|
claim.log_topic_history(:unclaimed, current_user)
|
|
notify_users(topic, current_user, claim.automatic, claimed: false)
|
|
end
|
|
|
|
render json: success_json
|
|
end
|
|
|
|
private
|
|
|
|
def notify_users(topic, user, automatic, claimed: true)
|
|
group_ids = Set.new([Group::AUTO_GROUPS[:staff]])
|
|
|
|
if SiteSetting.enable_category_group_moderation? && topic.category
|
|
group_ids.merge(topic.category.moderating_group_ids)
|
|
end
|
|
|
|
data = {
|
|
topic_id: topic.id,
|
|
user: BasicUserSerializer.new(user, root: false).as_json,
|
|
automatic:,
|
|
claimed:,
|
|
}
|
|
|
|
MessageBus.publish("/reviewable_claimed", data, group_ids: group_ids.to_a)
|
|
|
|
Jobs.enqueue(:refresh_users_reviewable_counts, group_ids: group_ids.to_a)
|
|
end
|
|
end
|