-
-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabling Flipper for multiple IDs? #656
Comments
I've considered adding I don't want to change the return value of flipper_id as that would ripple through the library. Everywhere would need to start using the first value instead of all and it would have to be clear in docs that first is used for most things but all are used for I think that #557 will help with this use case as then you could add |
That makes sense! Thank you For now, I'm considering wrapping # pseudo code
def enabled?(name, *args)
return Flipper.enabled?(name, *args) unless args.last.is_a?(User)
args_with_box = args.dup
args_with_box.pop # remove user to be replaced with org
args_with_box.push args.last.org # add org
return Flipper.enabled?(name, *args) || Flipper.enabled?(name, *args_with_org)
end Any thoughts?
That could make it easy to miss adding |
I'd probably just do: def enabled?(name, actors)
actors.any? { |actor| Flipper.enabled?(name, actor) }
end Or if you want to force always checking the user's org too: # * to always get array
def enabled?(name, *actors)
# flatten so passing array or single works
actors = actors.flatten
# get the user actors
user_actors = actors.select { |actor| actor.is_a?(User) }
# make sure the orgs are added automatically
user_actors.each { |user_actor| actors << user_actor.org unless actors.include?(user_actor.org) }
# check them all now
actors.any? { |actor| Flipper.enabled?(name, actor) }
end |
Closing to keep tidy but still very happy to respond. |
That's much simpler, thank you! I was copying the signature from here https://github.com/jnunemaker/flipper/blob/3dbd19323b50248eb090206b102dce4909d85223/lib/flipper/dsl.rb#L35 I wasn't sure what |
Warning! If you use code like the one above ( |
@jnunemaker With that said, I believe that multi-actor feature checking must be implemented by the Flipper gem itself to avoid unintended behaviour of calling |
@chernenkov-ayu-sbmt You can pass multiple actor IDs to Flipper.enabled?(:x, [actor1, actor2]) |
@bkeepers Great! Thank you very much for letting me know about it! |
For my use case, I need to enable Flipper for specific users or organizations.
I can add
||
and check for both, but that can add some complexity.Is there a way to simplify that?
If not, I was wondering if
flipper_id
could return astring
(current implementation) or astring[]
.Then Flipper could check on both.
Any thoughts?
The text was updated successfully, but these errors were encountered: