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
- #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
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 20 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
36 37 38 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 36 def markdown_field_changed?(field_name) attribute_changed?(field_name) end |
#save_markdown(updates) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 40 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
32 33 34 |
# File 'lib/gitlab/markdown_cache/active_record/extension.rb', line 32 def write_markdown_field(field_name, value) write_attribute(field_name, value) end |