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
Boxiang Sun
gitlab-ce
Commits
377244dd
Commit
377244dd
authored
Jul 07, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor filters
parent
bfe5f2d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
25 deletions
+22
-25
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-12
app/finders/users_finder.rb
app/finders/users_finder.rb
+2
-12
lib/gitlab/database/created_at_filter.rb
lib/gitlab/database/created_at_filter.rb
+17
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+1
-1
No files found.
app/finders/issuable_finder.rb
View file @
377244dd
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
# iids: integer[]
# iids: integer[]
#
#
class
IssuableFinder
class
IssuableFinder
include
Gitlab
::
Database
::
CreatedAtFilter
NONE
=
'0'
.
freeze
NONE
=
'0'
.
freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY
=
%i[utf8 sort page]
.
freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY
=
%i[utf8 sort page]
.
freeze
...
@@ -408,18 +410,6 @@ class IssuableFinder
...
@@ -408,18 +410,6 @@ class IssuableFinder
params
[
:non_archived
].
present?
?
items
.
non_archived
:
items
params
[
:non_archived
].
present?
?
items
.
non_archived
:
items
end
end
def
by_created_at
(
items
)
if
params
[
:created_after
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
gteq
(
params
[
:created_after
]))
end
if
params
[
:created_before
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
lteq
(
params
[
:created_before
]))
end
items
end
def
current_user_related?
def
current_user_related?
params
[
:scope
]
==
'created-by-me'
||
params
[
:scope
]
==
'authored'
||
params
[
:scope
]
==
'assigned-to-me'
params
[
:scope
]
==
'created-by-me'
||
params
[
:scope
]
==
'authored'
||
params
[
:scope
]
==
'assigned-to-me'
end
end
...
...
app/finders/users_finder.rb
View file @
377244dd
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
# external: boolean
# external: boolean
#
#
class
UsersFinder
class
UsersFinder
include
Gitlab
::
Database
::
CreatedAtFilter
attr_accessor
:current_user
,
:params
attr_accessor
:current_user
,
:params
def
initialize
(
current_user
,
params
=
{})
def
initialize
(
current_user
,
params
=
{})
...
@@ -72,16 +74,4 @@ class UsersFinder
...
@@ -72,16 +74,4 @@ class UsersFinder
users
.
external
users
.
external
end
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
end
lib/gitlab/database/created_at_filter.rb
0 → 100644
View file @
377244dd
module
Gitlab
module
Database
module
CreatedAtFilter
def
by_created_at
(
items
)
if
params
[
:created_after
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
gteq
(
params
[
:created_after
]))
end
if
params
[
:created_before
].
present?
items
=
items
.
where
(
items
.
klass
.
arel_table
[
:created_at
].
lteq
(
params
[
:created_before
]))
end
items
end
end
end
end
spec/requests/api/users_spec.rb
View file @
377244dd
...
@@ -164,7 +164,7 @@ describe API::Users do
...
@@ -164,7 +164,7 @@ describe API::Users do
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
it
"returns a
n
user created before a specific date"
do
it
"returns a user created before a specific date"
do
user
=
create
(
:user
,
created_at:
Date
.
new
(
2000
,
1
,
1
))
user
=
create
(
:user
,
created_at:
Date
.
new
(
2000
,
1
,
1
))
get
api
(
"/users?created_before=2000-01-02T00:00:00.060Z"
,
admin
)
get
api
(
"/users?created_before=2000-01-02T00:00:00.060Z"
,
admin
)
...
...
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