Add a helper method to consolidate feature flag, license, and group membership checks
As part of https://gitlab.com/gitlab-org/gitlab-ce/issues/49619, we're regularly going to need to perform three "feature gate" checks:
- Is this feature flag enabled?
- Is this feature available to the current license?
- Is this feature available to the current user (via group membership in
gitlab-com
, for example)
For the third, this is similar to what we already do in Gitlab::PerformanceBar.enabled?
, but will need to be made more generic.
The cleanest solution will likely be to have a helper method that wraps up these three checks into a single call, such as:
# NOTE: Not set on this name, it might be too ambiguous or easily confused
def licensed_feature_available?(feature)
Feature.enabled?(feature) &&
License.feature_available?(feature) &&
# some other check similar to `Gitlab::PerformanceBar.enabled?`
end
# elsewhere...
if licensed_feature_available?(:batch_comments)
# Add additional logic for batch comments
end
Note that although this method should include a License
check in EE, this also needs to be available for CE, where that check can be a no-op.
cc @marin @smcgivern @mdelaossa @andr3 from our call about this this morning.
cc @yorickpeterse as this will likely be relevant to us as part of gitlab-com/www-gitlab-com!13471 (merged).