2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EventPresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
presents :event
|
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
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.
|
|
|
|
def visible_to_user?(user = nil)
|
|
|
|
@visible_to_user_cache.fetch(user&.id) { super(user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
# implement cache here
|
2019-12-04 20:38:33 +05:30
|
|
|
def resource_parent_name
|
|
|
|
resource_parent&.full_name || ''
|
|
|
|
end
|
|
|
|
|
|
|
|
def target_link_options
|
|
|
|
case resource_parent
|
|
|
|
when Group
|
|
|
|
[event.group, event.target]
|
|
|
|
when Project
|
|
|
|
[event.project.namespace.becomes(Namespace), event.project, event.target]
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|