2019-09-10 06:11:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EventPresenter < Gitlab::View::Presenter::Delegated
|
2021-09-21 05:12:21 -04:00
|
|
|
presents ::Event, as: :event
|
2019-09-10 06:11:38 -04:00
|
|
|
|
2020-01-30 16:08:47 -05:00
|
|
|
def initialize(subject, **attributes)
|
|
|
|
super
|
|
|
|
|
|
|
|
@visible_to_user_cache = ActiveSupport::Cache::MemoryStore.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# Caching `visible_to_user?` method in the presenter beause it might be called multiple times.
|
2021-09-21 05:12:21 -04:00
|
|
|
delegator_override :visible_to_user?
|
2020-01-30 16:08:47 -05:00
|
|
|
def visible_to_user?(user = nil)
|
|
|
|
@visible_to_user_cache.fetch(user&.id) { super(user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
# implement cache here
|
2019-09-10 06:11:38 -04:00
|
|
|
def resource_parent_name
|
|
|
|
resource_parent&.full_name || ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def target_link_options
|
|
|
|
case resource_parent
|
|
|
|
when Group
|
|
|
|
[event.group, event.target]
|
|
|
|
when Project
|
2020-07-27 08:09:50 -04:00
|
|
|
[event.project, event.target]
|
2019-09-10 06:11:38 -04:00
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
2020-09-30 20:10:16 -04:00
|
|
|
|
|
|
|
def target_type_name
|
|
|
|
if design?
|
|
|
|
'Design'
|
|
|
|
elsif wiki_page?
|
|
|
|
'Wiki Page'
|
|
|
|
elsif target_type.present?
|
|
|
|
target_type.titleize
|
|
|
|
else
|
|
|
|
"Project"
|
|
|
|
end.downcase
|
|
|
|
end
|
|
|
|
|
|
|
|
def note_target_type_name
|
|
|
|
return unless note?
|
|
|
|
|
|
|
|
if design_note?
|
|
|
|
'Design'
|
|
|
|
else
|
|
|
|
target.noteable_type.titleize
|
|
|
|
end.downcase
|
|
|
|
end
|
2019-09-10 06:11:38 -04:00
|
|
|
end
|