summaryrefslogtreecommitdiff
path: root/lib/api/events.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-10-01 18:49:43 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-10-01 18:49:43 +0200
commit1cd07610664ab955c8a044b20c71224594a9a9bb (patch)
treee96e765ba0a148442efd477221fa9b77628f0f05 /lib/api/events.rb
parentc874a481346d0cd83801a510135f29c72fd8d3ae (diff)
parent7cb9957a33d37394cd884106865e4aedef519e97 (diff)
downloadgitlab-ce-1cd07610664ab955c8a044b20c71224594a9a9bb.tar.gz
Merge remote-tracking branch 'dev/master'
Diffstat (limited to 'lib/api/events.rb')
-rw-r--r--lib/api/events.rb22
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