lib/ecoportal/api/internal/account.rb in ecoportal-api-0.5.6 vs lib/ecoportal/api/internal/account.rb in ecoportal-api-0.5.7

- old
+ new

@@ -10,9 +10,20 @@ class_resolver :permissions_class, "Ecoportal::API::Internal::Permissions" embeds_one :permissions, key: "permissions_custom", klass: :permissions_class embeds_one :preferences, klass: :preferences_class + # Sets the `policy_group_ids` + def policy_group_ids=(value) + unless value.is_a?(Array) + raise "policy_group_ids= needs to be passed an Array, got #{value.class}" + end + + ini_ids = original_doc["policy_group_ids"] || [] + # preserve original order to avoid false updates + doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids) + end + # Sets the `permissions_preset`. # @note basically the same as `permissions_preset=` but when `"custom"`, it's changed to `nil` # @param value [nil, String] preset name. def preset=(value) self.permissions_preset = value == "custom" ? nil : value