Commit 28a5f8c6 authored by Matija Čupić's avatar Matija Čupić

Use secret_key and secret_value in Variables controller

parent 79aa0032
......@@ -35,11 +35,16 @@ module Groups
end
def group_variables_params
params.permit(variables_attributes: [*variable_params_attributes])
filtered_params = params.permit(variables_attributes: [*variable_params_attributes])
filtered_params["variables_attributes"].each do |variable|
variable["key"] = variable.delete("secret_key")
variable["value"] = variable.delete("secret_value")
end
filtered_params
end
def variable_params_attributes
%i[id key value protected _destroy]
%i[id secret_key secret_value protected _destroy]
end
def authorize_admin_build!
......
......@@ -32,10 +32,15 @@ class Projects::VariablesController < Projects::ApplicationController
end
def variables_params
params.permit(variables_attributes: [*variable_params_attributes])
filtered_params = params.permit(variables_attributes: [*variable_params_attributes])
filtered_params["variables_attributes"].each do |variable|
variable["key"] = variable.delete("secret_key")
variable["value"] = variable.delete("secret_value")
end
filtered_params
end
def variable_params_attributes
%i[id key value protected _destroy]
%i[id secret_key secret_value protected _destroy]
end
end
......@@ -15,21 +15,21 @@ end
shared_examples 'PATCH #update updates variables' do
let(:variable_attributes) do
{ id: variable.id,
key: variable.key,
value: variable.value,
secret_key: variable.key,
secret_value: variable.value,
protected: variable.protected?.to_s }
end
let(:new_variable_attributes) do
{ key: 'new_key',
value: 'dummy_value',
{ secret_key: 'new_key',
secret_value: 'dummy_value',
protected: 'false' }
end
context 'with invalid new variable parameters' do
let(:variables_attributes) do
[
variable_attributes.merge(value: 'other_value'),
new_variable_attributes.merge(key: '...?')
variable_attributes.merge(secret_value: 'other_value'),
new_variable_attributes.merge(secret_key: '...?')
]
end
......@@ -52,7 +52,7 @@ shared_examples 'PATCH #update updates variables' do
let(:variables_attributes) do
[
new_variable_attributes,
new_variable_attributes.merge(value: 'other_value')
new_variable_attributes.merge(secret_value: 'other_value')
]
end
......@@ -74,7 +74,7 @@ shared_examples 'PATCH #update updates variables' do
context 'with valid new variable parameters' do
let(:variables_attributes) do
[
variable_attributes.merge(value: 'other_value'),
variable_attributes.merge(secret_value: 'other_value'),
new_variable_attributes
]
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment