Method: LesliSecurity::UserService#index
- Defined in:
- app/services/lesli_security/user_service.rb
#index(params) ⇒ Array
TODO: Implement pg_search
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/services/lesli_security/user_service.rb', line 44 def index params # sql string to join to user_roles and get all the roles assigned to a user sql_string_for_user_roles = "left join ( select ur.user_id, string_agg(r.\"name\", ', ') rolenames from lesli_user_powers ur join lesli_roles r on r.id = ur.role_id where ur.deleted_at is null group by ur.user_id ) roles on roles.user_id = lesli_users.id" # sql string to joing to user_sessions and get all the active sessions of a user sql_string_for_user_sessions = "left join ( select max(last_used_at) as last_action_performed_at, user_id from lesli_user_sessions us where us.deleted_at is null group by(us.user_id) ) sessions on sessions.user_id = lesli_users.id" users = current_user.account.users .joins(sql_string_for_user_roles) #.joins(sql_string_for_user_sessions) users = users.page(query[:pagination][:page]) .per(query[:pagination][:perPage]) .order("#{query[:order][:by]} #{query[:order][:dir]} NULLS LAST") users.select( :id, "CONCAT(COALESCE(first_name, ''), ' ', COALESCE(last_name, '')) as name", :email, :active, :rolenames, Date2.new.date_time.db_column("current_sign_in_at") ) end |