Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
8354c76f
Commit
8354c76f
authored
Jan 19, 2017
by
Poornima M
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing sort of Users so that users who never logged in will be displayed last
Adding changelog entry
parent
0fd7919e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
19 deletions
+36
-19
app/models/user.rb
app/models/user.rb
+2
-2
changelogs/unreleased/26468-fix-users-sort-in-admin-area.yml
changelogs/unreleased/26468-fix-users-sort-in-admin-area.yml
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+30
-17
No files found.
app/models/user.rb
View file @
8354c76f
...
@@ -179,8 +179,8 @@ class User < ActiveRecord::Base
...
@@ -179,8 +179,8 @@ class User < ActiveRecord::Base
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
all
}
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
all
}
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
(
last_sign_in_at: :desc
)
}
scope
:order_recent_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'last_sign_in_at'
,
'DESC'
)
)
}
scope
:order_oldest_sign_in
,
->
{
reorder
(
last_sign_in_at: :asc
)
}
scope
:order_oldest_sign_in
,
->
{
reorder
(
Gitlab
::
Database
.
nulls_last_order
(
'last_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"
).
...
...
changelogs/unreleased/26468-fix-users-sort-in-admin-area.yml
0 → 100644
View file @
8354c76f
---
title
:
Fix Sort by Recent Sign-in in Admin Area
merge_request
:
8637
author
:
Poornima M
spec/models/user_spec.rb
View file @
8354c76f
...
@@ -797,14 +797,14 @@ describe User, models: true do
...
@@ -797,14 +797,14 @@ describe User, models: true do
describe
'#avatar_type'
do
describe
'#avatar_type'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
it
"is true if avatar is image"
do
it
'is true if avatar is image'
do
user
.
update_attribute
(
:avatar
,
'uploads/avatar.png'
)
user
.
update_attribute
(
:avatar
,
'uploads/avatar.png'
)
expect
(
user
.
avatar_type
).
to
be_truthy
expect
(
user
.
avatar_type
).
to
be_truthy
end
end
it
"is false if avatar is html page"
do
it
'is false if avatar is html page'
do
user
.
update_attribute
(
:avatar
,
'uploads/avatar.html'
)
user
.
update_attribute
(
:avatar
,
'uploads/avatar.html'
)
expect
(
user
.
avatar_type
).
to
eq
([
"only images allowed"
])
expect
(
user
.
avatar_type
).
to
eq
([
'only images allowed'
])
end
end
end
end
...
@@ -926,8 +926,8 @@ describe User, models: true do
...
@@ -926,8 +926,8 @@ describe User, models: true do
end
end
end
end
describe
"#starred?"
do
describe
'#starred?'
do
it
"determines if user starred a project"
do
it
'determines if user starred a project'
do
user
=
create
:user
user
=
create
:user
project1
=
create
(
:empty_project
,
:public
)
project1
=
create
(
:empty_project
,
:public
)
project2
=
create
(
:empty_project
,
:public
)
project2
=
create
(
:empty_project
,
:public
)
...
@@ -953,8 +953,8 @@ describe User, models: true do
...
@@ -953,8 +953,8 @@ describe User, models: true do
end
end
end
end
describe
"#toggle_star"
do
describe
'#toggle_star'
do
it
"toggles stars"
do
it
'toggles stars'
do
user
=
create
:user
user
=
create
:user
project
=
create
(
:empty_project
,
:public
)
project
=
create
(
:empty_project
,
:public
)
...
@@ -966,31 +966,44 @@ describe User, models: true do
...
@@ -966,31 +966,44 @@ describe User, models: true do
end
end
end
end
describe
"#sort"
do
describe
'#sort'
do
before
do
before
do
User
.
delete_all
User
.
delete_all
@user
=
create
:user
,
created_at:
Date
.
today
,
last_sign_in_at:
Date
.
today
,
name:
'Alpha'
@user
=
create
:user
,
created_at:
Date
.
today
,
last_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
,
last_sign_in_at:
Date
.
today
-
1
,
name:
'Omega'
@user2
=
create
:user
,
created_at:
Date
.
today
-
2
,
last_sign_in_at:
nil
,
name:
'Beta'
end
end
it
"sorts users by the recent sign-in time"
do
context
'when sort by recent_sign_in'
do
expect
(
User
.
sort
(
'recent_sign_in'
).
first
).
to
eq
(
@user
)
it
'sorts users by the recent sign-in time'
do
expect
(
User
.
sort
(
'recent_sign_in'
).
first
).
to
eq
(
@user
)
end
it
'pushes users who never signed in to the end'
do
expect
(
User
.
sort
(
'recent_sign_in'
).
third
).
to
eq
(
@user2
)
end
end
end
it
"sorts users by the oldest sign-in time"
do
context
'when sort by oldest_sign_in'
do
expect
(
User
.
sort
(
'oldest_sign_in'
).
first
).
to
eq
(
@user1
)
it
'sorts users by the oldest sign-in time'
do
expect
(
User
.
sort
(
'oldest_sign_in'
).
first
).
to
eq
(
@user1
)
end
it
'pushes users who never signed in to the end'
do
expect
(
User
.
sort
(
'oldest_sign_in'
).
third
).
to
eq
(
@user2
)
end
end
end
it
"sorts users in descending order by their creation time"
do
it
'sorts users in descending order by their creation time'
do
expect
(
User
.
sort
(
'created_desc'
).
first
).
to
eq
(
@user
)
expect
(
User
.
sort
(
'created_desc'
).
first
).
to
eq
(
@user
)
end
end
it
"sorts users in ascending order by their creation time"
do
it
'sorts users in ascending order by their creation time'
do
expect
(
User
.
sort
(
'created_asc'
).
first
).
to
eq
(
@user
1
)
expect
(
User
.
sort
(
'created_asc'
).
first
).
to
eq
(
@user
2
)
end
end
it
"sorts users by id in descending order when nil is passed"
do
it
'sorts users by id in descending order when nil is passed'
do
expect
(
User
.
sort
(
nil
).
first
).
to
eq
(
@user
1
)
expect
(
User
.
sort
(
nil
).
first
).
to
eq
(
@user
2
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment