Files
docuseal/app/controllers/api/api_base_controller.rb
T

41 lines
922 B
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
module Api
class ApiBaseController < ActionController::API
include ActiveStorage::SetCurrent
2023-10-01 01:57:47 +03:00
include Pagy::Backend
DEFAULT_LIMIT = 10
MAX_LIMIT = 100
wrap_parameters false
2023-05-21 17:59:36 +03:00
before_action :authenticate_user!
2023-09-17 00:45:57 +03:00
check_authorization
if Rails.env.production?
rescue_from CanCan::AccessDenied do |e|
Rollbar.error(e) if defined?(Rollbar)
render json: { error: e.message }, status: :forbidden
end
end
2023-05-21 17:59:36 +03:00
private
2023-10-01 01:57:47 +03:00
def paginate(relation)
result = relation.order(id: :desc)
2023-11-06 13:18:03 +02:00
.limit([params.fetch(:limit, DEFAULT_LIMIT).to_i, MAX_LIMIT].min)
2023-10-01 01:57:47 +03:00
result = result.where('id < ?', params[:after]) if params[:after].present?
result = result.where('id > ?', params[:before]) if params[:before].present?
result
end
2023-05-21 17:59:36 +03:00
def current_account
current_user&.account
end
end
end