diff options
| author | Lin Jen-Shin <godfat@godfat.org> | 2016-10-04 02:38:25 +0800 |
|---|---|---|
| committer | Lin Jen-Shin <godfat@godfat.org> | 2016-10-04 02:38:25 +0800 |
| commit | f39ba1bb5ed9c2421e60a618f71373c5d8dc94e9 (patch) | |
| tree | e5ad67c48bdc2d520b84d735225ff7eac4c7da84 /lib/api/helpers.rb | |
| parent | db6b2b18990297d98bd74af1d2f475d0d42ec443 (diff) | |
| parent | a1aea3266e4b90869d5a9bcc334272996ab80fda (diff) | |
| download | gitlab-ce-f39ba1bb5ed9c2421e60a618f71373c5d8dc94e9.tar.gz | |
Merge remote-tracking branch 'upstream/master' into pipeline-emails
* upstream/master: (372 commits)
Enable Lint/StringConversionInInterpolation cop and autocorrect offenses
resolve duplicated changelog entry
credit myself :smile:
change determine conditions
override subject method in devise mailer
follow the styleguide: Don't use parentheses around a literal
wrap subject with method subject
move spec back into shared example `an email sent from GitLab`
stub config settings in spec
remove empty line at block body end
remove extra entry
create new test in `spec/mailers/notify_spec.rb`
move changelog to 8.13
add configurable email subject suffix
Fixes sidebar navigation.
Convert "SSH Keys" Spinach features to RSpec
Enable import/export back for non-admins
Update gitlab-shell to 3.6.3
Updated artwork of empty group state.
Better empty state for Groups view.
...
Diffstat (limited to 'lib/api/helpers.rb')
| -rw-r--r-- | lib/api/helpers.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 150875ed4f0..714d4ea3dc6 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -12,13 +12,30 @@ module API nil end + def private_token + params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER] + end + + def warden + env['warden'] + end + + # Check the Rails session for valid authentication details + def find_user_from_warden + warden ? warden.authenticate : nil + end + def find_user_by_private_token - token_string = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s - User.find_by_authentication_token(token_string) || User.find_by_personal_access_token(token_string) + token = private_token + return nil unless token.present? + + User.find_by_authentication_token(token) || User.find_by_personal_access_token(token) end def current_user - @current_user ||= (find_user_by_private_token || doorkeeper_guard) + @current_user ||= find_user_by_private_token + @current_user ||= doorkeeper_guard + @current_user ||= find_user_from_warden unless @current_user && Gitlab::UserAccess.new(@current_user).allowed? return nil |
