lib/ecoportal/api/internal/account.rb in ecoportal-api-0.2.0 vs lib/ecoportal/api/internal/account.rb in ecoportal-api-0.2.1

- old
+ new

@@ -2,11 +2,25 @@ module API class Internal class Account < Common::BaseModel passthrough :policy_group_ids, :landing_page_id, :permissions_preset, :permissions_custom, :preferences, :prefilter, :filter_tags, :login_provider_ids, :starred_ids, to: :doc + VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/ + def preset=(value) self.permissions_preset = value == "custom" ? nil : value + end + + def filter_tags=(value) + unless value.is_a?(Array) + raise "filter_tags= needs to be passed an Array, got #{value.class}" + end + doc["filter_tags"] = value.map do |tag| + unless tag.match(VALID_TAG_REGEX) + raise "Invalid filter tag #{tag.inspect}" + end + tag.upcase + end end def preset self.permissions_preset.nil? ? "custom" : self.permissions_preset end