2017-11-28 00:07:59 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class InvitesController < BaseController
|
|
|
|
def index
|
|
|
|
authorize :invite, :index?
|
|
|
|
|
2017-12-02 00:40:02 +09:00
|
|
|
@invites = filtered_invites.includes(user: :account).page(params[:page])
|
2017-11-28 00:07:59 +09:00
|
|
|
@invite = Invite.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
authorize :invite, :create?
|
|
|
|
|
|
|
|
@invite = Invite.new(resource_params)
|
|
|
|
@invite.user = current_user
|
|
|
|
|
|
|
|
if @invite.save
|
|
|
|
redirect_to admin_invites_path
|
|
|
|
else
|
|
|
|
@invites = Invite.page(params[:page])
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@invite = Invite.find(params[:id])
|
|
|
|
authorize @invite, :destroy?
|
|
|
|
@invite.expire!
|
|
|
|
redirect_to admin_invites_path
|
|
|
|
end
|
2017-12-01 20:26:57 +09:00
|
|
|
|
2018-08-19 07:58:53 +09:00
|
|
|
def deactivate_all
|
|
|
|
authorize :invite, :deactivate_all?
|
|
|
|
Invite.available.in_batches.update_all(expires_at: Time.now.utc)
|
|
|
|
redirect_to admin_invites_path
|
|
|
|
end
|
|
|
|
|
2017-12-01 20:26:57 +09:00
|
|
|
private
|
|
|
|
|
|
|
|
def resource_params
|
|
|
|
params.require(:invite).permit(:max_uses, :expires_in)
|
|
|
|
end
|
2017-12-02 00:40:02 +09:00
|
|
|
|
|
|
|
def filtered_invites
|
|
|
|
InviteFilter.new(filter_params).results
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
2020-01-20 23:55:03 +09:00
|
|
|
params.slice(*InviteFilter::KEYS).permit(*InviteFilter::KEYS)
|
2017-12-02 00:40:02 +09:00
|
|
|
end
|
2017-11-28 00:07:59 +09:00
|
|
|
end
|
|
|
|
end
|