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
This commit is contained in:
commit
9483cbab26
|
@ -230,8 +230,8 @@ class User < ActiveRecord::Base
|
||||||
scope :active, -> { with_state(:active).non_internal }
|
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 :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 :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_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('last_sign_in_at', 'ASC')) }
|
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) }
|
||||||
|
|
||||||
def self.with_two_factor
|
def self.with_two_factor
|
||||||
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
|
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
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
|
describe '#sort' do
|
||||||
before do
|
before do
|
||||||
described_class.delete_all
|
described_class.delete_all
|
||||||
@user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha'
|
@user = create :user, created_at: Date.today, current_sign_in_at: Date.today, name: 'Alpha'
|
||||||
@user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega'
|
@user1 = create :user, created_at: Date.today - 1, current_sign_in_at: Date.today - 1, name: 'Omega'
|
||||||
@user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta'
|
@user2 = create :user, created_at: Date.today - 2, name: 'Beta'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sort by recent_sign_in' do
|
context 'when sort by recent_sign_in' do
|
||||||
it 'sorts users by the recent sign-in time' do
|
let(:users) { described_class.sort('recent_sign_in') }
|
||||||
expect(described_class.sort('recent_sign_in').first).to eq(@user)
|
|
||||||
|
it 'sorts users by recent sign-in time' do
|
||||||
|
expect(users.first).to eq(@user)
|
||||||
|
expect(users.second).to eq(@user1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'pushes users who never signed in to the end' do
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sort by oldest_sign_in' do
|
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
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'pushes users who never signed in to the end' do
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue