require "beetle_reporter/version" require "beetle_reporter/engine" require 'beetle_reporter/configuration' require 'aasm' require 'pagy' require 'hamlit' require 'discard' require 'turbo-rails' module BeetleReporter class << self def config return @config if defined?(@config) @config = Configuration.new @config.user_class = 'User' @config.current_user_method = 'current_user' @config.user_name_method = 'name' @config.main_app_root_path_method = 'root_path' @config.main_app_user_path_method = 'user_path' @config end def configure yield(config) end def add(record, user_id, reason) report = BeetleReporter::Report.pending.kept.find_by(record: record) if report report.user_ids << user_id unless report.user_ids.include?(user_id) report.reasons << reason unless report.reasons.include?(reason) # 未登录用户也有可能 report.reported_count += 1 report.user_ids = report.user_ids.uniq report.reasons = report.reasons.uniq report.save else report = BeetleReporter::Report.create(record: record, user_ids: [user_id], reasons: [reason], reported_count: 1, ) end report end end end