Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
8354c76f
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8354c76f
编写于
1月 19, 2017
作者:
P
Poornima M
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixing sort of Users so that users who never logged in will be displayed last
Adding changelog entry
上级
0fd7919e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
19 deletion
+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
未找到文件。
app/models/user.rb
浏览文件 @
8354c76f
...
...
@@ -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
: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
(
last_sign_in_at: :desc
)
}
scope
:order_oldest_sign_in
,
->
{
reorder
(
last_sign_in_at: :asc
)
}
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'
)
)
}
def
self
.
with_two_factor
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
浏览文件 @
8354c76f
---
title
:
Fix Sort by Recent Sign-in in Admin Area
merge_request
:
8637
author
:
Poornima M
spec/models/user_spec.rb
浏览文件 @
8354c76f
...
...
@@ -797,14 +797,14 @@ describe User, models: true do
describe
'#avatar_type'
do
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'
)
expect
(
user
.
avatar_type
).
to
be_truthy
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'
)
expect
(
user
.
avatar_type
).
to
eq
([
"only images allowed"
])
expect
(
user
.
avatar_type
).
to
eq
([
'only images allowed'
])
end
end
...
...
@@ -926,8 +926,8 @@ describe User, models: true do
end
end
describe
"#starred?"
do
it
"determines if user starred a project"
do
describe
'#starred?'
do
it
'determines if user starred a project'
do
user
=
create
:user
project1
=
create
(
:empty_project
,
:public
)
project2
=
create
(
:empty_project
,
:public
)
...
...
@@ -953,8 +953,8 @@ describe User, models: true do
end
end
describe
"#toggle_star"
do
it
"toggles stars"
do
describe
'#toggle_star'
do
it
'toggles stars'
do
user
=
create
:user
project
=
create
(
:empty_project
,
:public
)
...
...
@@ -966,31 +966,44 @@ describe User, models: true do
end
end
describe
"#sort"
do
describe
'#sort'
do
before
do
User
.
delete_all
@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'
@user2
=
create
:user
,
created_at:
Date
.
today
-
2
,
last_sign_in_at:
nil
,
name:
'Beta'
end
it
"sorts users by the recent sign-in time"
do
expect
(
User
.
sort
(
'recent_sign_in'
).
first
).
to
eq
(
@user
)
context
'when sort by recent_sign_in'
do
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
it
"sorts users by the oldest sign-in time"
do
expect
(
User
.
sort
(
'oldest_sign_in'
).
first
).
to
eq
(
@user1
)
context
'when sort by oldest_sign_in'
do
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
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
)
end
it
"sorts users in ascending order by their creation time"
do
expect
(
User
.
sort
(
'created_asc'
).
first
).
to
eq
(
@user
1
)
it
'sorts users in ascending order by their creation time'
do
expect
(
User
.
sort
(
'created_asc'
).
first
).
to
eq
(
@user
2
)
end
it
"sorts users by id in descending order when nil is passed"
do
expect
(
User
.
sort
(
nil
).
first
).
to
eq
(
@user
1
)
it
'sorts users by id in descending order when nil is passed'
do
expect
(
User
.
sort
(
nil
).
first
).
to
eq
(
@user
2
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录