require_dependency "censor_bear/application_controller" module CensorBear class ReviewLogsController < ApplicationController before_action :set_review_log, except: [:index, :statistics] def index @q = ReviewLog.ransack(params[:q]) @condition = @q.result @condition = @condition.order(:created_at => :desc) @pagy, @review_logs = pagy(@condition) end def statistics if params[:q] && params[:q][:created_at_gteq].blank? params[:q][:created_at_gteq] = 1.month.ago end @q = ReviewLog.ransack(params[:q]) @condition = @q.result user_dict = @condition.group(:operator_id).count @operators_operate_count = change_operator_id_to_user_email(user_dict) end def raw_data end def destroy @review_log.destroy render turbo_stream: turbo_stream.remove(@review_log) end def reject @review_log.reject!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def undo_reject @review_log.undo_reject!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def remove @review_log.remove!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def undo_remove @review_log.undo_remove!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def approve @review_log.approve!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def undo_approve @review_log.undo_approve!(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end def ban_user @review_log.censor_ban_user(current_user) render turbo_stream: [turbo_stream.replace(@review_log, partial: "censor_bear/review_logs/row", locals: { review_log: @review_log }), turbo_stream.update("message-box", partial: "censor_bear/shared/message", locals: { message: "操作完毕" })] end private def set_review_log @review_log = ReviewLog.find(params[:id]) end def change_operator_id_to_user_email(user_dict) user_dict.each_with_object({}) do |(key, value), hash| tmp = CensorBear.config.user_class.constantize.find_by_id key hash[tmp&.email || "未设定email"] = value end end end end