model_driven_api 3.7.1 → 3.7.2

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: ad2abbdb4e4fd783d5e4fadde50593be43e265aa857a0077655513b4e73f522e
4
- data.tar.gz: 323ffab731877ae6c4f8adb6b75bb358e12319a7b2d55ccc77aadd5e6e52d41d
3
+ metadata.gz: 83a93641c80f4714d3979c54cc931a039a2e7fce13f19064c2383d17dfd2a1ff
4
+ data.tar.gz: 2252a0af2913ead1b23bcb80e3c0207a8fffd07df9a24de027f2066e93f4603a
5
5
  SHA512:
6
- metadata.gz: 17322346aef3972a55db2fce8703abfe9b2148076509c3a14aa465c0d34e4d5ec41294366496a77fc7dc44c5dd324fe9513f77961338591ae035ac5d03e8575d
7
- data.tar.gz: f11a3a215784201aa30fb20b45b29a1df75ef8d1e8f045d2d15c6b8f45425487d40a9ba6315db679a827dabd2e54846ef78ee9950f5533861befb6342d59b150
6
+ metadata.gz: 5715f08361af0fef0b53916ee097d97592afe15932f61379b62014dd1850afed334eedb22163e1b3952b66d5ca5209ac3fc5af10127433951640901eda190860
7
+ data.tar.gz: d20f2cf91888026f26c76cb6053169f0e57b91cbf20d84c6ad37001fd9914f2eec485eb3f6314f3b3446e9fb8edeafbf64eaeee8ad50f7c75d4f186d0950fffa
@@ -13,7 +13,7 @@ class Api::V2::ApplicationController < ActionController::API
13
13
 
14
14
  # GET :controller/
15
15
  def index
16
- authorize! :index, @model unless public_custom_action?
16
+ authorize! :index, @model unless custom_action?
17
17
 
18
18
  # Custom Action
19
19
  status, result, status_number = check_for_custom_action
@@ -53,7 +53,7 @@ class Api::V2::ApplicationController < ActionController::API
53
53
  end
54
54
 
55
55
  def show
56
- authorize! :show, @record_id.presence || @model
56
+ authorize! :show, @record_id.presence || @model unless custom_action?
57
57
 
58
58
  # Custom Show Action
59
59
  status, result, status_number = check_for_custom_action
@@ -67,7 +67,7 @@ class Api::V2::ApplicationController < ActionController::API
67
67
  def create
68
68
  # Normal Create Action
69
69
  Rails.logger.debug("Creating a new record #{@record}")
70
- authorize! :create, @record.presence || @model unless public_custom_action?
70
+ authorize! :create, @record.presence || @model unless custom_action?
71
71
  # Custom Action
72
72
  status, result, status_number = check_for_custom_action
73
73
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -80,7 +80,7 @@ class Api::V2::ApplicationController < ActionController::API
80
80
  end
81
81
 
82
82
  def update
83
- authorize! :update, @record.presence || @model
83
+ authorize! :update, @record.presence || @model unless custom_action?
84
84
 
85
85
  # Custom Action
86
86
  status, result, status_number = check_for_custom_action
@@ -105,7 +105,7 @@ class Api::V2::ApplicationController < ActionController::API
105
105
  end
106
106
 
107
107
  def destroy
108
- authorize! :destroy, @record.presence || @model
108
+ authorize! :destroy, @record.presence || @model unless custom_action?
109
109
 
110
110
  # Custom Action
111
111
  status, result, status_number = check_for_custom_action
@@ -127,12 +127,18 @@ class Api::V2::ApplicationController < ActionController::API
127
127
 
128
128
  private
129
129
 
130
- # Returns true if the current request is for a NonCrudEndpoints custom action
131
- # that has been declared as public (no authentication required).
130
+ # Returns true for any custom action request (public or authenticated).
131
+ # Custom actions are self-contained and handle their own authorization logic;
132
+ # the generic CanCan model-level check is not applicable to them.
133
+ def custom_action?
134
+ params[:action_name].present?
135
+ end
136
+
137
+ # Returns true only for custom actions declared as public (no JWT required).
132
138
  # Forces autoloading of the Endpoints::<Model> class so the public_action_registry
133
139
  # is populated before authenticate_request checks it.
134
140
  def public_custom_action?
135
- return false unless request.url.include?("/custom_action/")
141
+ return false unless custom_action?
136
142
  model_name = params[:ctrl].to_s.classify
137
143
  action_name = params[:action_name].to_s
138
144
  # Ensure the endpoint class is loaded so its public_action declarations are registered.
@@ -2,7 +2,7 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
2
2
  include Pagy::Backend
3
3
 
4
4
  def index
5
- authorize! :index, @model unless public_custom_action?
5
+ authorize! :index, @model unless custom_action?
6
6
 
7
7
  status, result, status_number = check_for_custom_action
8
8
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -18,7 +18,7 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
18
18
  end
19
19
 
20
20
  def show
21
- authorize! :show, @record
21
+ authorize! :show, @record unless custom_action?
22
22
 
23
23
  status, result, status_number = check_for_custom_action
24
24
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -28,7 +28,7 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
28
28
  end
29
29
 
30
30
  def create
31
- authorize! :create, @model
31
+ authorize! :create, @model unless custom_action?
32
32
 
33
33
  status, result, status_number = check_for_custom_action
34
34
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -40,7 +40,7 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
40
40
  end
41
41
 
42
42
  def update
43
- authorize! :update, @record
43
+ authorize! :update, @record unless custom_action?
44
44
 
45
45
  status, result, status_number = check_for_custom_action
46
46
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -53,7 +53,7 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
53
53
  alias_method :patch, :update
54
54
 
55
55
  def destroy
56
- authorize! :destroy, @record
56
+ authorize! :destroy, @record unless custom_action?
57
57
 
58
58
  status, result, status_number = check_for_custom_action
59
59
  return render json: result, status: (status_number.presence || 200) if status == true
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.7.1".freeze
2
+ VERSION = "3.7.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni