Module: Gitlab::BackgroundMigration::UserMentions::Models::Concerns::IsolatedMentionable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb
Overview
IsolatedMentionable concern
Shortcutted for isolation version of Mentionable to be used in mentions migrations
Instance Method Summary collapse
- #all_references(current_user = nil, extractor: nil) ⇒ Object
- #array_to_sql(ids_array) ⇒ Object
- #build_mention_values(resource_foreign_key) ⇒ Object
- #extractors ⇒ Object
- #skip_project_check? ⇒ Boolean
Instance Method Details
#all_references(current_user = nil, extractor: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb', line 34 def all_references(current_user = nil, extractor: nil) # Use custom extractor if it's passed in the function parameters. if extractor extractors[current_user] = extractor else extractor = extractors[current_user] ||= ::Gitlab::ReferenceExtractor.new(project, current_user) extractor.reset_memoized_values end self.class.mentionable_attrs.each do |attr, | text = __send__(attr) # rubocop:disable GitlabSecurity/PublicSend = .merge( cache_key: [self, attr], author: , skip_project_check: skip_project_check? ).merge(mentionable_params) cached_html = self.try(:updated_cached_html_for, attr.to_sym) [:rendered] = cached_html if cached_html extractor.analyze(text, ) end extractor end |
#array_to_sql(ids_array) ⇒ Object
87 88 89 90 91 |
# File 'lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb', line 87 def array_to_sql(ids_array) return unless ids_array.present? '{' + ids_array.join(", ") + '}' end |
#build_mention_values(resource_foreign_key) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb', line 69 def build_mention_values(resource_foreign_key) refs = all_references() mentioned_users_ids = array_to_sql(refs.mentioned_users.pluck(:id)) mentioned_projects_ids = array_to_sql(refs.mentioned_projects.pluck(:id)) mentioned_groups_ids = array_to_sql(refs.mentioned_groups.pluck(:id)) return if mentioned_users_ids.blank? && mentioned_projects_ids.blank? && mentioned_groups_ids.blank? { "#{resource_foreign_key}": user_mention_resource_id, note_id: user_mention_note_id, mentioned_users_ids: mentioned_users_ids, mentioned_projects_ids: mentioned_projects_ids, mentioned_groups_ids: mentioned_groups_ids } end |
#extractors ⇒ Object
61 62 63 |
# File 'lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb', line 61 def extractors @extractors ||= {} end |
#skip_project_check? ⇒ Boolean
65 66 67 |
# File 'lib/gitlab/background_migration/user_mentions/models/concerns/isolated_mentionable.rb', line 65 def skip_project_check? false end |