filters_controller.rb 1.14 KB
Newer Older
Rob Colbert's avatar
Rob Colbert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
# frozen_string_literal: true

class FiltersController < ApplicationController
  include Authorization

  layout 'admin'

  before_action :set_filters, only: :index
  before_action :set_filter, only: [:edit, :update, :destroy]
  before_action :set_body_classes

  def index
    @filters = current_account.custom_filters
  end

  def new
    @filter = current_account.custom_filters.build
  end

  def create
    @filter = current_account.custom_filters.build(resource_params)

    if @filter.save
      redirect_to filters_path
    else
      render action: :new
    end
  end

  def edit; end

  def update
    if @filter.update(resource_params)
      redirect_to filters_path
    else
      render action: :edit
    end
  end

  def destroy
    @filter.destroy
    redirect_to filters_path
  end

  private

  def set_filters
    @filters = current_account.custom_filters
  end

  def set_filter
    @filter = current_account.custom_filters.find(params[:id])
  end

  def resource_params
    params.require(:custom_filter).permit(:phrase, :expires_in, :irreversible, :whole_word, context: [])
  end

  def set_body_classes
    @body_classes = 'admin'
  end
end