Commit 9483cbab authored by Rémy Coutable's avatar Rémy Coutable 🏖

Merge branch '26468-fix-admin-recent-sign-in' into 'master'

Using correct column for sorting users by Recent Sign-in

Closes #26468

See merge request gitlab-org/gitlab-ce!13852
parents 84bda43a cca13d1e
......@@ -230,8 +230,8 @@ class User < ActiveRecord::Base
scope :active, -> { with_state(:active).non_internal }
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members WHERE user_id IS NOT NULL AND requested_at IS NULL)') }
scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) }
scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'DESC')) }
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) }
scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'DESC')) }
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) }
def self.with_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id =")
title: Fix Sort by Recent Sign-in in Admin Area
merge_request: 13852
author: Poornima M
......@@ -1433,28 +1433,34 @@ describe User do
describe '#sort' do
before do
@user = create :user, created_at:, last_sign_in_at:, name: 'Alpha'
@user1 = create :user, created_at: - 1, last_sign_in_at: - 1, name: 'Omega'
@user2 = create :user, created_at: - 2, last_sign_in_at: nil, name: 'Beta'
@user = create :user, created_at:, current_sign_in_at:, name: 'Alpha'
@user1 = create :user, created_at: - 1, current_sign_in_at: - 1, name: 'Omega'
@user2 = create :user, created_at: - 2, name: 'Beta'
context 'when sort by recent_sign_in' do
it 'sorts users by the recent sign-in time' do
expect(described_class.sort('recent_sign_in').first).to eq(@user)
let(:users) { described_class.sort('recent_sign_in') }
it 'sorts users by recent sign-in time' do
expect(users.first).to eq(@user)
expect(users.second).to eq(@user1)
it 'pushes users who never signed in to the end' do
expect(described_class.sort('recent_sign_in').third).to eq(@user2)
expect(users.third).to eq(@user2)
context 'when sort by oldest_sign_in' do
let(:users) { described_class.sort('oldest_sign_in') }
it 'sorts users by the oldest sign-in time' do
expect(described_class.sort('oldest_sign_in').first).to eq(@user1)
expect(users.first).to eq(@user1)
expect(users.second).to eq(@user)
it 'pushes users who never signed in to the end' do
expect(described_class.sort('oldest_sign_in').third).to eq(@user2)
expect(users.third).to eq(@user2)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment