summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-04 01:41:24 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-07-04 01:41:24 +0800
commit1cecc285cfa7dfb3c34b34f07ab0b51c2a970bde (patch)
treedb5cd7e4e9cedc03bdd402d8409fc390405a3b1b /lib/api
parent2c74e73f6f994346192acb2e723b026c2ec55f8b (diff)
parent68ac391435684352555ca5c4aca0e018face525a (diff)
downloadgitlab-ce-add-ci_variables-environment_scope.tar.gz
Merge remote-tracking branch 'upstream/master' into add-ci_variables-environment_scopeadd-ci_variables-environment_scope
* upstream/master: (79 commits) Reset @full_path to nil when cache expires add margin between captcha and register button Eagerly create a milestone that is used in a feature spec Adjust readme repo width Resolve "Issue Board -> "Remove from board" button when viewing an issue gives js error and fails" Fix rubocop offenses Make entrypoint and command keys to be array of strings Add issuable-list class to shared mr/issue lists to fix new responsive layout New navigation breadcrumbs Restore timeago translations in renderTimeago. Fix curl example paths (missing the 'files' segment) Automatically hide sidebar on smaller screens Fix typo in IssuesFinder comment Remove placeholder note when award emoji slash command is applied Make setSidebarHeight more efficient with SidebarHeightManager. Update CHANGELOG.md for 9.3.3 Resolve "More actions dropdown hidden by end of diff" Use Gitaly 0.14.0 Improve support for external issue references Make issuables_count_for_state public ...
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/features.rb39
-rw-r--r--lib/api/projects.rb2
2 files changed, 35 insertions, 6 deletions
diff --git a/lib/api/features.rb b/lib/api/features.rb
index cff0ba2ddff..21745916463 100644
--- a/lib/api/features.rb
+++ b/lib/api/features.rb
@@ -2,6 +2,29 @@ module API
class Features < Grape::API
before { authenticated_as_admin! }
+ helpers do
+ def gate_value(params)
+ case params[:value]
+ when 'true'
+ true
+ when '0', 'false'
+ false
+ else
+ params[:value].to_i
+ 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
+ end
+ end
+
resource :features do
desc 'Get a list of all features' do
success Entities::Feature
@@ -17,16 +40,22 @@ module API
end
params do
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)
+ value = gate_value(params)
- if %w(0 false).include?(params[:value])
- feature.disable
- elsif params[:value] == 'true'
- feature.enable
+ case value
+ when true
+ feature.enable(target)
+ when false
+ feature.disable(target)
else
- feature.enable_percentage_of_time(params[:value].to_i)
+ feature.enable_percentage_of_time(value)
end
present feature, with: Entities::Feature, current_user: current_user
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 886e97a2638..d0bd64b2972 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -1,4 +1,4 @@
-require 'declarative_policy'
+require_dependency 'declarative_policy'
module API
# Projects API