Sha256: fdac7b0d401e2489b23758528a8320b43bc40ecca8629fc90db09bba68ee8929
Contents?: true
Size: 1.95 KB
Versions: 27
Compression:
Stored size: 1.95 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) return unless session.tagtree filter_tags_excluded = options.dig(:exclude, :core) || options.dig(:exclude, :filter_tags) return if !person.new? && filter_tags_excluded 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 private # default `true` def _fix_filter_tags_preserve_custom?(options) key_defined = options.key?(:filter_tags) && options[:filter_tags].key?(:preserve_custom) return true unless 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) return true unless key_defined options.dig(:filter_tags, :add_custom) end end end end
Version data entries
27 entries across 27 versions & 1 rubygems