From cfd475a45ee2655fa0148b0b561f95b44fe8641b Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Tue, 15 Aug 2017 11:27:37 +0100 Subject: Removes default scope from sortable --- app/models/user.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/models/user.rb') diff --git a/app/models/user.rb b/app/models/user.rb index c5b5f09722f..1ac5b029c81 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,7 @@ class User < ActiveRecord::Base # # Namespace for personal projects - has_one :namespace, -> { where type: nil }, dependent: :destroy, foreign_key: :owner_id, autosave: true # rubocop:disable Cop/ActiveRecordDependent + has_one :namespace, -> { where(type: nil) }, dependent: :destroy, foreign_key: :owner_id, autosave: true # rubocop:disable Cop/ActiveRecordDependent # Profile has_many :keys, -> do @@ -255,11 +255,13 @@ class User < ActiveRecord::Base end def sort(method) - case method.to_s + order_method = method || 'id_desc' + + case order_method.to_s when 'recent_sign_in' then order_recent_sign_in when 'oldest_sign_in' then order_oldest_sign_in else - order_by(method) + order_by(order_method) end end @@ -367,7 +369,7 @@ class User < ActiveRecord::Base # Returns a user for the given SSH key. def find_by_ssh_key_id(key_id) - find_by(id: Key.unscoped.select(:user_id).where(id: key_id)) + Key.find_by(id: key_id)&.user end def find_by_full_path(path, follow_redirects: false) -- cgit v1.2.1