2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
class BansController < ApplicationController
|
2024-06-30 12:14:37 -04:00
|
|
|
before_action :moderator_only, except: %i[index show]
|
2020-05-18 20:05:08 -04:00
|
|
|
respond_to :html
|
2024-06-30 12:14:37 -04:00
|
|
|
respond_to :json, only: %i[index show]
|
2018-04-02 13:51:26 -04:00
|
|
|
helper_method :search_params
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def new
|
2018-04-12 19:02:41 -04:00
|
|
|
@ban = Ban.new(ban_params(:create))
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def edit
|
2010-11-19 13:44:11 -05:00
|
|
|
@ban = Ban.find(params[:id])
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def index
|
2018-04-02 13:51:26 -04:00
|
|
|
@bans = Ban.search(search_params).paginate(params[:page], :limit => params[:limit])
|
2024-06-30 12:14:37 -04:00
|
|
|
respond_with(@bans) do |format|
|
|
|
|
format.html { @bans = @bans.includes(:user, :banner) }
|
2017-04-13 01:06:02 -04:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def show
|
2010-11-19 13:44:11 -05:00
|
|
|
@ban = Ban.find(params[:id])
|
2016-10-16 09:06:08 -04:00
|
|
|
respond_with(@ban)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def create
|
2018-04-02 13:51:26 -04:00
|
|
|
@ban = Ban.create(ban_params(:create))
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2011-10-27 19:35:43 -04:00
|
|
|
if @ban.errors.any?
|
2010-11-19 13:44:11 -05:00
|
|
|
render :action => "new"
|
2011-10-27 19:35:43 -04:00
|
|
|
else
|
|
|
|
redirect_to ban_path(@ban), :notice => "Ban created"
|
2010-11-19 13:44:11 -05:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def update
|
2010-11-19 13:44:11 -05:00
|
|
|
@ban = Ban.find(params[:id])
|
2018-04-02 13:51:26 -04:00
|
|
|
if @ban.update(ban_params(:update))
|
2010-11-19 16:24:17 -05:00
|
|
|
redirect_to ban_path(@ban), :notice => "Ban updated"
|
2010-11-19 13:44:11 -05:00
|
|
|
else
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
end
|
|
|
|
|
2010-11-19 16:24:17 -05:00
|
|
|
def destroy
|
|
|
|
@ban = Ban.find(params[:id])
|
|
|
|
@ban.destroy
|
2010-12-01 18:50:04 -05:00
|
|
|
redirect_to bans_path, :notice => "Ban destroyed"
|
2010-11-19 16:24:17 -05:00
|
|
|
end
|
2018-04-02 13:51:26 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ban_params(context)
|
2019-08-10 03:22:34 -04:00
|
|
|
permitted_params = %i[reason duration expires_at is_permaban]
|
2018-04-02 13:51:26 -04:00
|
|
|
permitted_params += %i[user_id user_name] if context == :create
|
|
|
|
|
2018-05-09 14:56:01 -04:00
|
|
|
params.fetch(:ban, {}).permit(permitted_params)
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|