From ee7e4fd34196003d8f3899704e5c537d965b7a9a Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 21 Aug 2015 12:19:05 +0100 Subject: Fix problem with variables saving --- CHANGELOG | 1 + app/models/variable.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f2c33fa..3d3b2ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ v7.14.0 (unreleased) - Rename type(s) to stage(s) - Add missing stage when doing retry - Require variable keys to be not-empty and unique + - Fix variable saving issue v7.13.1 - Fix: user could steal specific runner diff --git a/app/models/variable.rb b/app/models/variable.rb index 559b9f2..c084b89 100644 --- a/app/models/variable.rb +++ b/app/models/variable.rb @@ -15,7 +15,7 @@ class Variable < ActiveRecord::Base belongs_to :project validates_presence_of :key - validates_uniqueness_of :key + validates_uniqueness_of :key, scope: :project_id attr_encrypted :value, mode: :per_attribute_iv_and_salt, key: GitlabCi::Application.secrets.db_key_base end -- cgit v1.2.1 From fe9a1e31f5255b34b43974c303410063c07cc292 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 21 Aug 2015 12:20:25 +0100 Subject: Update variables from within it's own controller not the project's --- CHANGELOG | 1 + app/controllers/variables_controller.rb | 16 +++++++++++++- app/views/variables/index.html.haml | 37 --------------------------------- app/views/variables/show.html.haml | 37 +++++++++++++++++++++++++++++++++ config/routes.rb | 2 +- 5 files changed, 54 insertions(+), 39 deletions(-) delete mode 100644 app/views/variables/index.html.haml create mode 100644 app/views/variables/show.html.haml diff --git a/CHANGELOG b/CHANGELOG index 3d3b2ef..eddfded 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ v7.14.0 (unreleased) - Add missing stage when doing retry - Require variable keys to be not-empty and unique - Fix variable saving issue + - Display variable saving errors in variables page not the project's v7.13.1 - Fix: user could steal specific runner diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index 6eb908e..754ebf3 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -6,7 +6,17 @@ class VariablesController < ApplicationController layout 'project' - def index + def show + end + + def update + if project.update_attributes(project_params) + EventService.new.change_project_settings(current_user, project) + + redirect_to :back, notice: 'Variables was successfully updated.' + else + render action: 'show' + end end private @@ -14,4 +24,8 @@ class VariablesController < ApplicationController def project @project ||= Project.find(params[:project_id]) end + + def project_params + params.require(:project).permit({ variables_attributes: [:id, :key, :value, :_destroy] }) + end end diff --git a/app/views/variables/index.html.haml b/app/views/variables/index.html.haml deleted file mode 100644 index 64a4451..0000000 --- a/app/views/variables/index.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -%h3 Secret Variables -%p.light - These variables will be set to environment by the runner and will be hidden in the build log. - %br - So you can use them for passwords, secret keys or whatever you want. - -%hr - - -= nested_form_for @project, html: { class: 'form-horizontal' } do |f| - - if @project.errors.any? - #error_explanation - %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" - .alert.alert-error - %ul - - @project.errors.full_messages.each do |msg| - %li= msg - - = f.fields_for :variables do |variable_form| - .form-group - = variable_form.label :key, 'Key', class: 'control-label' - .col-sm-10 - = variable_form.text_field :key, class: 'form-control', placeholder: "PROJECT_VARIABLE" - - .form-group - = variable_form.label :value, 'Value', class: 'control-label' - .col-sm-10 - = variable_form.text_area :value, class: 'form-control', rows: 2, placeholder: "" - - = variable_form.link_to_remove "Remove this variable", class: 'btn btn-danger pull-right prepend-top-10' - %hr - %p - .clearfix - = f.link_to_add "Add a variable", :variables, class: 'btn btn-success pull-right' - - .form-actions - = f.submit 'Save changes', class: 'btn btn-save', return_to: request.original_url diff --git a/app/views/variables/show.html.haml b/app/views/variables/show.html.haml new file mode 100644 index 0000000..e296e17 --- /dev/null +++ b/app/views/variables/show.html.haml @@ -0,0 +1,37 @@ +%h3 Secret Variables +%p.light + These variables will be set to environment by the runner and will be hidden in the build log. + %br + So you can use them for passwords, secret keys or whatever you want. + +%hr + + += nested_form_for @project, url: url_for(controller: 'variables', action: 'update'), html: { class: 'form-horizontal' } do |f| + - if @project.errors.any? + #error_explanation + %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" + .alert.alert-error + %ul + - @project.errors.full_messages.each do |msg| + %li= msg + + = f.fields_for :variables do |variable_form| + .form-group + = variable_form.label :key, 'Key', class: 'control-label' + .col-sm-10 + = variable_form.text_field :key, class: 'form-control', placeholder: "PROJECT_VARIABLE" + + .form-group + = variable_form.label :value, 'Value', class: 'control-label' + .col-sm-10 + = variable_form.text_area :value, class: 'form-control', rows: 2, placeholder: "" + + = variable_form.link_to_remove "Remove this variable", class: 'btn btn-danger pull-right prepend-top-10' + %hr + %p + .clearfix + = f.link_to_add "Add a variable", :variables, class: 'btn btn-success pull-right' + + .form-actions + = f.submit 'Save changes', class: 'btn btn-save', return_to: request.original_url diff --git a/config/routes.rb b/config/routes.rb index e92e726..cd0054f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,7 @@ Rails.application.routes.draw do resources :runner_projects, only: [:create, :destroy] resources :events, only: [:index] - resources :variables, only: [:index] + resource :variables, only: [:show, :update] end resource :user_sessions do -- cgit v1.2.1 From 0a1390641ef9c5599d7c9ddc54be47e0a6cb9810 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 21 Aug 2015 12:27:25 +0100 Subject: Fix spelling --- app/controllers/variables_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index 754ebf3..afc33c7 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -13,7 +13,7 @@ class VariablesController < ApplicationController if project.update_attributes(project_params) EventService.new.change_project_settings(current_user, project) - redirect_to :back, notice: 'Variables was successfully updated.' + redirect_to :back, notice: 'Variables were successfully updated.' else render action: 'show' end -- cgit v1.2.1 From 5b9bb9aeef59d9eb1214da6a731653fdf96162c0 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 21 Aug 2015 12:30:51 +0100 Subject: Redirect to known route instead of :back --- app/controllers/variables_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/variables_controller.rb b/app/controllers/variables_controller.rb index afc33c7..00f60f3 100644 --- a/app/controllers/variables_controller.rb +++ b/app/controllers/variables_controller.rb @@ -13,7 +13,7 @@ class VariablesController < ApplicationController if project.update_attributes(project_params) EventService.new.change_project_settings(current_user, project) - redirect_to :back, notice: 'Variables were successfully updated.' + redirect_to project_variables_path(project), notice: 'Variables were successfully updated.' else render action: 'show' end -- cgit v1.2.1 From fefa3ce9fa2725d8d0541b9a7455d516f7d61559 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 21 Aug 2015 14:11:31 +0100 Subject: Fix specs --- spec/features/variables_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/variables_spec.rb b/spec/features/variables_spec.rb index 21a7a11..2bb0d9d 100644 --- a/spec/features/variables_spec.rb +++ b/spec/features/variables_spec.rb @@ -18,7 +18,7 @@ describe "Variables" do fill_in "Value", with: "SECRET_VALUE" click_on "Save changes" - page.should have_content("Project was successfully updated.") + page.should have_content("Variables were successfully updated.") @project.variables.count.should == 1 end -- cgit v1.2.1