1 class IssuesController < ApplicationController
 
   4   before_action :authorize_web
 
   5   before_action :require_user
 
   6   before_action :check_permission, only: [:index, :show, :resolve,:open,:ignore,:comment]
 
   7   before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
 
  14     @read_reports = @issue.read_reports
 
  15     @unread_reports = @issue.unread_reports
 
  16     @comments = @issue.comments
 
  17     @related_issues = @issue.user.issues
 
  21     unless create_new_issue_params.blank?
 
  22       @issue = Issue.find_or_initialize_by(create_new_issue_params)
 
  27     @issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
 
  29       @issue = Issue.find_or_initialize_by(issue_params)
 
  30       @admins = UserRole.where(role: "administrator")
 
  31       @admins.each do |admin|
 
  32         Notifier.new_issue_notification(User.find(admin.user_id)).deliver_now
 
  35     if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
 
  36       @report = @issue.reports.build(report_params)
 
  37       details =  params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
 
  38       @report.reporter_user_id = @user.id
 
  39       @report.details = details
 
  41         redirect_to root_path, notice: t('issues.create.successful_report')
 
  44       redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.create.provide_details')
 
  49     @issue = Issue.find_by(issue_params)
 
  50     if params[:report][:details] and (params[:spam] or params[:offensive] or params[:threat] or params[:vandal] or params[:other])
 
  51       @report = @issue.reports.where(reporter_user_id: @user.id).first
 
  52       details =  params[:report][:details].to_s + "||" + params[:spam].to_s + "||" + params[:offensive].to_s + "||" + params[:threat].to_s + "||" + params[:vandal].to_s + "||" + params[:other].to_s
 
  53       @report.details = details    
 
  55         redirect_to root_path, notice: t('issues.update.successful_update')
 
  58       redirect_to new_issue_path(reportable_type: @issue.reportable_type,reportable_id: @issue.reportable_id, reported_user_id: @issue.reported_user_id), notice: t('issues.update.provide_details')
 
  63     @issue = Issue.find(params[:id])
 
  64     @issue_comment = @issue.comments.build(issue_comment_params)
 
  65     @issue_comment.commenter_user_id = @user.id
 
  74       redirect_to @issue, notice: t('issues.resolved')
 
  83       redirect_to @issue, notice: t('issues.ignored')
 
  92       redirect_to @issue, notice: t('issues.reopened')
 
 101       @issue = Issue.find(params[:id])
 
 105       unless @user.administrator?
 
 106         flash[:error] = t("application.require_admin.not_an_admin")
 
 107         redirect_to root_path
 
 111     def create_new_issue_params
 
 112       params.permit(:reportable_id, :reportable_type, :reported_user_id)
 
 116       params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id)
 
 120       params[:report].permit(:details)
 
 123     def issue_comment_params
 
 124       params.require(:issue_comment).permit(:body)