From ddaa1e6ee822e7249541e6de2ec79ad4b7f55570 Mon Sep 17 00:00:00 2001 From: Kim Burgestrand Date: Fri, 22 Nov 2024 10:17:57 +0100 Subject: [PATCH] Regroup documentation for pundit_reset! --- lib/pundit/authorization.rb | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/pundit/authorization.rb b/lib/pundit/authorization.rb index 93a62405..2e57cff8 100644 --- a/lib/pundit/authorization.rb +++ b/lib/pundit/authorization.rb @@ -40,12 +40,33 @@ def pundit # Hook method which allows customizing which user is passed to policies and # scopes initialized by {#authorize}, {#policy} and {#policy_scope}. # + # @note Make sure to call `pundit_reset!` if this changes during a request. # @see https://github.com/varvet/pundit#customize-pundit-user + # @see #pundit + # @see #pundit_reset! # @return [Object] the user object to be used with pundit def pundit_user current_user end + # Clears the cached Pundit authorization data. + # + # This method should be called when the pundit_user is changed, + # such as during user switching, to ensure that stale authorization + # data is not used. Pundit caches authorization policies and scopes + # for the pundit_user, so calling this method will reset those + # caches and ensure that the next authorization checks are performed + # with the correct context for the new pundit_user. + # + # @return [void] + def pundit_reset! + @pundit = nil + @_pundit_policies = nil + @_pundit_policy_scopes = nil + @_pundit_policy_authorized = nil + @_pundit_policy_scoped = nil + end + # @!group Policies # Retrieves the policy for the given record, initializing it with the record @@ -217,27 +238,5 @@ def pundit_params_for(record) end # @!endgroup - - # @!group Customize Pundit user - - # Clears the cached Pundit authorization data. - # - # This method should be called when the pundit_user is changed, - # such as during user switching, to ensure that stale authorization - # data is not used. Pundit caches authorization policies and scopes - # for the pundit_user, so calling this method will reset those - # caches and ensure that the next authorization checks are performed - # with the correct context for the new pundit_user. - # - # @return [void] - def pundit_reset! - @pundit = nil - @_pundit_policies = nil - @_pundit_policy_scopes = nil - @_pundit_policy_authorized = nil - @_pundit_policy_scoped = nil - end - - # @!endgroup end end