diff options
author | Rémy Coutable <remy@rymai.me> | 2017-07-05 21:55:27 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-07-06 11:18:26 +0200 |
commit | e5a7d1da8cfda5dc3755b6a0a1ed450415f39873 (patch) | |
tree | 409af2c78ed74fa045562f92bc3c17a045519c72 /lib/api/features.rb | |
parent | 00ac76cc4ce87954d770abae411c54eb8bf23360 (diff) | |
download | gitlab-ce-e5a7d1da8cfda5dc3755b6a0a1ed450415f39873.tar.gz |
Improve Features API and its docs and add a Changelog item
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/api/features.rb')
-rw-r--r-- | lib/api/features.rb | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/api/features.rb b/lib/api/features.rb index 21745916463..9385c6ca174 100644 --- a/lib/api/features.rb +++ b/lib/api/features.rb @@ -14,14 +14,12 @@ module API end end - def gate_target(params) - if params[:feature_group] - Feature.group(params[:feature_group]) - elsif params[:user] - User.find_by_username(params[:user]) - else - gate_value(params) - end + def gate_targets(params) + targets = [] + targets << Feature.group(params[:feature_group]) if params[:feature_group] + targets << User.find_by_username(params[:user]) if params[:user] + + targets end end @@ -42,18 +40,25 @@ module API requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time' optional :feature_group, type: String, desc: 'A Feature group name' optional :user, type: String, desc: 'A GitLab username' - mutually_exclusive :feature_group, :user end post ':name' do feature = Feature.get(params[:name]) - target = gate_target(params) + targets = gate_targets(params) value = gate_value(params) case value when true - feature.enable(target) + if targets.present? + targets.each { |target| feature.enable(target) } + else + feature.enable + end when false - feature.disable(target) + if targets.present? + targets.each { |target| feature.disable(target) } + else + feature.disable + end else feature.enable_percentage_of_time(value) end |