Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
c64181ce
Commit
c64181ce
authored
Jan 13, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move variable loading into before_action
parent
b91539d6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
app/controllers/projects/variables_controller.rb
app/controllers/projects/variables_controller.rb
+12
-12
No files found.
app/controllers/projects/variables_controller.rb
View file @
c64181ce
class
Projects::VariablesController
<
Projects
::
ApplicationController
class
Projects::VariablesController
<
Projects
::
ApplicationController
before_action
:variable
,
only:
[
:show
,
:update
,
:destroy
]
before_action
:variable
,
only:
[
:show
,
:update
,
:destroy
]
before_action
:variables
,
only:
[
:save_multiple
]
before_action
:authorize_admin_build!
before_action
:authorize_admin_build!
layout
'project_settings'
layout
'project_settings'
...
@@ -35,10 +36,9 @@ class Projects::VariablesController < Projects::ApplicationController
...
@@ -35,10 +36,9 @@ class Projects::VariablesController < Projects::ApplicationController
def
save_multiple
def
save_multiple
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
do
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
head
:ok
end
end
end
end
...
@@ -66,15 +66,6 @@ class Projects::VariablesController < Projects::ApplicationController
...
@@ -66,15 +66,6 @@ class Projects::VariablesController < Projects::ApplicationController
params
.
permit
(
variables:
[
*
variable_params_attributes
])
params
.
permit
(
variables:
[
*
variable_params_attributes
])
end
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
def
variable_params_attributes
%i[id key value protected _destroy]
%i[id key value protected _destroy]
end
end
...
@@ -82,4 +73,13 @@ class Projects::VariablesController < Projects::ApplicationController
...
@@ -82,4 +73,13 @@ class Projects::VariablesController < Projects::ApplicationController
def
variable
def
variable
@variable
||=
project
.
variables
.
find
(
params
[
:id
]).
present
(
current_user:
current_user
)
@variable
||=
project
.
variables
.
find
(
params
[
:id
]).
present
(
current_user:
current_user
)
end
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
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment