rhino-rails 4.8.0 → 4.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e5e5a25c72952be8b915169fd2f5320476a1414b20aba43428c636e92513188
4
- data.tar.gz: 48af3696d7a56d92fc1e9f7e270077f108579bf1e2701542e563d6a75f94dd4e
3
+ metadata.gz: c77838e9b0818c083a66439097840287fdfadcd94fe17f7e403b9a1c00e08322
4
+ data.tar.gz: 698536e45e86aed2abd48ba646c0ebc4e821511838c79db07e6525413ace80c5
5
5
  SHA512:
6
- metadata.gz: '099ea8dc9ecea149b1fd30cd56446fb107d474478cb669d39dbc1bb2d01a16a1669160f6912658da035fa9dc62e26a4639962ad9f661848919ca3b15178f59da'
7
- data.tar.gz: d9423c888d912f451312d5c0b3243dd1a1b43493ee4fb60378fafa17127c9f22f445cd0161197492e08543ce6946d2202cfef1a8891f7847e5677374f96c7991
6
+ metadata.gz: 52ec8339ccd944fcb4b3c071bc4829acaf37c1d401abfce18bec28648eac3005d7ca18c407ad3784bc541dcd16cf3238144c8ebd7bbc58ada65b8537f64e0515
7
+ data.tar.gz: '096db647db3f380fe23621e6fc31496321e857a80ce22911bc2133a7877a7e607a49be3e60cb08f88594030c784b9b3a6d3e8f9415969ed0188bfb11569e3ffc'
@@ -9,6 +9,12 @@ module Rhino
9
9
  # model that does not declare its own +rhino_route_key+. Default nil =
10
10
  # primary key (today's behavior, fully backward compatible).
11
11
  attr_accessor :route_key
12
+ # How many client-selectable named scopes one request may combine with the
13
+ # bracket form (?scope[a]=&scope[b][x]=1). Each scope is an arbitrary query
14
+ # fragment that may add joins or subqueries, so the number is capped: a
15
+ # request over the cap is refused with 403 "Too many scopes requested".
16
+ # Default 3 — a base scope, a window, and one more predicate.
17
+ attr_reader :max_scopes_per_request
12
18
  attr_reader :auth
13
19
 
14
20
  def initialize
@@ -33,6 +39,14 @@ module Rhino
33
39
  @client_path = nil
34
40
  @mobile_path = nil
35
41
  @route_key = nil
42
+ @max_scopes_per_request = 3
43
+ end
44
+
45
+ # A non-numeric or non-positive value would lock every scope out of every
46
+ # request, so it falls back to the default instead.
47
+ def max_scopes_per_request=(value)
48
+ value = value.to_i if value.respond_to?(:to_i)
49
+ @max_scopes_per_request = value.is_a?(Integer) && value.positive? ? value : 3
36
50
  end
37
51
 
38
52
  # Auth configuration accessor. Merges supplied keys over defaults so a host
@@ -12,10 +12,12 @@ module Rhino
12
12
  # - Fields: ?fields[posts]=id,title,status
13
13
  # - Includes: ?include=user,comments
14
14
  class QueryBuilder
15
- # How many named scopes one request may combine. Scopes are arbitrary query
16
- # fragments, so stacking many of them is a good way to build an accidental
17
- # cross join; three covers every real listing.
18
- MAX_SCOPES_PER_REQUEST = 3
15
+ # Fallback for how many named scopes one request may combine, used when no
16
+ # Rhino configuration is reachable. Apps set +config.max_scopes_per_request+.
17
+ #
18
+ # Scopes are arbitrary query fragments, so stacking many of them is a good
19
+ # way to build an accidental cross join; three covers every real listing.
20
+ DEFAULT_MAX_SCOPES_PER_REQUEST = 3
19
21
 
20
22
  attr_reader :scope, :model_class, :params
21
23
 
@@ -109,7 +111,7 @@ module Rhino
109
111
  { raw.to_s => "" }
110
112
  end
111
113
 
112
- raise Rhino::ScopeNotAllowedError, "Too many scopes requested" if requested.size > MAX_SCOPES_PER_REQUEST
114
+ raise Rhino::ScopeNotAllowedError, "Too many scopes requested" if requested.size > max_scopes_per_request
113
115
 
114
116
  permitted = permitted_scope_names
115
117
 
@@ -132,6 +134,14 @@ module Rhino
132
134
  end
133
135
  end
134
136
 
137
+ # How many named scopes this app allows in one request.
138
+ def max_scopes_per_request
139
+ configured = Rhino.config.try(:max_scopes_per_request)
140
+ configured.is_a?(Integer) && configured.positive? ? configured : DEFAULT_MAX_SCOPES_PER_REQUEST
141
+ rescue StandardError
142
+ DEFAULT_MAX_SCOPES_PER_REQUEST
143
+ end
144
+
135
145
  # Run one already-authorized named scope, passing the bound arguments in the
136
146
  # order the model declared them.
137
147
  def run_named_scope(name, entry, args)
data/lib/rhino/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rhino
4
- VERSION = "4.8.0"
4
+ VERSION = "4.8.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhino-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Cipolla