Module: Gitlab::MarkdownCache::ActiveRecord::Extension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/gitlab/markdown_cache/active_record/extension.rb
Instance Method Summary collapse
-
#attributes ⇒ Object
Always exclude _html fields from attributes (including serialization).
- #markdown_field_changed?(field_name) ⇒ Boolean
- #run_store_mentions! ⇒ Object
- #save_markdown(updates) ⇒ Object
- #write_markdown_field(field_name, value) ⇒ Object
Instance Method Details
#attributes ⇒ Object
Always exclude _html fields from attributes (including serialization). They contain unredacted HTML, which would be a security issue
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 28 def attributes attrs = super html_fields = cached_markdown_fields.html_fields whitelisted = cached_markdown_fields.html_fields_whitelisted exclude_fields = html_fields - whitelisted attrs.except!(*exclude_fields) attrs.delete('cached_markdown_version') if whitelisted.empty? attrs end |
#markdown_field_changed?(field_name) ⇒ Boolean
44 45 46 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 44 def markdown_field_changed?(field_name) attribute_changed?(field_name) end |
#run_store_mentions! ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 18 def run_store_mentions! if store_mentions_after_commit? run_after_commit { store_mentions! } else store_mentions! end end |
#save_markdown(updates) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 48 def save_markdown(updates) return unless persisted? && Gitlab::Database.read_write? return if cached_markdown_version.to_i < cached_markdown_version_in_database.to_i update_columns(updates) end |
#write_markdown_field(field_name, value) ⇒ Object
40 41 42 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 40 def write_markdown_field(field_name, value) write_attribute(field_name, value) end |