Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/group_variables.rb')
-rw-r--r--lib/api/group_variables.rb55
1 files changed, 33 insertions, 22 deletions
diff --git a/lib/api/group_variables.rb b/lib/api/group_variables.rb
index d3ca1c79e73..e7b8cd10197 100644
--- a/lib/api/group_variables.rb
+++ b/lib/api/group_variables.rb
@@ -13,18 +13,18 @@ module API
resource :groups, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get group-level variables' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
use :pagination
end
get ':id/variables' do
variables = user_group.variables
- present paginate(variables), with: Entities::Variable
+ present paginate(variables), with: Entities::Ci::Variable
end
desc 'Get a specific variable from a group' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
@@ -36,12 +36,12 @@ module API
break not_found!('GroupVariable') unless variable
- present variable, with: Entities::Variable
+ present variable, with: Entities::Ci::Variable
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Create a new variable in a group' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
@@ -51,19 +51,21 @@ module API
optional :variable_type, type: String, values: ::Ci::GroupVariable.variable_types.keys, desc: 'The type of variable, must be one of env_var or file. Defaults to env_var'
end
post ':id/variables' do
- variable_params = declared_params(include_missing: false)
-
- variable = user_group.variables.create(variable_params)
+ variable = ::Ci::ChangeVariableService.new(
+ container: user_group,
+ current_user: current_user,
+ params: { action: :create, variable_params: declared_params(include_missing: false) }
+ ).execute
if variable.valid?
- present variable, with: Entities::Variable
+ present variable, with: Entities::Ci::Variable
else
render_validation_error!(variable)
end
end
desc 'Update an existing variable from a group' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
optional :key, type: String, desc: 'The key of the variable'
@@ -74,32 +76,41 @@ module API
end
# rubocop: disable CodeReuse/ActiveRecord
put ':id/variables/:key' do
- variable = user_group.variables.find_by(key: params[:key])
-
- break not_found!('GroupVariable') unless variable
-
- variable_params = declared_params(include_missing: false).except(:key)
+ variable = ::Ci::ChangeVariableService.new(
+ container: user_group,
+ current_user: current_user,
+ params: { action: :update, variable_params: declared_params(include_missing: false) }
+ ).execute
- if variable.update(variable_params)
- present variable, with: Entities::Variable
+ if variable.valid?
+ present variable, with: Entities::Ci::Variable
else
render_validation_error!(variable)
end
+ rescue ::ActiveRecord::RecordNotFound
+ not_found!('GroupVariable')
end
# rubocop: enable CodeReuse/ActiveRecord
desc 'Delete an existing variable from a group' do
- success Entities::Variable
+ success Entities::Ci::Variable
end
params do
requires :key, type: String, desc: 'The key of the variable'
end
# rubocop: disable CodeReuse/ActiveRecord
delete ':id/variables/:key' do
- variable = user_group.variables.find_by(key: params[:key])
- not_found!('GroupVariable') unless variable
-
- destroy_conditionally!(variable)
+ variable = user_group.variables.find_by!(key: params[:key])
+
+ destroy_conditionally!(variable) do |target_variable|
+ ::Ci::ChangeVariableService.new(
+ container: user_group,
+ current_user: current_user,
+ params: { action: :destroy, variable_params: declared_params(include_missing: false) }
+ ).execute
+ end
+ rescue ::ActiveRecord::RecordNotFound
+ not_found!('GroupVariable')
end
# rubocop: enable CodeReuse/ActiveRecord
end