NoamB/sorcery — Issue #229: Sorcery + overriden current_user method
Author: krzyzak
Created: 2012-02-28 21:36:56+00:00
State: open

Hi Noam,
First of all, thanks for sorcery – I really appreciate your work!

In my app, I've got a little bit tricky configuration. My sorcery model is Account, which belongs to STI'ed model User (actually to one of 3 subclasses).
Moreover, current_user method returns in my case not Account instance (ie. sorcery model), but user instance, so it's something like:

def current_user
@current_account ||= login_from_session
@current_account.user if @current_account
end

In very basic setup, it used to work preety nice, however, I've realised, that adding submodules is impossible now, because eg. activity_logging submodule uses current_user method, so

def register_last_activity_time_to_db
return unless Config.register_last_activity_time
return unless logged_in?
current_user.update_single_attribute(current_user.sorcery_config.last_activity_at_attribute_name, Time.now.in_time_zone)
end

won't work, because current_user isn't sorcery model.
I've started thinking about solution for that, and actually only one reasonable solution, which I'm considering is to provide new method (eg. current_sorcery_user), which by default returns current user(but is configurable, so I'll be able to change to return current_user.account), and sorcery internally will use that method.
What do you think about that solution?