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 ...@@ -35,11 +35,16 @@ module Groups
end end
def group_variables_params 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 end
def variable_params_attributes def variable_params_attributes
%i[id key value protected _destroy] %i[id secret_key secret_value protected _destroy]
end end
def authorize_admin_build! def authorize_admin_build!
......
...@@ -32,10 +32,15 @@ class Projects::VariablesController < Projects::ApplicationController ...@@ -32,10 +32,15 @@ class Projects::VariablesController < Projects::ApplicationController
end end
def variables_params 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 end
def variable_params_attributes def variable_params_attributes
%i[id key value protected _destroy] %i[id secret_key secret_value protected _destroy]
end end
end end
...@@ -15,21 +15,21 @@ end ...@@ -15,21 +15,21 @@ end
shared_examples 'PATCH #update updates variables' do shared_examples 'PATCH #update updates variables' do
let(:variable_attributes) do let(:variable_attributes) do
{ id: variable.id, { id: variable.id,
key: variable.key, secret_key: variable.key,
value: variable.value, secret_value: variable.value,
protected: variable.protected?.to_s } protected: variable.protected?.to_s }
end end
let(:new_variable_attributes) do let(:new_variable_attributes) do
{ key: 'new_key', { secret_key: 'new_key',
value: 'dummy_value', secret_value: 'dummy_value',
protected: 'false' } protected: 'false' }
end end
context 'with invalid new variable parameters' do context 'with invalid new variable parameters' do
let(:variables_attributes) do let(:variables_attributes) do
[ [
variable_attributes.merge(value: 'other_value'), variable_attributes.merge(secret_value: 'other_value'),
new_variable_attributes.merge(key: '...?') new_variable_attributes.merge(secret_key: '...?')
] ]
end end
...@@ -52,7 +52,7 @@ shared_examples 'PATCH #update updates variables' do ...@@ -52,7 +52,7 @@ shared_examples 'PATCH #update updates variables' do
let(:variables_attributes) do let(:variables_attributes) do
[ [
new_variable_attributes, new_variable_attributes,
new_variable_attributes.merge(value: 'other_value') new_variable_attributes.merge(secret_value: 'other_value')
] ]
end end
...@@ -74,7 +74,7 @@ shared_examples 'PATCH #update updates variables' do ...@@ -74,7 +74,7 @@ shared_examples 'PATCH #update updates variables' do
context 'with valid new variable parameters' do context 'with valid new variable parameters' do
let(:variables_attributes) do let(:variables_attributes) do
[ [
variable_attributes.merge(value: 'other_value'), variable_attributes.merge(secret_value: 'other_value'),
new_variable_attributes new_variable_attributes
] ]
end 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