Skip to content
Extraits de code Groupes Projets
report_controller.rb 1,1 ko
Newer Older
class ReportController < ApplicationController
  before_filter :authenticate_user!
  before_filter :redirect_unless_admin, :except => [:create]

  def index
Lukas Matt's avatar
Lukas Matt a validé
    @reports = Report.where(reviewed: false).all
  end

  def update
Lukas Matt's avatar
Lukas Matt a validé
    if report = Report.where(id: params[:id]).first
      report.mark_as_reviewed
Lukas Matt's avatar
Lukas Matt a validé
    redirect_to :action => :index
  end

  def destroy
Lukas Matt's avatar
Lukas Matt a validé
    if report = Report.where(id: params[:id]).first
      if report.destroy_reported_item
        flash[:notice] = I18n.t 'report.status.destroyed'
      else
        flash[:error] = I18n.t 'report.status.failed'
Lukas Matt's avatar
Lukas Matt a validé
    else
      flash[:error] = I18n.t 'report.status.failed'
Lukas Matt's avatar
Lukas Matt a validé
    redirect_to :action => :index
  end

  def create
    report = current_user.reports.new(report_params)
    if report.save
Lukas Matt's avatar
Lukas Matt a validé
      flash.now[:notice] = I18n.t 'report.status.created'
      render :nothing => true, :status => 200
Lukas Matt's avatar
Lukas Matt a validé
    else
      flash.now[:error] = I18n.t 'report.status.failed'
      render :nothing => true, :status => 409
Lukas Matt's avatar
Lukas Matt a validé
    def report_params
      params.require(:report).permit(:post_id, :post_type, :text)