dont raise an exception if the before_actions are not defined#28
dont raise an exception if the before_actions are not defined#28sudoaza wants to merge 1 commit intoTrestleAdmin:mainfrom
Conversation
|
aza seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Thanks for the contribution. This looks like it is probably okay to merge (once I fix the Travis errors). However I'm curious as to how you are defining your custom controller that is causing an issue? Is it a custom sessions controller (perhaps inheriting from |
|
It may be a mess i made because of my setup, i wanted to allow access to users logged with devise but who were internal and sharing the same model. This is what i did. lib/trestle/auth/controller_methods.rb module Trestle
module Auth
module ControllerMethods
extend ActiveSupport::Concern
included do
before_action :authenticate_user!
before_action :require_authenticated_user
end
protected
def require_internal!
redirect_to "/" unless current_user.internal?
return false
end
def require_authenticated_user
current_user && require_internal!
end
end
end
endconfig/initializers/trestle.rb Trestle.configure do |config|
# ...
config.auth.backend = :devise
config.auth.user_class = -> { User }
# afaik this is ignored, it didn't work by itself
config.auth.user_scope = -> { User.internal }
# ...
end
require File.join(Rails.root, 'lib', 'trestle', 'auth', 'controller_methods.rb')
Trestle::ApplicationController.send(:include, Trestle::Auth::ControllerMethods)versions:
Also, did i break the specs or is it unrelated? I can fix the PR |
This fixes an error when using a custom controller and not defining either of the before filters