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

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

Constant Summary collapse

PROPERTIES =
%w[
  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
].freeze

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



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

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



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

def as_update(ref = :last, ignore: [])
  super(ref, ignore: ignore | %w[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



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

def default_tag=(value)
  unless !value || value.is_a?(String)
    raise ArgumentError, "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, "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.



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

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

#login_provider_ids=(value) ⇒ Object

Sets the login_provider_ids



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

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.



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

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.



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

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.



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

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.



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

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.



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

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

#starred_ids=(value) ⇒ Object

Sets the starred_ids



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

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