1 # frozen_string_literal: true
3 class ReportsController < ApplicationController
6 before_action :authorize_web
7 before_action :set_locale
8 before_action :check_database_readable
12 before_action :check_database_writable, :only => [:new, :create]
15 if required_new_report_params_present?
17 @report.issue = Issue.find_or_initialize_by(create_new_report_params)
24 @report = current_user.reports.new(report_params)
26 .create_with(:assigned_role => default_assigned_role)
27 .find_or_initialize_by(issue_params)
30 @report.issue.assigned_role = "administrator" if default_assigned_role == "administrator"
31 @report.issue.reopen unless @report.issue.open?
34 @report.issue.reported_user&.spam_check
36 redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report")
38 flash.now[:warning] = t(".provide_details")
39 render :action => "new"
45 def required_new_report_params_present?
46 create_new_report_params["reportable_id"].present? && create_new_report_params["reportable_type"].present?
49 def create_new_report_params
50 params.permit(:reportable_id, :reportable_type)
54 params.expect(:report => [:details, :category])
58 params.require(:report).require(:issue).permit(:reportable_id, :reportable_type)
61 def default_assigned_role
62 case issue_params[:reportable_type]
66 case report_params[:category]
67 when "vandal" then "moderator"