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
Boxiang Sun
gitlab-ce
Commits
59d910f2
Commit
59d910f2
authored
Mar 28, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set user when adding deploy key to project using API
parent
f56ef206
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+11
-12
spec/requests/api/deploy_keys_spec.rb
spec/requests/api/deploy_keys_spec.rb
+4
-0
No files found.
lib/api/deploy_keys.rb
View file @
59d910f2
...
@@ -54,7 +54,7 @@ module API
...
@@ -54,7 +54,7 @@ module API
present
key
,
with:
Entities
::
DeployKeysProject
present
key
,
with:
Entities
::
DeployKeysProject
end
end
desc
'Add new deploy key to
currently authenticated user
'
do
desc
'Add new deploy key to
a project
'
do
success
Entities
::
DeployKeysProject
success
Entities
::
DeployKeysProject
end
end
params
do
params
do
...
@@ -66,33 +66,32 @@ module API
...
@@ -66,33 +66,32 @@ module API
params
[
:key
].
strip!
params
[
:key
].
strip!
# Check for an existing key joined to this project
# Check for an existing key joined to this project
key
=
user_project
.
deploy_keys_projects
deploy_key_project
=
user_project
.
deploy_keys_projects
.
joins
(
:deploy_key
)
.
joins
(
:deploy_key
)
.
find_by
(
keys:
{
key:
params
[
:key
]
})
.
find_by
(
keys:
{
key:
params
[
:key
]
})
if
key
if
deploy_key_project
present
key
,
with:
Entities
::
DeployKeysProject
present
deploy_key_project
,
with:
Entities
::
DeployKeysProject
break
break
end
end
# Check for available deploy keys in other projects
# Check for available deploy keys in other projects
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
params
[
:key
])
key
=
current_user
.
accessible_deploy_keys
.
find_by
(
key:
params
[
:key
])
if
key
if
key
added_key
=
add_deploy_keys_project
(
user_project
,
deploy_key:
key
,
can_push:
!!
params
[
:can_push
])
deploy_key_project
=
add_deploy_keys_project
(
user_project
,
deploy_key:
key
,
can_push:
!!
params
[
:can_push
])
present
added_key
,
with:
Entities
::
DeployKeysProject
present
deploy_key_project
,
with:
Entities
::
DeployKeysProject
break
break
end
end
# Create a new deploy key
# Create a new deploy key
key_attributes
=
{
can_push:
!!
params
[
:can_push
],
deploy_key_attributes
=
declared_params
.
except
(
:can_push
).
merge
(
user:
current_user
)
deploy_key_attributes:
declared_params
.
except
(
:can_push
)
}
deploy_key_project
=
add_deploy_keys_project
(
user_project
,
deploy_key_attributes:
deploy_key_attributes
,
can_push:
!!
params
[
:can_push
])
key
=
add_deploy_keys_project
(
user_project
,
key_attributes
)
if
key
.
valid?
if
deploy_key_project
.
valid?
present
key
,
with:
Entities
::
DeployKeysProject
present
deploy_key_project
,
with:
Entities
::
DeployKeysProject
else
else
render_validation_error!
(
key
)
render_validation_error!
(
deploy_key_project
)
end
end
end
end
...
...
spec/requests/api/deploy_keys_spec.rb
View file @
59d910f2
...
@@ -91,6 +91,10 @@ describe API::DeployKeys do
...
@@ -91,6 +91,10 @@ describe API::DeployKeys do
expect
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
key_attrs
post
api
(
"/projects/
#{
project
.
id
}
/deploy_keys"
,
admin
),
key_attrs
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
new_key
=
project
.
deploy_keys
.
last
expect
(
new_key
.
key
).
to
eq
(
key_attrs
[
:key
])
expect
(
new_key
.
user
).
to
eq
(
admin
)
end
end
it
'returns an existing ssh key when attempting to add a duplicate'
do
it
'returns an existing ssh key when attempting to add a duplicate'
do
...
...
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