Commit dbee13d6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-events-api' into 'master'

Fix events order in users/:id/events endpoint

Order of events in contributions API is currently being lost, though docs are saying:

> Get the contribution events for the specified user, sorted **from newest to oldest**.

Order becomes different after `.merge(ProjectsFinder.new.execute(current_user))` call, so I moved ordering below this line.

This MR also removes extra `.page(params[:page])` call in the method chain, since [`paginate(events)` already does it](https://gitlab.com/airat/gitlab-ce/blob/master/lib/api/helpers.rb#L112).

See merge request !7039
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 1e4b63b7
...@@ -9,6 +9,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -9,6 +9,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Fix issue boards user link when in subdirectory. !7018 - Fix issue boards user link when in subdirectory. !7018
- Refactor and add new environment functionality to CI yaml reference. !7026 - Refactor and add new environment functionality to CI yaml reference. !7026
- Fix typo in project settings that prevents users from enabling container registry. !7037 - Fix typo in project settings that prevents users from enabling container registry. !7037
- Fix events order in `users/:id/events` endpoint. !7039
- Remove extra line for empty issue description. !7045 - Remove extra line for empty issue description. !7045
- Don't append issue/MR templates to any existing text. !7050 - Don't append issue/MR templates to any existing text. !7050
- Fix error in generating labels. !7055 - Fix error in generating labels. !7055
......
...@@ -333,11 +333,11 @@ module API ...@@ -333,11 +333,11 @@ module API
user = User.find_by(id: declared(params).id) user = User.find_by(id: declared(params).id)
not_found!('User') unless user not_found!('User') unless user
events = user.recent_events. events = user.events.
merge(ProjectsFinder.new.execute(current_user)). merge(ProjectsFinder.new.execute(current_user)).
references(:project). references(:project).
with_associations. with_associations.
page(params[:page]) recent
present paginate(events), with: Entities::Event present paginate(events), with: Entities::Event
end end
......
...@@ -958,6 +958,29 @@ describe API::API, api: true do ...@@ -958,6 +958,29 @@ describe API::API, api: true do
expect(joined_event['author']['name']).to eq(user.name) expect(joined_event['author']['name']).to eq(user.name)
end end
end end
context 'when there are multiple events from different projects' do
let(:second_note) { create(:note_on_issue, project: create(:empty_project)) }
let(:third_note) { create(:note_on_issue, project: project) }
before do
second_note.project.add_user(user, :developer)
[second_note, third_note].each do |note|
EventCreateService.new.leave_note(note, user)
end
end
it 'returns events in the correct order (from newest to oldest)' do
get api("/users/#{user.id}/events", user)
comment_events = json_response.select { |e| e['action_name'] == 'commented on' }
expect(comment_events[0]['target_id']).to eq(third_note.id)
expect(comment_events[1]['target_id']).to eq(second_note.id)
expect(comment_events[2]['target_id']).to eq(note.id)
end
end
end end
it 'returns a 404 error if not found' do it 'returns a 404 error if not found' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment