summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-06-05 20:26:56 +0800
committerPatrick Bajao <ebajao@gitlab.com>2019-06-05 20:30:43 +0800
commitea12c5aae83dd3f2edefce765438e94ff7c4f870 (patch)
tree3063af3b1ca6ea3e30a7eb4fd9e7d03a0caf8104
parent93dd5390b6b4bc94cc83626e1369f3925c82028e (diff)
downloadgitlab-ce-54140-non-ar-cache-commit-markdown.tar.gz
Cleanup #attributes method54140-non-ar-cache-commit-markdown
Since we're prepending the ActiveRecord::Extension module, we can take advantage of it and avoid using an alias to extend the original #attributes method.
-rw-r--r--lib/gitlab/markdown_cache/active_record/extension.rb34
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/gitlab/markdown_cache/active_record/extension.rb b/lib/gitlab/markdown_cache/active_record/extension.rb
index bcc3432bd31..f3abe631779 100644
--- a/lib/gitlab/markdown_cache/active_record/extension.rb
+++ b/lib/gitlab/markdown_cache/active_record/extension.rb
@@ -7,31 +7,25 @@ module Gitlab
extend ActiveSupport::Concern
included do
- # Always exclude _html fields from attributes (including serialization).
- # They contain unredacted HTML, which would be a security issue
- alias_method :attributes_before_markdown_cache, :attributes
- def attributes
- attrs = attributes_before_markdown_cache
- html_fields = cached_markdown_fields.html_fields
- whitelisted = cached_markdown_fields.html_fields_whitelisted
- exclude_fields = html_fields - whitelisted
-
- exclude_fields.each do |field|
- attrs.delete(field)
- end
-
- if whitelisted.empty?
- attrs.delete('cached_markdown_version')
- end
-
- attrs
- end
-
# Using before_update here conflicts with elasticsearch-model somehow
before_create :refresh_markdown_cache, if: :invalidated_markdown_cache?
before_update :refresh_markdown_cache, if: :invalidated_markdown_cache?
end
+ # Always exclude _html fields from attributes (including serialization).
+ # They contain unredacted HTML, which would be a security issue
+ 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
+
def changed_markdown_fields
changed_attributes.keys.map(&:to_s) & cached_markdown_fields.markdown_fields.map(&:to_s)
end