flipflop icon indicating copy to clipboard operation
flipflop copied to clipboard

Current user argunment

Open olvap opened this issue 5 years ago • 3 comments

Hello, I see in the documentation for custom strategies that can only check features if we have the user's session. The problem with that is that the current user is not always obtain the same way in different parts of a application (API token, sso, session) and I would like to have an option to pass the current_user object directly like:

def enabled?(feature, current_user)
  current_user.enabled_features[feature]
end

How could do it do something like this possible?

olvap avatar Jan 30 '20 14:01 olvap

I imagine you have a request object in all cases? So the solution would be to unify whatever differences you have by inspecting the request and retrieve the user information in different ways depending on the request parameters/hostname/session/path, etc.

rolftimmermans avatar Jan 30 '20 15:01 rolftimmermans

hey @rolftimmermans, thanks for your response,

so you mean something like this?

def enabled?(feature)
  current_user.enabled_features[feature]
end

def current_user
  if(request_has_session?)
    request.get_current_user_by_session_id
  elsif(request_has_a_token)
    request.get_current_user_by_token
  end
end

olvap avatar Jan 30 '20 16:01 olvap

Yes, pretty much that. Does that help?

rolftimmermans avatar Jan 31 '20 13:01 rolftimmermans