chore: DRY up check_authorization method (#1351)

This commit is contained in:
Ronald Walker 2020-10-20 06:52:21 -07:00 committed by GitHub
parent bbef03edea
commit cbe9e06472
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 21 deletions

View file

@ -10,4 +10,10 @@ class Api::BaseController < ApplicationController
def authenticate_by_access_token?
request.headers[:api_access_token].present? || request.headers[:HTTP_API_ACCESS_TOKEN].present?
end
def check_authorization(model = nil)
model ||= controller_name.classify.constantize
authorize(model)
end
end

View file

@ -27,7 +27,7 @@ class Api::V1::Accounts::AgentsController < Api::V1::Accounts::BaseController
private
def check_authorization
authorize(User)
super(User)
end
def fetch_agent

View file

@ -41,10 +41,6 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
private
def check_authorization
authorize(Contact)
end
def build_contact_inbox
return if params[:inbox_id].blank?

View file

@ -55,10 +55,6 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
@agent_bot = AgentBot.find(params[:agent_bot]) if params[:agent_bot]
end
def check_authorization
authorize(Inbox)
end
def create_channel
case permitted_params[:channel][:type]
when 'web_widget'

View file

@ -28,10 +28,6 @@ class Api::V1::Accounts::LabelsController < Api::V1::Accounts::BaseController
@label = Current.account.labels.find(params[:id])
end
def check_authorization
authorize(Label)
end
def permitted_params
params.require(:label).permit(:title, :description, :color, :show_on_sidebar)
end

View file

@ -29,8 +29,4 @@ class Api::V1::Accounts::WebhooksController < Api::V1::Accounts::BaseController
def fetch_webhook
@webhook = Current.account.webhooks.find(params[:id])
end
def check_authorization
authorize(Webhook)
end
end

View file

@ -44,10 +44,6 @@ class Api::V1::AccountsController < Api::BaseController
private
def check_authorization
authorize(Account)
end
def confirmed?
super_admin? && params[:confirmed]
end