Class: EventPresenter

Inherits:
Gitlab::View::Presenter::Delegated show all
Defined in:
app/presenters/event_presenter.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::DelegatorOverride

#delegator_override, #delegator_override_with, #delegator_target, validator, validators, verify!

Methods included from Gitlab::View::Presenter::Base

#__subject__, #can?, #declarative_policy_delegate, #is_a?, #path_with_line_numbers, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Methods included from Gitlab::Routing

includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

#initialize(event, **attributes) ⇒ EventPresenter



6
7
8
9
10
# File 'app/presenters/event_presenter.rb', line 6

def initialize(event, **attributes)
  super

  @visible_to_user_cache = ActiveSupport::Cache::MemoryStore.new
end

Instance Method Details

#batch_push?Boolean



74
75
76
# File 'app/presenters/event_presenter.rb', line 74

def batch_push?
  push_action? && ref_count.to_i > 0
end

#linked_to_reference?Boolean



78
79
80
81
82
83
84
85
86
87
# File 'app/presenters/event_presenter.rb', line 78

def linked_to_reference?
  return false unless push_action?
  return false if event.project.nil?

  if tag?
    project.repository.tag_exists?(ref_name)
  else
    project.repository.branch_exists?(ref_name)
  end
end

#note_target_type_nameObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/presenters/event_presenter.rb', line 50

def note_target_type_name
  return unless note?

  if design_note?
    'Design'
  elsif wiki_page_note?
    'Wiki Page'
  elsif target.for_issue? || target.for_work_item?
    target.noteable.issue_type
  else
    target.noteable_type.titleize
  end.downcase
end

#push_activity_descriptionObject



64
65
66
67
68
69
70
71
72
# File 'app/presenters/event_presenter.rb', line 64

def push_activity_description
  return unless push_action?

  if batch_push?
    "#{action_name} #{ref_count} #{ref_type.pluralize(ref_count)}"
  else
    "#{action_name} #{ref_type}"
  end
end

#resource_parent_nameObject

implement cache here



21
22
23
# File 'app/presenters/event_presenter.rb', line 21

def resource_parent_name
  resource_parent&.full_name || ''
end


25
26
27
28
29
30
31
32
33
34
# File 'app/presenters/event_presenter.rb', line 25

def target_link_options
  case resource_parent
  when Group
    [event.group, event.target]
  when Project
    [event.project, event.target]
  else
    ''
  end
end

#target_type_nameObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/presenters/event_presenter.rb', line 36

def target_type_name
  if design?
    'Design'
  elsif wiki_page?
    'Wiki Page'
  elsif issue? || work_item?
    target.issue_type
  elsif target_type.present?
    target_type.titleize
  else
    "Project"
  end.downcase
end

#visible_to_user?(user = nil) ⇒ Boolean



14
15
16
17
18
# File 'app/presenters/event_presenter.rb', line 14

def visible_to_user?(user = nil)
  return super(user) unless user

  @visible_to_user_cache.fetch(user&.id) { super(user) }
end