Commit dad831662ad6521dfaf404621b72e551d456ca5c

Authored by Dmitriy Zaporozhets
2 parents 9afc930b 12420a22

Merge pull request #5350 from NARKOZ/patch-0

fix variable name
Showing 2 changed files with 3 additions and 11 deletions   Show diff stats
app/models/user.rb
@@ -199,11 +199,7 @@ class User < ActiveRecord::Base @@ -199,11 +199,7 @@ class User < ActiveRecord::Base
199 end 199 end
200 200
201 def by_username_or_id(name_or_id) 201 def by_username_or_id(name_or_id)
202 - if (name_or_id.is_a?(Integer))  
203 - User.find_by_id(name_or_id)  
204 - else  
205 - User.find_by_username(name_or_id)  
206 - end 202 + where('username = ? OR id = ?', name_or_id, name_or_id).first
207 end 203 end
208 204
209 def build_user(attrs = {}, options= {}) 205 def build_user(attrs = {}, options= {})
lib/api/helpers.rb
@@ -11,12 +11,8 @@ module API @@ -11,12 +11,8 @@ module API
11 # If the sudo is the current user do nothing 11 # If the sudo is the current user do nothing
12 if (identifier && !(@current_user.id == identifier || @current_user.username == identifier)) 12 if (identifier && !(@current_user.id == identifier || @current_user.username == identifier))
13 render_api_error!('403 Forbidden: Must be admin to use sudo', 403) unless @current_user.is_admin? 13 render_api_error!('403 Forbidden: Must be admin to use sudo', 403) unless @current_user.is_admin?
14 - begin  
15 - @current_user = User.by_username_or_id(identifier)  
16 - rescue => ex  
17 - not_found!("No user id or username for: #{identifier}")  
18 - end  
19 - not_found!("No user id or username for: #{identifier}") if current_user.nil? 14 + @current_user = User.by_username_or_id(identifier)
  15 + not_found!("No user id or username for: #{identifier}") if @current_user.nil?
20 end 16 end
21 @current_user 17 @current_user
22 end 18 end