diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-10-01 18:49:43 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-10-01 18:49:43 +0200 |
commit | 1cd07610664ab955c8a044b20c71224594a9a9bb (patch) | |
tree | e96e765ba0a148442efd477221fa9b77628f0f05 /lib/api | |
parent | c874a481346d0cd83801a510135f29c72fd8d3ae (diff) | |
parent | 7cb9957a33d37394cd884106865e4aedef519e97 (diff) | |
download | gitlab-ce-1cd07610664ab955c8a044b20c71224594a9a9bb.tar.gz |
Merge remote-tracking branch 'dev/master'
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/events.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/api/events.rb b/lib/api/events.rb index bca4db1a80e..6e0b508be19 100644 --- a/lib/api/events.rb +++ b/lib/api/events.rb @@ -18,12 +18,27 @@ module API desc: 'Return events sorted in ascending and descending order' end + RedactedEvent = OpenStruct.new(target_title: 'Confidential event').freeze + + def redact_events(events) + events.map do |event| + if event.visible_to_user?(current_user) + event + else + RedactedEvent + end + end + end + # rubocop: disable CodeReuse/ActiveRecord - def present_events(events) + def present_events(events, redact: true) events = events.reorder(created_at: params[:sort]) .with_associations - present paginate(events), with: Entities::Event + events = paginate(events) + events = redact_events(events) if redact + + present events, with: Entities::Event end # rubocop: enable CodeReuse/ActiveRecord end @@ -46,7 +61,8 @@ module API events = EventsFinder.new(params.merge(source: current_user, current_user: current_user)).execute.preload(:author, :target) - present_events(events) + # Since we're viewing our own events, redaction is unnecessary + present_events(events, redact: false) end # rubocop: enable CodeReuse/ActiveRecord end |