diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-03 21:01:07 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-06-03 21:01:07 +0300 |
commit | 0611c5c6120503b57237c2580fddf318cd6a552a (patch) | |
tree | 00b8a976294e07f86bf973ec091fdc9036af60e9 /lib/api | |
parent | 50e8d6c0c03b11cc539cca37aea782538ee77262 (diff) | |
download | gitlab-ce-0611c5c6120503b57237c2580fddf318cd6a552a.tar.gz |
Fix deploy key api 500 if key is empty
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/projects.rb | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 13aa42b755d..3711057ecaa 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -428,21 +428,23 @@ module API post ":id/keys" do attrs = attributes_for_keys [:title, :key] - attrs[:key].strip! - - # check if key already exist in project - key = user_project.deploy_keys.find_by_key(attrs[:key]) - if key - present key, with: Entities::SSHKey - return - end + if attrs[:key].present? + attrs[:key].strip! + + # check if key already exist in project + key = user_project.deploy_keys.find_by_key(attrs[:key]) + if key + present key, with: Entities::SSHKey + return + end - # Check for available deploy keys in other projects - key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) - if key - user_project.deploy_keys << key - present key, with: Entities::SSHKey - return + # Check for available deploy keys in other projects + key = current_user.owned_deploy_keys.find_by_key(attrs[:key]) + if key + user_project.deploy_keys << key + present key, with: Entities::SSHKey + return + end end key = DeployKey.new attrs |