implement account locking/unlocking

This commit is contained in:
Bilal
2020-09-08 16:25:32 +03:00
parent 3db230de9b
commit 9bafbe36db
12 changed files with 83 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
class AccountLocksController < ApplicationController
before_action :set_account
def create
authorize :account_lock, :create?
@account.update(locked: true)
redirect_to admin_accounts_path, notice: 'Account locked'
end
def destroy
authorize :account_lock, :destroy?
@account.update(locked: false)
redirect_to admin_accounts_path, notice: 'Account unlocked'
end
private
def set_account
if params[:id].present?
@account = Account.find(params[:id])
else
failure_redirect
end
rescue ActiveRecord::RecordNotFound
failure_redirect
end
def failure_redirect
redirect_to admin_accounts_path, alert: 'Failed to find the account'
end
end