@@ -9,6 +9,7 @@ module Pundit
9
9
# end
10
10
# @see #pundit
11
11
# @api public
12
+ # @since v2.2.0
12
13
module Authorization
13
14
extend ActiveSupport ::Concern
14
15
@@ -30,6 +31,7 @@ module Authorization
30
31
# @return [Pundit::Context]
31
32
# @see #pundit_user
32
33
# @see #policies
34
+ # @since v2.3.2
33
35
def pundit
34
36
@pundit ||= Pundit ::Context . new (
35
37
user : pundit_user ,
@@ -45,6 +47,7 @@ def pundit
45
47
# @see #pundit
46
48
# @see #pundit_reset!
47
49
# @return [Object] the user object to be used with pundit
50
+ # @since v0.2.2
48
51
def pundit_user
49
52
current_user
50
53
end
@@ -59,6 +62,7 @@ def pundit_user
59
62
# with the correct context for the new pundit_user.
60
63
#
61
64
# @return [void]
65
+ # @since v2.5.0
62
66
def pundit_reset!
63
67
@pundit = nil
64
68
@_pundit_policies = nil
@@ -81,6 +85,7 @@ def pundit_reset!
81
85
# @return [record] Always returns the passed object record
82
86
# @see Pundit::Context#authorize
83
87
# @see #verify_authorized
88
+ # @since v0.1.0
84
89
def authorize ( record , query = nil , policy_class : nil )
85
90
query ||= "#{ action_name } ?"
86
91
@@ -94,13 +99,15 @@ def authorize(record, query = nil, policy_class: nil)
94
99
# @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
95
100
# @return [void]
96
101
# @see #verify_authorized
102
+ # @since v1.0.0
97
103
def skip_authorization
98
104
@_pundit_policy_authorized = :skipped
99
105
end
100
106
101
107
# @return [Boolean] wether or not authorization has been performed
102
108
# @see #authorize
103
109
# @see #skip_authorization
110
+ # @since v1.0.0
104
111
def pundit_policy_authorized?
105
112
!!@_pundit_policy_authorized
106
113
end
@@ -115,6 +122,7 @@ def pundit_policy_authorized?
115
122
# @return [void]
116
123
# @see #authorize
117
124
# @see #skip_authorization
125
+ # @since v0.1.0
118
126
def verify_authorized
119
127
raise AuthorizationNotPerformedError , self . class unless pundit_policy_authorized?
120
128
end
@@ -124,6 +132,7 @@ def verify_authorized
124
132
# Cache of policies. You should not rely on this method.
125
133
#
126
134
# @api private
135
+ # @since v1.0.0
127
136
def policies
128
137
@_pundit_policies ||= { }
129
138
end
@@ -137,6 +146,7 @@ def policies
137
146
# @see https://github.com/varvet/pundit#policies
138
147
# @param record [Object] the object we're retrieving the policy for
139
148
# @return [Object] instance of policy class with query methods
149
+ # @since v0.1.0
140
150
def policy ( record )
141
151
pundit . policy! ( record )
142
152
end
@@ -149,6 +159,7 @@ def policy(record)
149
159
# @param scope [Object] the object we're retrieving the policy scope for
150
160
# @param policy_scope_class [#resolve] the policy scope class we want to force use of
151
161
# @return [#resolve, nil] instance of scope class which can resolve to a scope
162
+ # @since v0.1.0
152
163
def policy_scope ( scope , policy_scope_class : nil )
153
164
@_pundit_policy_scoped = true
154
165
policy_scope_class ? policy_scope_class . new ( pundit_user , scope ) . resolve : pundit_policy_scope ( scope )
@@ -159,13 +170,15 @@ def policy_scope(scope, policy_scope_class: nil)
159
170
# @see https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
160
171
# @return [void]
161
172
# @see #verify_policy_scoped
173
+ # @since v1.0.0
162
174
def skip_policy_scope
163
175
@_pundit_policy_scoped = :skipped
164
176
end
165
177
166
178
# @return [Boolean] wether or not policy scoping has been performed
167
179
# @see #policy_scope
168
180
# @see #skip_policy_scope
181
+ # @since v1.0.0
169
182
def pundit_policy_scoped?
170
183
!!@_pundit_policy_scoped
171
184
end
@@ -181,6 +194,7 @@ def pundit_policy_scoped?
181
194
# @return [void]
182
195
# @see #policy_scope
183
196
# @see #skip_policy_scope
197
+ # @since v0.2.1
184
198
def verify_policy_scoped
185
199
raise PolicyScopingNotPerformedError , self . class unless pundit_policy_scoped?
186
200
end
@@ -190,6 +204,7 @@ def verify_policy_scoped
190
204
# Cache of policy scope. You should not rely on this method.
191
205
#
192
206
# @api private
207
+ # @since v1.0.0
193
208
def policy_scopes
194
209
@_pundit_policy_scopes ||= { }
195
210
end
@@ -206,6 +221,7 @@ def policy_scopes
206
221
# @note This also memoizes the instance with `scope` as the key.
207
222
# @see Pundit::Helper#policy_scope
208
223
# @api private
224
+ # @since v1.0.0
209
225
def pundit_policy_scope ( scope )
210
226
policy_scopes [ scope ] ||= pundit . policy_scope! ( scope )
211
227
end
@@ -228,6 +244,7 @@ def pundit_policy_scope(scope)
228
244
# @param action [Symbol, String] the name of the action being performed on the record (e.g. `:update`).
229
245
# If omitted then this defaults to the Rails controller action name.
230
246
# @return [Hash{String => Object}] the permitted attributes
247
+ # @since v1.0.0
231
248
def permitted_attributes ( record , action = action_name )
232
249
policy = policy ( record )
233
250
method_name = if policy . respond_to? ( "permitted_attributes_for_#{ action } " )
@@ -242,6 +259,7 @@ def permitted_attributes(record, action = action_name)
242
259
#
243
260
# @param record [Object] the object we're retrieving params for
244
261
# @return [ActionController::Parameters] the params
262
+ # @since v2.0.0
245
263
def pundit_params_for ( record )
246
264
params . require ( PolicyFinder . new ( record ) . param_key )
247
265
end
0 commit comments