module Ecoportal module API class Internal class Account < Common::BaseModel PROPERTIES = [ "user_id", "policy_group_ids", "default_tag", "prefilter", "permissions_custom", "permissions_merged", "preferences", "login_provider_ids", "starred_ids", "landing_page_id", "accept_eula", "send_invites" ] passthrough *PROPERTIES.map(&:to_sym) class_resolver :preferences_class, "Ecoportal::API::Internal::Preferences" class_resolver :permissions_class, "Ecoportal::API::Internal::Permissions" embeds_one :permissions, key: "permissions_custom", klass: :permissions_class embeds_one :perms_merged, key: "permissions_merged", klass: :permissions_class embeds_one :preferences, klass: :preferences_class # Sets the `policy_group_ids` # @note it preserves the original order # @param value [Array] the policy group ids to be set. def policy_group_ids=(value) set_uniq_array_keep_order("policy_group_ids", value) end # @return [Array] the policy group ids of this user. def policy_group_ids doc["policy_group_ids"] ||= [] end # Sets the `login_provider_ids` def login_provider_ids=(value) set_uniq_array_keep_order("login_provider_ids", value) end # @return [Array] the login provider ids of this user. def login_provider_ids doc["login_provider_ids"] ||= [] end # Sets the `starred_ids` def starred_ids=(value) set_uniq_array_keep_order("starred_ids", value) end # @return [Array] the starred page ids of this user. def starred_ids doc["starred_ids"] ||= [] 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| hash["permissions_custom"] = permissions.as_json hash["permissions_merged"] = perms_merged.as_json hash["preferences"] = preferences.as_json end end def as_update(ref = :last, ignore: []) super(ref, ignore: ignore | ["user_id", "permissions_merged", "prefilter"]) end end end end end require 'ecoportal/api/internal/permissions' require 'ecoportal/api/internal/preferences'