diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-01-07 13:07:14 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-01-14 16:29:51 +0300 |
commit | 5396594a831de3f467f28c25c5856ba441b07ea7 (patch) | |
tree | 67adf2e591c65446a1d73ac90685e6073f867ad4 /lib/feature.rb | |
parent | 604073ffc38f938e36f613c592c444d56c99f49c (diff) |
Allow setting of feature gates per project
For features the feature gates are sometimes projects, not groups or
users. For example for git object pools:
https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/5872
This commit allows for setting feature group gates based on projects, by its
path as that seems most convenient.
Diffstat (limited to 'lib/feature.rb')
-rw-r--r-- | lib/feature.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/feature.rb b/lib/feature.rb index e048a443abc..e59cd70f822 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -102,4 +102,42 @@ class Feature expires_in: 1.hour) end end + + class Target + attr_reader :params + + def initialize(params) + @params = params + end + + def gate_specified? + %i(user project feature_group).any? { |key| params.key?(key) } + end + + def targets + [feature_group, user, project].compact + end + + private + + # rubocop: disable CodeReuse/ActiveRecord + def feature_group + return unless params.key?(:feature_group) + + Feature.group(params[:feature_group]) + end + # rubocop: enable CodeReuse/ActiveRecord + + def user + return unless params.key?(:user) + + UserFinder.new(params[:user]).find_by_username! + end + + def project + return unless params.key?(:project) + + Project.find_by_full_path(params[:project]) + end + end end |