diff options
author | Joshua Welsh <joshua.welsh@performancehorizon.com> | 2016-10-11 10:02:51 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-10-26 12:54:47 +0200 |
commit | ce4760bbd57f3b30b0e3845493ed4e39cc463359 (patch) | |
tree | 81508538e7d045f898a1e45904e9a2fe5d5205bb /lib | |
parent | 70074733bb5f8dd09d3389b8873da22c39d52b50 (diff) | |
download | gitlab-ce-ce4760bbd57f3b30b0e3845493ed4e39cc463359.tar.gz |
Fixes various errors when adding deploy keys caused by not exiting the control flow.
When adding a deploy key that already exists in the project the existing key would not be returned, resulting in an attempt to create a new one, which in turn caused a 500 error due to an ActiveRecord exception.
When adding a deploy key that exists within another project the key would be joined to the project, but would also attempt to create a new one, which resulted in a 400 error due to the key already existing.
Fixes #22741
Fixes #21754
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/deploy_keys.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/api/deploy_keys.rb b/lib/api/deploy_keys.rb index 825e05fbae3..425df2c176a 100644 --- a/lib/api/deploy_keys.rb +++ b/lib/api/deploy_keys.rb @@ -49,18 +49,23 @@ module API attrs = attributes_for_keys [:title, :key] attrs[:key].strip! if attrs[:key] + # Check for an existing key joined to this project key = user_project.deploy_keys.find_by(key: attrs[:key]) - present key, with: Entities::SSHKey if key + if key + present key, with: Entities::SSHKey + break + end # Check for available deploy keys in other projects key = current_user.accessible_deploy_keys.find_by(key: attrs[:key]) if key user_project.deploy_keys << key present key, with: Entities::SSHKey + break end + # Create a new deploy key key = DeployKey.new attrs - if key.valid? && user_project.deploy_keys << key present key, with: Entities::SSHKey else |