pundit: convert ip bans to pundit.

This commit is contained in:
evazion
2020-03-18 01:36:54 -05:00
parent 9242bf522b
commit 92aeb8728f
4 changed files with 29 additions and 21 deletions

View File

@@ -1,35 +1,32 @@
class IpBansController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :moderator_only
def new
@ip_ban = IpBan.new
@ip_ban = authorize IpBan.new(permitted_attributes(IpBan))
respond_with(@ip_ban)
end
def create
@ip_ban = CurrentUser.ip_bans.create(ip_ban_params)
@ip_ban = authorize IpBan.new(creator: CurrentUser.user, **permitted_attributes(IpBan))
@ip_ban.save
respond_with(@ip_ban, :location => ip_bans_path)
end
def index
@ip_bans = IpBan.paginated_search(params, count_pages: true)
@ip_bans = authorize IpBan.paginated_search(params, count_pages: true)
@ip_bans = @ip_bans.includes(:creator) if request.format.html?
respond_with(@ip_bans)
end
def destroy
@ip_ban = IpBan.find(params[:id])
@ip_ban = authorize IpBan.find(params[:id])
@ip_ban.destroy
respond_with(@ip_ban)
end
private
def ip_ban_params
params.fetch(:ip_ban, {}).permit(%i[ip_addr reason])
end
def search_params
params.fetch(:search, {}).permit(%i[ip_addr order])
end