summaryrefslogtreecommitdiff
path: root/lib/api/features.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-10 13:40:11 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-10 13:40:11 +0200
commit6120dc261ab3700b7a19f683559494319b6a1b75 (patch)
tree9b9c9b0c5664f03af9732ebf3c0d01079533df94 /lib/api/features.rb
parent6c477d5b9496829eb5cb56ef32a0dd813be7dc16 (diff)
parentcd735170d3bc5e71d46ba1e37249ae713b7842f8 (diff)
downloadgitlab-ce-6120dc261ab3700b7a19f683559494319b6a1b75.tar.gz
Merge branch 'master' into backstage/gb/migrate-stages-statuses
* master: (587 commits) Increase GitLab QA screenshots size Fix QA test scenario for creating a new project Configure headless chrome screenshots correctly Allow passing exceptions when creating project services Also inject new route helpers into includers of GitlabRoutingHelper Remove many N+1 queries with merge requests API fix milestones finder failing spec Make wrong migrations idempotent Remove double border on last group row Update tests to test what the component renders and what the clicks calls Username and password are no longer stripped from import url on import Change `sign_out` usage to `gitlab_sign_out` in one spec Send Gitaly Repository with /api/internal/allowed Resolve "Liberation Mono weird font rendering on Fedora/openSUSE/other Linux distros" Force mobile view for admin projects fix spec Mark a subgroup-related spec as PostgreSQL-only Use vue .prevent to prevent the click Add members-list class to admin projects page Fix another typo in SHA attribute spec ... Conflicts: db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb db/schema.rb lib/gitlab/background_migration/migrate_build_stage_id_reference.rb spec/migrations/migrate_stage_id_reference_in_background_spec.rb
Diffstat (limited to 'lib/api/features.rb')
-rw-r--r--lib/api/features.rb29
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