Class: ResourceLabelEvent

Inherits:
ResourceEvent show all
Includes:
CacheMarkdownField, IssueResourceEvent, MergeRequestResourceEvent
Defined in:
app/models/resource_label_event.rb

Constant Summary

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CacheMarkdownField

#attribute_invalidated?, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #updated_cached_html_for

Methods inherited from ResourceEvent

#discussion_id

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.issuable_attrsObject


25
26
27
# File 'app/models/resource_label_event.rb', line 25

def self.issuable_attrs
  %i(issue merge_request).freeze
end

.preload_label_subjects(events) ⇒ Object


29
30
31
32
33
34
35
36
# File 'app/models/resource_label_event.rb', line 29

def self.preload_label_subjects(events)
  labels = events.map(&:label).compact
  project_labels, group_labels = labels.partition { |label| label.is_a? ProjectLabel }

  preloader = ActiveRecord::Associations::Preloader.new
  preloader.preload(project_labels, { project: :project_feature })
  preloader.preload(group_labels, :group)
end

.visible_to_user?(user, events) ⇒ Boolean

Returns:

  • (Boolean)

74
75
76
77
78
79
80
# File 'app/models/resource_label_event.rb', line 74

def self.visible_to_user?(user, events)
  ResourceLabelEvent.preload_label_subjects(events)

  events.select do |event|
    Ability.allowed?(user, :read_label, event)
  end
end

Instance Method Details

#banzai_render_context(field) ⇒ Object


56
57
58
# File 'app/models/resource_label_event.rb', line 56

def banzai_render_context(field)
  super.merge(pipeline: :label, only_path: true)
end

#groupObject


46
47
48
# File 'app/models/resource_label_event.rb', line 46

def group
  issuable.group if issuable.respond_to?(:group)
end

#issuableObject


38
39
40
# File 'app/models/resource_label_event.rb', line 38

def issuable
  issue || merge_request
end

#outdated_markdown?Boolean

Returns:

  • (Boolean)

50
51
52
53
54
# File 'app/models/resource_label_event.rb', line 50

def outdated_markdown?
  return true if label_id.nil? && reference.present?

  reference.nil? || latest_cached_markdown_version != cached_markdown_version
end

#projectObject


42
43
44
# File 'app/models/resource_label_event.rb', line 42

def project
  issuable.project
end

#refresh_invalid_referenceObject


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/resource_label_event.rb', line 60

def refresh_invalid_reference
  # label_id could be nullified on label delete
  self.reference = '' if label_id.nil?

  # reference is not set for events which were not rendered yet
  self.reference ||= label_reference

  if changed?
    save
  elsif invalidated_markdown_cache?
    refresh_markdown_cache!
  end
end