summaryrefslogtreecommitdiff
path: root/lib/api/internal.rb
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2016-08-24 19:58:05 -0500
committerDrew Blessing <drew@gitlab.com>2016-08-31 19:41:55 -0500
commit8b6154c145b22d34146fc08c49d2e2d1569d44a0 (patch)
tree97ec9ae77feb579e1d44f08b47846828f60b381e /lib/api/internal.rb
parent0e3c7b2f2a5742216eda2d2cf6df9a5ea5f866ff (diff)
downloadgitlab-ce-8b6154c145b22d34146fc08c49d2e2d1569d44a0.tar.gz
Minor edits to two_factor_recovery_codes API error catching
Diffstat (limited to 'lib/api/internal.rb')
-rw-r--r--lib/api/internal.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index 5b54c11ef62..6e6efece7c4 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -105,15 +105,19 @@ module API
post '/two_factor_recovery_codes' do
status 200
- key = Key.find(params[:key_id])
- user = key.user
+ key = Key.find_by(id: params[:key_id])
+
+ unless key
+ return { 'success' => false, 'message' => 'Could not find the given key' }
+ end
- # Make sure this isn't a deploy key
- unless key.type.nil?
+ if key.is_a?(DeployKey)
return { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' }
end
- unless user.present?
+ user = key.user
+
+ unless user
return { success: false, message: 'Could not find a user for the given key' }
end