mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-12 01:48:20 +02:00
2 KiB
2 KiB
Adding feature flags
Feature flags are booleans (stored in our DB as the WaffleFlag
object) that programmatically disable/enable "features" (such as DNS hosting) for a specified set of users.
We use django-waffle for our feature flags. Waffle makes using flags fairly straight forward.
Adding feature flags through django admin
- On the app, navigate to
\admin
. - Under models, click
Waffle flags
. - Click
Add waffle flag
. - Add the model as you would normally. Refer to waffle's documentation regarding attributes for more information on them.
Enabling a feature flag
- On the app, navigate to
\admin
. - Under models, click
Waffle flags
. - Click the featue flag record. This should exist by default, if not - create one with that name.
- (Important) Set the field
Everyone
toUnknown
. This field overrides all other settings when set to anything else. - Configure the settings as you see fit.
Enabling a feature flag with portfolio permissions
- Go to file
context_processors.py
- Add feature flag name to the
porfolio_context
within theportfolio_permissions
method. - For the conditional under
if portfolio
, add the feature flag name, and assign the appropiate permission that are in theuser.py
model.
Note:
- If your use case includes non org, you want to add a feature flag outside of it, you can just update the portfolio context outside of the if statement.
Using feature flags as boolean values
Waffle provides a boolean called flag_is_active
that you can use as you otherwise would a boolean. This boolean requires a request object and the flag name.
Using feature flags to disable/enable views
Waffle provides a decorator that you can use to enable/disable views. When disabled, the view will return a 404 if said user tries to navigate to it.