1 class ReportsController < ApplicationController
4 before_action :authorize_web
5 before_action :set_locale
10 if required_new_report_params_present?
12 @report.issue = Issue.find_or_initialize_by(create_new_report_params)
14 redirect_to root_path, :notice => t(".missing_params")
19 @report = current_user.reports.new(report_params)
21 .create_with(:assigned_role => default_assigned_role)
22 .find_or_initialize_by(issue_params)
25 @report.issue.assigned_role = "administrator" if default_assigned_role == "administrator"
26 @report.issue.reopen unless @report.issue.open?
29 redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report")
31 flash.now[:notice] = t(".provide_details")
32 render :action => "new"
38 def required_new_report_params_present?
39 create_new_report_params["reportable_id"].present? && create_new_report_params["reportable_type"].present?
42 def create_new_report_params
43 params.permit(:reportable_id, :reportable_type)
47 params.require(:report).permit(:details, :category)
51 params.require(:report).require(:issue).permit(:reportable_id, :reportable_type)
54 def default_assigned_role
55 case issue_params[:reportable_type]
59 case report_params[:category]
60 when "vandal" then "moderator"