diff options
author | Izaak Alpert <ialpert@blackberry.com> | 2013-06-28 08:59:05 -0400 |
---|---|---|
committer | Izaak Alpert <ialpert@blackberry.com> | 2013-09-09 12:04:38 -0400 |
commit | 7a56075efac308a3bd08e022e56e96d41c4c05b5 (patch) | |
tree | 52d3857509ea673952f39bad2085632637e1d8e6 /lib/api | |
parent | e86e8818327059279247db3a451994c6a62ab161 (diff) | |
download | gitlab-ce-7a56075efac308a3bd08e022e56e96d41c4c05b5.tar.gz |
Some of the requested updates, rebase on master
Change-Id: I305266fe9acbbb5136adeeb52e7e4e1d6629a30a
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/helpers.rb | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 996d3adb174..4f189f35196 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -12,25 +12,18 @@ module API if (identifier && !(@current_user.id == identifier || @current_user.username == identifier)) render_api_error!('403 Forbidden: Must be admin to use sudo', 403) unless @current_user.is_admin? begin - - if (identifier.is_a?(Integer)) - user = User.find_by_id(identifier) - else - user = User.find_by_username(identifier) - end - if user.nil? - not_found!("No user id or username for: #{identifier}") - end - @current_user = user + @current_user = User.by_username_or_id(identifier) rescue => ex not_found!("No user id or username for: #{identifier}") end + not_found!("No user id or username for: #{identifier}") if current_user.nil? end @current_user end def sudo_identifier() - identifier = params[SUDO_PARAM] == nil ? env[SUDO_HEADER] : params[SUDO_PARAM] + identifier ||= params[SUDO_PARAM] ||= env[SUDO_HEADER] + # Regex for integers if (!!(identifier =~ /^[0-9]+$/)) identifier.to_i else @@ -129,10 +122,10 @@ module API def abilities @abilities ||= begin - abilities = Six.new - abilities << Ability - abilities - end + abilities = Six.new + abilities << Ability + abilities + end end end end |