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
Jérome Perrin
gitlab-ce
Commits
4e0da232
Commit
4e0da232
authored
Oct 10, 2014
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Admin: user sorting
parent
9c824888
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
11 deletions
+70
-11
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+1
-0
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+11
-11
app/models/user.rb
app/models/user.rb
+10
-0
app/views/admin/users/index.html.haml
app/views/admin/users/index.html.haml
+20
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+28
-0
No files found.
app/controllers/admin/users_controller.rb
View file @
4e0da232
...
...
@@ -4,6 +4,7 @@ class Admin::UsersController < Admin::ApplicationController
def
index
@users
=
User
.
filter
(
params
[
:filter
])
@users
=
@users
.
search
(
params
[
:name
])
if
params
[
:name
].
present?
@users
=
@users
.
sort
(
@sort
=
params
[
:sort
])
@users
=
@users
.
alphabetically
.
page
(
params
[
:page
])
end
...
...
app/finders/snippets_finder.rb
View file @
4e0da232
...
...
@@ -30,7 +30,7 @@ class SnippetsFinder
snippets
=
user
.
snippets
.
fresh
.
non_expired
if
user
==
current_user
snippets
=
case
scope
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
...
...
@@ -41,7 +41,7 @@ class SnippetsFinder
snippets
end
else
snippets
=
snippets
.
public_and_internal
snippets
.
public_and_internal
end
end
...
...
app/models/user.rb
View file @
4e0da232
...
...
@@ -196,6 +196,16 @@ class User < ActiveRecord::Base
end
end
def
sort
(
method
)
case
method
.
to_s
when
'recent_sign_in'
then
reorder
(
'users.last_sign_in_at DESC'
)
when
'oldest_sign_in'
then
reorder
(
'users.last_sign_in_at ASC'
)
when
'recently_created'
then
reorder
(
'users.created_at DESC'
)
when
'late_created'
then
reorder
(
'users.created_at ASC'
)
else
reorder
(
"users.name ASC"
)
end
end
def
find_for_commit
(
email
,
name
)
# Prefer email match over name match
User
.
where
(
email:
email
).
first
||
...
...
app/views/admin/users/index.html.haml
View file @
4e0da232
...
...
@@ -32,6 +32,26 @@
.panel-heading
Users (
#{
@users
.
total_count
}
)
.panel-head-actions
.dropdown.inline
%a
.dropdown-toggle.btn
{
href:
'#'
,
"data-toggle"
=>
"dropdown"
}
%span
.light
sort:
-
if
@sort
.
present?
=
@sort
.
humanize
-
else
Name
%b
.caret
%ul
.dropdown-menu
%li
=
link_to
admin_users_path
(
sort:
nil
)
do
Name
=
link_to
admin_users_path
(
sort:
'recent_sign_in'
)
do
Recent sign in
=
link_to
admin_users_path
(
sort:
'oldest_sign_in'
)
do
Oldest sign in
=
link_to
admin_users_path
(
sort:
'recently_created'
)
do
Recently created
=
link_to
admin_users_path
(
sort:
'late_created'
)
do
Late created
=
link_to
'New User'
,
new_admin_user_path
,
class:
"btn btn-new"
%ul
.well-list
-
@users
.
each
do
|
user
|
...
...
spec/models/user_spec.rb
View file @
4e0da232
...
...
@@ -429,4 +429,32 @@ describe User do
expect
(
user
.
starred?
(
project
)).
to
be_false
end
end
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'
end
it
"sorts users as recently_signed_in"
do
User
.
sort
(
'recent_sign_in'
).
first
.
should
==
@user
end
it
"sorts users as late_signed_in"
do
User
.
sort
(
'oldest_sign_in'
).
first
.
should
==
@user1
end
it
"sorts users as recently_created"
do
User
.
sort
(
'recently_created'
).
first
.
should
==
@user
end
it
"sorts users as late_created"
do
User
.
sort
(
'late_created'
).
first
.
should
==
@user1
end
it
"sorts users by name when nil is passed"
do
User
.
sort
(
nil
).
first
.
should
==
@user
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