diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-07 12:23:36 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-02-07 12:23:36 +0000 |
commit | a55cfc1e6316232e25a46416b0a60be7c1282da7 (patch) | |
tree | 26ea2ed9e04c2110e718441577aec2489ea76642 /app/controllers | |
parent | 024c8a427eaf3267daf92359dcb9668f28fa8384 (diff) | |
parent | efcdc269e03836e78dcc8d460621c948ac02bc24 (diff) | |
download | gitlab-ce-a55cfc1e6316232e25a46416b0a60be7c1282da7.tar.gz |
Merge branch 'ce-39118-dynamic-pipeline-variables-fe' into 'master'
Dynamic CI secret variables -- CE backport
See merge request gitlab-org/gitlab-ce!16842
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/groups/variables_controller.rb | 57 | ||||
-rw-r--r-- | app/controllers/projects/variables_controller.rb | 57 |
2 files changed, 39 insertions, 75 deletions
diff --git a/app/controllers/groups/variables_controller.rb b/app/controllers/groups/variables_controller.rb index 10038ff3ad9..913e13bf734 100644 --- a/app/controllers/groups/variables_controller.rb +++ b/app/controllers/groups/variables_controller.rb @@ -1,60 +1,43 @@ module Groups class VariablesController < Groups::ApplicationController - before_action :variable, only: [:show, :update, :destroy] before_action :authorize_admin_build! - def index - redirect_to group_settings_ci_cd_path(group) - end - def show + respond_to do |format| + format.json do + render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) } + end + end end def update - if variable.update(variable_params) - redirect_to group_variables_path(group), - notice: 'Variable was successfully updated.' + if @group.update(group_variables_params) + respond_to do |format| + format.json { return render_group_variables } + end else - render "show" + respond_to do |format| + format.json { render_error } + end end end - def create - @variable = group.variables.create(variable_params) - .present(current_user: current_user) + private - if @variable.persisted? - redirect_to group_settings_ci_cd_path(group), - notice: 'Variable was successfully created.' - else - render "show" - end + def render_group_variables + render status: :ok, json: { variables: GroupVariableSerializer.new.represent(@group.variables) } end - def destroy - if variable.destroy - redirect_to group_settings_ci_cd_path(group), - status: 302, - notice: 'Variable was successfully removed.' - else - redirect_to group_settings_ci_cd_path(group), - status: 302, - notice: 'Failed to remove the variable.' - end + def render_error + render status: :bad_request, json: @group.errors.full_messages end - private - - def variable_params - params.require(:variable).permit(*variable_params_attributes) + def group_variables_params + params.permit(variables_attributes: [*variable_params_attributes]) end def variable_params_attributes - %i[key value protected] - end - - def variable - @variable ||= group.variables.find(params[:id]).present(current_user: current_user) + %i[id key value protected _destroy] end def authorize_admin_build! diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb index 6a825137564..7eb509e2e64 100644 --- a/app/controllers/projects/variables_controller.rb +++ b/app/controllers/projects/variables_controller.rb @@ -1,60 +1,41 @@ class Projects::VariablesController < Projects::ApplicationController - before_action :variable, only: [:show, :update, :destroy] before_action :authorize_admin_build! - layout 'project_settings' - - def index - redirect_to project_settings_ci_cd_path(@project) - end - def show + respond_to do |format| + format.json do + render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) } + end + end end def update - if variable.update(variable_params) - redirect_to project_variables_path(project), - notice: 'Variable was successfully updated.' + if @project.update(variables_params) + respond_to do |format| + format.json { return render_variables } + end else - render "show" + respond_to do |format| + format.json { render_error } + end end end - def create - @variable = project.variables.create(variable_params) - .present(current_user: current_user) + private - if @variable.persisted? - redirect_to project_settings_ci_cd_path(project), - notice: 'Variable was successfully created.' - else - render "show" - end + def render_variables + render status: :ok, json: { variables: VariableSerializer.new.represent(@project.variables) } end - def destroy - if variable.destroy - redirect_to project_settings_ci_cd_path(project), - status: 302, - notice: 'Variable was successfully removed.' - else - redirect_to project_settings_ci_cd_path(project), - status: 302, - notice: 'Failed to remove the variable.' - end + def render_error + render status: :bad_request, json: @project.errors.full_messages end - private - - def variable_params - params.require(:variable).permit(*variable_params_attributes) + def variables_params + params.permit(variables_attributes: [*variable_params_attributes]) end def variable_params_attributes %i[id key value protected _destroy] end - - def variable - @variable ||= project.variables.find(params[:id]).present(current_user: current_user) - end end |