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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1a7d2aba
Commit
1a7d2aba
authored
Jul 07, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add created at filter logic to users finder and API
parent
b08df253
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
app/finders/users_finder.rb
app/finders/users_finder.rb
+13
-0
lib/api/users.rb
lib/api/users.rb
+6
-0
spec/finders/users_finder_spec.rb
spec/finders/users_finder_spec.rb
+3
-1
No files found.
app/finders/users_finder.rb
View file @
1a7d2aba
...
...
@@ -29,6 +29,7 @@ class UsersFinder
users
=
by_active
(
users
)
users
=
by_external_identity
(
users
)
users
=
by_external
(
users
)
users
=
by_created_at
(
users
)
users
end
...
...
@@ -71,4 +72,16 @@ class UsersFinder
users
.
external
end
def
by_created_at
(
users
)
if
params
[
:created_after
].
present?
users
=
users
.
where
(
users
.
klass
.
arel_table
[
:created_at
].
gteq
(
params
[
:created_after
]))
end
if
params
[
:created_before
].
present?
users
=
users
.
where
(
users
.
klass
.
arel_table
[
:created_at
].
lteq
(
params
[
:created_before
]))
end
users
end
end
lib/api/users.rb
View file @
1a7d2aba
...
...
@@ -48,6 +48,8 @@ module API
optional
:active
,
type:
Boolean
,
default:
false
,
desc:
'Filters only active users'
optional
:external
,
type:
Boolean
,
default:
false
,
desc:
'Filters only external users'
optional
:blocked
,
type:
Boolean
,
default:
false
,
desc:
'Filters only blocked users'
optional
:created_after
,
type:
DateTime
,
desc:
'Return users created after the specified time'
optional
:created_before
,
type:
DateTime
,
desc:
'Return users created before the specified time'
all_or_none_of
:extern_uid
,
:provider
use
:pagination
...
...
@@ -55,6 +57,10 @@ module API
get
do
authenticated_as_admin!
if
params
[
:external
].
present?
||
(
params
[
:extern_uid
].
present?
&&
params
[
:provider
].
present?
)
unless
current_user
.
admin?
params
.
except!
(
:created_after
,
:created_before
)
end
users
=
UsersFinder
.
new
(
current_user
,
params
).
execute
authorized
=
can?
(
current_user
,
:read_users_list
)
...
...
spec/finders/users_finder_spec.rb
View file @
1a7d2aba
...
...
@@ -47,7 +47,9 @@ describe UsersFinder do
end
it
'filters by created_at'
do
users
=
described_class
.
new
(
user
,
created_after:
2
.
days
.
ago
,
created_before:
Time
.
now
+
2
.
days
).
execute
users
=
described_class
.
new
(
user
,
created_after:
2
.
days
.
ago
,
created_before:
Time
.
now
+
2
.
days
).
execute
expect
(
users
.
count
).
to
eq
(
4
)
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