Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

605 B
Raw Blame
class Api::V1::Accounts::Companies::BaseController < Api::V1::Accounts::BaseController
  before_action :ensure_companies_enabled!
  before_action :fetch_company

  private

  def ensure_companies_enabled!
    return if Current.account.feature_enabled?('companies')

    render json: { error: 'Companies are not enabled for this account' }, status: :forbidden
  end

  def fetch_company
    @company = Current.account.companies.find(params[:company_id])
  end

  def authorize_company_read!
    authorize(@company, :show?)
  end

  def authorize_company_update!
    authorize(@company, :update?)
  end
end