You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be useful to have our pundit ApplicationPolicy raise an exception if current_user is nil.
The pundit README has an example of this for what it calls "closed systems (systems where you have to be a user to do anything). I think that "closed systems" are the most common kind of app we build so this would be a useful change.
Policies that don't require a current_user are 1) quite rare and 2) can just not inherit from ApplicationPolicy.
I'm happy to make the PR if we have consensus on this being a useful change.
The ApplicationPolicy we currently generate
# frozen_string_literal: trueclassApplicationPolicyattr_reader:user,:recorddefinitialize(user,record)@user=user@record=recordenddefindex?falseenddefshow?falseenddefcreate?falseenddefnew?create?enddefupdate?falseenddefedit?update?enddefdestroy?falseendclassScopedefinitialize(user,scope)@user=user@scope=scopeenddefresolveraiseNotImplementedError,"You must define #resolve in #{self.class}"endprivateattr_reader:user,:scopeendend
The ApplicationPolicy I am proposing we generate
classApplicationPolicyattr_reader:user,:recorddefinitialize(user,record)# We should immediately fail if we try to authorize an endpoint which does# not already require authentication as per# https://github.com/varvet/pundit#closed-systemsfailPundit::NotAuthorizedError,"must be logged in"unlessuser@user=user@record=recordenddefindex?falseenddefshow?falseenddefcreate?falseenddefnew?create?enddefupdate?falseenddefedit?update?enddefdestroy?falseendclassScopedefinitialize(user,scope)# We should immediately fail if we try to authorize an endpoint which does# not already require authentication as per# https://github.com/varvet/pundit#closed-systemsfailPundit::NotAuthorizedError,"must be logged in"unlessuser@user=user@scope=scopeenddefresolvefailNotImplementedError,"You must define #resolve in #{self.class}"endprivateattr_reader:user,:scopeendend
The text was updated successfully, but these errors were encountered:
I think it would be useful to have our pundit
ApplicationPolicy
raise an exception ifcurrent_user
isnil
.The pundit README has an example of this for what it calls "closed systems (systems where you have to be a user to do anything). I think that "closed systems" are the most common kind of app we build so this would be a useful change.
Policies that don't require a
current_user
are 1) quite rare and 2) can just not inherit fromApplicationPolicy
.I'm happy to make the PR if we have consensus on this being a useful change.
The ApplicationPolicy we currently generate
The ApplicationPolicy I am proposing we generate
The text was updated successfully, but these errors were encountered: