Class: ResourceLabelEvent

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

Constant Summary

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

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, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #updated_cached_html_for

Methods inherited from ResourceEvent

#discussion_id

Methods included from WorkItemResourceEvent

#trigger_note_subscription_create, #work_item_synthetic_system_note

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.issuable_attrsObject



23
24
25
# File 'app/models/resource_label_event.rb', line 23

def self.issuable_attrs
  %i[issue merge_request].freeze
end

.preload_label_subjects(events) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/resource_label_event.rb', line 27

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

  ActiveRecord::Associations::Preloader.new(records: project_labels, associations: { project: :project_feature }).call
  ActiveRecord::Associations::Preloader.new(records: group_labels, associations: :group).call
end

.visible_to_user?(user, events) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

#groupObject



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

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

#issuableObject



35
36
37
# File 'app/models/resource_label_event.rb', line 35

def issuable
  issue || merge_request
end

#outdated_markdown?Boolean

Returns:

  • (Boolean)


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

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

  reference.nil? || latest_cached_markdown_version != cached_markdown_version
end

#projectObject



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

def project
  issuable.project
end

#refresh_invalid_referenceObject



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

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

#synthetic_note_classObject



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

def synthetic_note_class
  LabelNote
end