|
@@ -19,6 +19,18 @@ module Gql::Concerns::HandlesAuthorization
|
|
|
true # Authorization is granted by default.
|
|
|
end
|
|
|
|
|
|
+ # Helper method to check pundit authorization of the current user for a given object.
|
|
|
+ def pundit_authorize!(record, query = :show?)
|
|
|
+ Pundit.authorize(context.current_user, record, query)
|
|
|
+ end
|
|
|
+
|
|
|
+ # Helper method to check pundit authorization of the current user for a given object.
|
|
|
+ def pundit_authorized?(record, query = :show?)
|
|
|
+ # Invoke policy directly to get back the actual result,
|
|
|
+ # not the original object as returned by 'authorize'.
|
|
|
+ Pundit.policy(context.current_user, record).public_send(query)
|
|
|
+ end
|
|
|
+
|
|
|
#
|
|
|
# Internal methods
|
|
|
#
|