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

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

Instance Attribute Summary

Attributes inherited from Common::BaseModel

#_key, #_parent

Instance Method Summary collapse

Methods inherited from Common::BaseModel

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

Methods included from Common::BaseClass

#class_resolver, #resolve_class

Constructor Details

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

Instance Method Details

#as_jsonObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/ecoportal/api/internal/account.rb', line 89

def as_json
  super.tap do |hash|
    if preset == "custom"
      hash["permissions_custom"] = permissions.as_json
    else
      hash.delete "permissions_custom"
    end
    hash["preferences"] = preferences.as_json
  end
end

#login_provider_idsArray<String>

Returns the login provider ids of this user.

Returns:

  • (Array<String>)

    the login provider ids of this user.



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

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

#login_provider_ids=(value) ⇒ Object

Sets the login_provider_ids



36
37
38
39
40
41
# File 'lib/ecoportal/api/internal/account.rb', line 36

def (value)
  unless value.is_a?(Array)
    raise "login_provider_ids= needs to be passed an Array, got #{value.class}"
  end
  doc["login_provider_ids"] = value.compact
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.



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

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.



31
32
33
# File 'lib/ecoportal/api/internal/account.rb', line 31

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.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ecoportal/api/internal/account.rb', line 18

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)
  doc["policy_group_ids"].compact
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.



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

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

#presetnil, String

Note:

basically the same as permissions_preset but when 'nil', it returns "custom" instead

Gets the permissions_preset.

Returns:

  • (nil, String)

    preset name.



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

def preset
  self.permissions_preset.nil? ? "custom" : self.permissions_preset
end

#preset=(value) ⇒ Object

Note:

basically the same as permissions_preset= but when "custom", it's changed to nil

Sets the permissions_preset.

Parameters:

  • value (nil, String)

    preset name.



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

def preset=(value)
  self.permissions_preset = value == "custom" ? nil : value
end

#starred_idsArray<String>

Returns the starred page ids of this user.

Returns:

  • (Array<String>)

    the starred page ids of this user.



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

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

#starred_ids=(value) ⇒ Object

Sets the starred_ids



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

def starred_ids=(value)
  unless value.is_a?(Array)
    raise "starred_ids= needs to be passed an Array, got #{value.class}"
  end
  doc["starred_ids"] = value.compact
end