diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-09-02 14:20:07 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-09-02 14:20:07 +0000 |
commit | 0a41b340b4c575712bb3032f3e7636f3d00a8c92 (patch) | |
tree | 09c27d8dd57bddd0ed28373246fbe227b0b0f7af /lib | |
parent | 5a7e027859a85e9ad0aba82fff52703b15140f38 (diff) | |
parent | 8b6154c145b22d34146fc08c49d2e2d1569d44a0 (diff) | |
download | gitlab-ce-0a41b340b4c575712bb3032f3e7636f3d00a8c92.tar.gz |
Merge branch 'internal_recovery_api' into 'master'
Minor edits to two_factor_recovery_codes API error catching
Minor fixes to the `two_factor_recovery_codes` internal API making the conditionals more sane. Thanks @DouweM for pointing it out.
See merge request !6000
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/internal.rb | 14 |
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 |