Class: Ecoportal::API::Internal::Account

Inherits:
Common::BaseModel show all
Defined in:
lib/ecoportal/api/internal/account.rb

Constant Summary collapse

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", "force_send_invites"
]

Instance Attribute Summary

Attributes inherited from Common::BaseModel

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Common::BaseModel

#consolidate!, #dirty?, #doc, embeds_one, #initial_doc, #initialize, #original_doc, passthrough, #print_pretty, #replace_doc!, #replace_original_doc!, #reset!, #to_json

Methods included from Common::BaseClass

#class_resolver, #redef_without_warning, #resolve_class

Constructor Details

This class inherits a constructor from Ecoportal::API::Common::BaseModel

Instance Method Details

#as_jsonObject



83
84
85
86
87
88
89
# File 'lib/ecoportal/api/internal/account.rb', line 83

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

#as_update(ref = :last, ignore: []) ⇒ Object



91
92
93
# File 'lib/ecoportal/api/internal/account.rb', line 91

def as_update(ref = :last, ignore: [])
  super(ref, ignore: ignore | ["user_id", "permissions_merged", "prefilter"])
end

#default_tag=(value) ⇒ String?

Note:

it upcases the value

Sets the default_tag of the user

Parameters:

  • value (String, nil)

    the tag

Returns:

  • (String, nil)

    the value set in default_tag



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ecoportal/api/internal/account.rb', line 24

def default_tag=(value)
  unless !value || value.is_a?(String)
    raise ArgumentError.new("default_tag= needs to be passed a String or nil, got #{value.class}")
  end
  if value
    unless value.match(Ecoportal::API::V1::Person::VALID_TAG_REGEX)
      raise ArgumentError.new("Invalid default tag #{value.inspect}")
    end
    value = value.upcase
  end
  doc["default_tag"] = value
end

#login_provider_idsArray<String>

Returns the login provider ids of this user.

Returns:

  • (Array<String>)

    the login provider ids of this user.



55
56
57
# File 'lib/ecoportal/api/internal/account.rb', line 55

def 
  doc["login_provider_ids"] ||= []
end

#login_provider_ids=(value) ⇒ Object

Sets the login_provider_ids



50
51
52
# File 'lib/ecoportal/api/internal/account.rb', line 50

def (value)
  set_uniq_array_keep_order("login_provider_ids", value)
end

#permissions_custom=(value) ⇒ Object

It preserves the values of keys that are not defined in value.

Parameters:

  • value (Hash)

    the abilities that you want to update.



71
72
73
74
# File 'lib/ecoportal/api/internal/account.rb', line 71

def permissions_custom=(value)
  doc["permissions_custom"] ||= {}
  doc["permissions_custom"].merge!(value)
end

#policy_group_idsArray<String>

Returns the policy group ids of this user.

Returns:

  • (Array<String>)

    the policy group ids of this user.



45
46
47
# File 'lib/ecoportal/api/internal/account.rb', line 45

def policy_group_ids
  doc["policy_group_ids"] ||= []
end

#policy_group_ids=(value) ⇒ Object

Note:

it preserves the original order

Sets the policy_group_ids

Parameters:

  • value (Array<String>)

    the policy group ids to be set.



40
41
42
# File 'lib/ecoportal/api/internal/account.rb', line 40

def policy_group_ids=(value)
  set_uniq_array_keep_order("policy_group_ids", value)
end

#preferences=(value) ⇒ Object

It preserves the values of keys that are not defined in value.

Parameters:

  • value (Hash)

    the preferences that you want to update.



78
79
80
81
# File 'lib/ecoportal/api/internal/account.rb', line 78

def preferences=(value)
  doc["preferences"] ||= {}
  doc["preferences"].merge!(value)
end

#starred_idsArray<String>

Returns the starred page ids of this user.

Returns:

  • (Array<String>)

    the starred page ids of this user.



65
66
67
# File 'lib/ecoportal/api/internal/account.rb', line 65

def starred_ids
  doc["starred_ids"] ||= []
end

#starred_ids=(value) ⇒ Object

Sets the starred_ids



60
61
62
# File 'lib/ecoportal/api/internal/account.rb', line 60

def starred_ids=(value)
  set_uniq_array_keep_order("starred_ids", value)
end