lib/ecoportal/api/internal/account.rb in ecoportal-api-0.7.1 vs lib/ecoportal/api/internal/account.rb in ecoportal-api-0.7.2

- old
+ new

@@ -11,20 +11,38 @@ embeds_one :permissions, key: "permissions_custom", klass: :permissions_class embeds_one :preferences, klass: :preferences_class # Sets the `policy_group_ids` + # @note it preserves the original order + # @param value [Array<String>] the policy group ids to be set. def policy_group_ids=(value) unless value.is_a?(Array) raise "policy_group_ids= needs to be passed an Array, got #{value.class}" end + value.uniq! ini_ids = (original_doc && original_doc["policy_group_ids"]) || [] # preserve original order to avoid false updates doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids) end + # @return [Array<String>] the policy group ids of this user. + def policy_group_ids + doc["policy_group_ids"] ||= [] + end + + # @return [Array<String>] the login provider ids of this user. + def login_provider_ids + doc["login_provider_ids"] ||= [] + end + + # @return [Array<String>] the starred page ids of this user. + def starred_ids + doc["starred_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 @@ -33,9 +51,23 @@ # Gets the `permissions_preset`. # @note basically the same as `permissions_preset` but when 'nil', it returns `"custom"` instead # @return [nil, String] preset name. def preset self.permissions_preset.nil? ? "custom" : self.permissions_preset + end + + # It preserves the values of keys that are not defined in `value`. + # @param value [Hash] the abilities that you want to update. + def permissions_custom=(value) + doc["permissions_custom"] ||= {} + doc["permissions_custom"].merge!(value) + end + + # It preserves the values of keys that are not defined in `value`. + # @param value [Hash] the preferences that you want to update. + def preferences=(value) + doc["preferences"] ||= {} + doc["preferences"].merge!(value) end def as_json super.tap do |hash| if preset == "custom"