voormedia / flipflop

Flipflop lets you declare and manage feature flags in your Rails application.
MIT License
181 stars 32 forks source link

Current user argunment #32

Open olvap opened 4 years ago

olvap commented 4 years ago

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?

rolftimmermans commented 4 years ago

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.

olvap commented 4 years ago

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
rolftimmermans commented 4 years ago

Yes, pretty much that. Does that help?