1 class ReportsController < ApplicationController
4 before_action :authorize_web
5 before_action :set_locale
6 before_action :check_database_readable
10 before_action :check_database_writable, :only => [:new, :create]
13 if required_new_report_params_present?
15 @report.issue = Issue.find_or_initialize_by(create_new_report_params)
17 redirect_to root_path, :notice => t(".missing_params")
22 @report = current_user.reports.new(report_params)
24 .create_with(:assigned_role => default_assigned_role)
25 .find_or_initialize_by(issue_params)
28 @report.issue.assigned_role = "administrator" if default_assigned_role == "administrator"
29 @report.issue.reopen unless @report.issue.open?
32 redirect_to helpers.reportable_url(@report.issue.reportable), :notice => t(".successful_report")
34 flash.now[:notice] = t(".provide_details")
35 render :action => "new"
41 def required_new_report_params_present?
42 create_new_report_params["reportable_id"].present? && create_new_report_params["reportable_type"].present?
45 def create_new_report_params
46 params.permit(:reportable_id, :reportable_type)
50 params.require(:report).permit(:details, :category)
54 params.require(:report).require(:issue).permit(:reportable_id, :reportable_type)
57 def default_assigned_role
58 case issue_params[:reportable_type]
62 case report_params[:category]
63 when "vandal" then "moderator"