Commit 0611c5c6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix deploy key api 500 if key is empty

parent 50e8d6c0
...@@ -428,21 +428,23 @@ module API ...@@ -428,21 +428,23 @@ module API
post ":id/keys" do post ":id/keys" do
attrs = attributes_for_keys [:title, :key] attrs = attributes_for_keys [:title, :key]
attrs[:key].strip! if attrs[:key].present?
attrs[:key].strip!
# check if key already exist in project
key = user_project.deploy_keys.find_by_key(attrs[:key]) # check if key already exist in project
if key key = user_project.deploy_keys.find_by_key(attrs[:key])
present key, with: Entities::SSHKey if key
return present key, with: Entities::SSHKey
end return
end
# Check for available deploy keys in other projects # Check for available deploy keys in other projects
key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) key = current_user.owned_deploy_keys.find_by_key(attrs[:key])
if key if key
user_project.deploy_keys << key user_project.deploy_keys << key
present key, with: Entities::SSHKey present key, with: Entities::SSHKey
return return
end
end end
key = DeployKey.new attrs key = DeployKey.new attrs
......
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