Class: ResourceLabelEvent

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

Constant Summary

Constants included from Import::HasImportSource

Import::HasImportSource::IMPORT_SOURCES

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#importing, #user_contributions

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Import::HasImportSource

#imported?

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, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

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
# 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 }

  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)


59
60
61
62
63
64
65
# File 'app/models/resource_label_event.rb', line 59

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

#issuableObject



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

def issuable
  issue || merge_request
end

#outdated_reference?Boolean

Returns:

  • (Boolean)


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

def outdated_reference?
  (label_id.nil? && reference.present?) || reference.nil?
end

#refresh_invalid_referenceObject



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

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

  save if changed?
end

#synthetic_note_classObject



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

def synthetic_note_class
  LabelNote
end