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
36c4e1db
Commit
36c4e1db
authored
Dec 23, 2019
by
Johan Henkens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add system/comment filter to notes api
parent
a36d844f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
1 deletion
+84
-1
changelogs/unreleased/notes_api_system_filter.yml
changelogs/unreleased/notes_api_system_filter.yml
+5
-0
lib/api/notes.rb
lib/api/notes.rb
+4
-1
spec/models/user_preference_spec.rb
spec/models/user_preference_spec.rb
+6
-0
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+69
-0
No files found.
changelogs/unreleased/notes_api_system_filter.yml
0 → 100644
View file @
36c4e1db
---
title
:
25968-activity-filter-to-notes-api
merge_request
:
21159
author
:
jhenkens
type
:
added
lib/api/notes.rb
View file @
36c4e1db
...
...
@@ -24,6 +24,8 @@ module API
desc:
'Return notes ordered by `created_at` or `updated_at` fields.'
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
desc:
'Return notes sorted in `asc` or `desc` order.'
optional
:activity_filter
,
type:
String
,
values:
UserPreference
::
NOTES_FILTERS
.
stringify_keys
.
keys
,
default:
'all_notes'
,
desc:
'The type of notables which are returned.'
use
:pagination
end
# rubocop: disable CodeReuse/ActiveRecord
...
...
@@ -35,7 +37,8 @@ module API
# at the DB query level (which we cannot in that case), the current
# page can have less elements than :per_page even if
# there's more than one page.
raw_notes
=
noteable
.
notes
.
with_metadata
.
reorder
(
order_options_with_tie_breaker
)
notes_filter
=
UserPreference
::
NOTES_FILTERS
[
params
[
:activity_filter
].
to_sym
]
raw_notes
=
noteable
.
notes
.
with_metadata
.
with_notes_filter
(
notes_filter
).
reorder
(
order_options_with_tie_breaker
)
# paginate() only works with a relation. This could lead to a
# mismatch between the pagination headers info and the actual notes
...
...
spec/models/user_preference_spec.rb
View file @
36c4e1db
...
...
@@ -5,6 +5,12 @@ require 'spec_helper'
describe
UserPreference
do
let
(
:user_preference
)
{
create
(
:user_preference
)
}
describe
'notes filters global keys'
do
it
'contains expected values'
do
expect
(
UserPreference
::
NOTES_FILTERS
.
keys
).
to
match_array
([
:all_notes
,
:only_comments
,
:only_activity
])
end
end
describe
'#set_notes_filter'
do
let
(
:issuable
)
{
build_stubbed
(
:issue
)
}
...
...
spec/requests/api/notes_spec.rb
View file @
36c4e1db
...
...
@@ -101,6 +101,75 @@ describe API::Notes do
expect
(
json_response
.
first
[
'body'
]).
to
eq
(
cross_reference_note
.
note
)
end
end
context
"activity filters"
do
let!
(
:user_reference_note
)
do
create
:note
,
noteable:
ext_issue
,
project:
ext_proj
,
note:
"Hello there general!"
,
system:
false
end
let
(
:test_url
)
{
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
iid
}
/notes"
}
shared_examples
'a notes request'
do
it
'is a note array response'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
end
end
context
"when not provided"
do
let
(
:count
)
{
2
}
before
do
get
api
(
test_url
,
private_user
)
end
it_behaves_like
'a notes request'
it
'returns all the notes'
do
expect
(
json_response
.
count
).
to
eq
(
count
)
end
end
context
"when all_notes provided"
do
let
(
:count
)
{
2
}
before
do
get
api
(
test_url
+
"?activity_filter=all_notes"
,
private_user
)
end
it_behaves_like
'a notes request'
it
'returns all the notes'
do
expect
(
json_response
.
count
).
to
eq
(
count
)
end
end
context
"when provided"
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:filter
,
:count
,
:system_notable
)
do
"only_comments"
|
1
|
false
"only_activity"
|
1
|
true
end
with_them
do
before
do
get
api
(
test_url
+
"?activity_filter=
#{
filter
}
"
,
private_user
)
end
it_behaves_like
'a notes request'
it
"properly filters the returned notables"
do
expect
(
json_response
.
count
).
to
eq
(
count
)
expect
(
json_response
.
first
[
"system"
]).
to
be
system_notable
end
end
end
end
end
describe
"GET /projects/:id/noteable/:noteable_id/notes/:note_id"
do
...
...
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