diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-06-17 12:38:49 -0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-06-17 14:29:11 -0300 |
commit | e5aa902860fcc2380fd25a6a4f0736dae159eba3 (patch) | |
tree | ba3c678a476bc7153490da412ebd64223c155c1c /lib/api/helpers.rb | |
parent | ab236c76247d83c190b148acbffa48f244414553 (diff) | |
parent | ae4491b42181f7195199fd6ac9273891d6e48263 (diff) | |
download | gitlab-ce-issue_12758.tar.gz |
Merge master into issue_12758issue_12758
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index de5959e3aae..77e407b54c5 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -9,9 +9,13 @@ module API [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value) 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) + end + def current_user - private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s - @current_user ||= (User.find_by(authentication_token: private_token) || doorkeeper_guard) + @current_user ||= (find_user_by_private_token || doorkeeper_guard) unless @current_user && Gitlab::UserAccess.allowed?(@current_user) return nil @@ -33,7 +37,7 @@ module API identifier ||= params[SUDO_PARAM] || env[SUDO_HEADER] # Regex for integers - if !!(identifier =~ /^[0-9]+$/) + if !!(identifier =~ /\A[0-9]+\z/) identifier.to_i else identifier |