Sha256: 9fc03a68379706ad6ac45d6dd77b7ab770adaf08994d5cd063d69c08489bff73
Contents?: true
Size: 1.89 KB
Versions: 4
Compression:
Stored size: 1.89 KB
Contents
# frozen_string_literal: true require 'drillbit/authorizers/parameters' module Drillbit module Authorizers class Parameters class Filtering < Authorizers::Parameters def call params.permit(*authorized_params) end private def authorized_params @authorized_params ||= [ :sort, :token, :token_b64, :token_jwt, :format, :accept, :include, page: %i{ number size offset limit cursor }, filter: [ :query, {}, ], ] end def add_filterable_parameter(name) param = params. fetch(:filter, {}). fetch(name, nil) if param.class == Array authorized_params[7][:filter][1][name] = [] else authorized_params[7][:filter] << name end end def add_filterable_parameters(*names) names.each do |name| add_filterable_parameter(name) end end def add_filter_override(name:, value:, only_when_present: false, override_if_admin: false) add_filterable_parameter name return true if !override_if_admin && token.admin? param = params. fetch(:filter, {}). fetch(name, nil) return if !param && only_when_present params[:filter] ||= {} params[:filter][name] = value end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems