Sha256: bb0d26bfc56bf91736931c22628ace91e803327523bf75d31c480e419850c366
Contents?: true
Size: 1.87 KB
Versions: 135
Compression:
Stored size: 1.87 KB
Contents
module Eco module API class MicroCases # Helper that makes sure the **custom `tags`** are preserved. # @note # - this feature is essential to preserve custom `tags` in users that have register tags. # - for this to work out, it requires a `tagtree` to be defined. # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes already done. # @param options [Hash] the options. # @option options [Hash<Symbol, Object>] :filter_tags options around `filter_tags`. # * `:preserve_custom` (Boolean) [true] indicates if original tags that are not in the tree should be added/preserved. # * `:add_custom` (Boolean) [true] indicates if target tags that are not in the tree should be really added. def fix_filter_tags(person, options) if session.tagtree unless !person.new? && (options.dig(:exclude, :core) || options.dig(:exclude, :filter_tags)) person.filter_tags = session.tagtree.user_tags( initial: person.original_doc["filter_tags"] || [], final: person.filter_tags, preserve_custom: _fix_filter_tags_preserve_custom?(options), add_custom: _fix_filter_tags_add_custom?(options) ) end end end private # default `true` def _fix_filter_tags_preserve_custom?(options) key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:preserve_custom) !key_defined || options.dig(:filter_tags, :preserve_custom) end # default `true` def _fix_filter_tags_add_custom?(options) key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:add_custom) !key_defined || options.dig(:filter_tags, :add_custom) end end end end
Version data entries
135 entries across 135 versions & 1 rubygems