cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
260 stars 32 forks source link

Allow disabling flags based on a condition #51

Closed K900 closed 4 years ago

K900 commented 5 years ago

This may be a niche use case, but it would be nice to have an option to explicitly disable a flag based on a condition, e.g. for a specific QA user account, or for a predefined control group of users. Right now the only somewhat convenient way to achieve this behavior seems to be to introduce a second flag (e.g. NEVER_FLAG if the main flag is FLAG) and then check if FLAG and not NEVER_FLAG.

willbarton commented 5 years ago

@K900 I think you could accomplish this by simply creating the negating condition and making it required. For example:

# myconditions.py

from flags import conditions

@conditions.register('user is not')
def not_user(path, request=None, **kwargs):
    return request.user.get_username() != username
# settings.py
FLAGS = {
    'FLAG': [
        {'condition': 'user is not', 'value': ''qa.user, 'required': True},
        {'condition': 'boolean', 'value': True},
    ]
}

(Note: I haven't tried this, but conceptually, I think something like this could work.)

K900 commented 5 years ago

Yeah, this is more or less what I ended up with. It's still somewhat inconvenient, but it'll work for now.