summaryrefslogtreecommitdiff
path: root/app/controllers/projects
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-01-13 02:52:49 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-02-05 18:57:43 +0100
commitc64181ce4c57bc7ffbbcc51ee9bf0001bf83e1b1 (patch)
tree1fdfbfc4d4f9b2691c488b5223f74c3fdbbafd71 /app/controllers/projects
parentb91539d68fa21979001e122c912fad1c31dfd5d5 (diff)
downloadgitlab-ce-c64181ce4c57bc7ffbbcc51ee9bf0001bf83e1b1.tar.gz
Move variable loading into before_action
Diffstat (limited to 'app/controllers/projects')
-rw-r--r--app/controllers/projects/variables_controller.rb24
1 files changed, 12 insertions, 12 deletions
diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb
index 9aacb53078a..cd68018e033 100644
--- a/app/controllers/projects/variables_controller.rb
+++ b/app/controllers/projects/variables_controller.rb
@@ -1,5 +1,6 @@
class Projects::VariablesController < Projects::ApplicationController
before_action :variable, only: [:show, :update, :destroy]
+ before_action :variables, only: [:save_multiple]
before_action :authorize_admin_build!
layout 'project_settings'
@@ -35,10 +36,9 @@ class Projects::VariablesController < Projects::ApplicationController
def save_multiple
respond_to do |format|
format.json do
- variables = variables_from_params(variables_params)
- return head :bad_request unless variables.all?(&:valid?)
+ return head :bad_request unless @variables.all?(&:valid?)
- variables.each(&:save)
+ @variables.each(&:save)
head :ok
end
end
@@ -66,15 +66,6 @@ class Projects::VariablesController < Projects::ApplicationController
params.permit(variables: [*variable_params_attributes])
end
- def variables_from_params(params)
- params[:variables].map do |variable_hash|
- variable = project.variables.where(key: variable_hash[:key])
- .first_or_initialize(variable_hash)
- variable.assign_attributes(variable_hash) unless variable.new_record?
- variable
- end
- end
-
def variable_params_attributes
%i[id key value protected _destroy]
end
@@ -82,4 +73,13 @@ class Projects::VariablesController < Projects::ApplicationController
def variable
@variable ||= project.variables.find(params[:id]).present(current_user: current_user)
end
+
+ def variables
+ @variables = variables_params[:variables].map do |variable_hash|
+ variable = project.variables.where(key: variable_hash[:key])
+ .first_or_initialize(variable_hash).present(current_user: current_user)
+ variable.assign_attributes(variable_hash) unless variable.new_record?
+ variable
+ end
+ end
end