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, #pretty_print, #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



72
73
74
75
76
77
78
79
80
81
# File 'lib/ecoportal/api/internal/account.rb', line 72

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.



35
36
37
# File 'lib/ecoportal/api/internal/account.rb', line 35

def 
  doc["login_provider_ids"] ||= []
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.



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

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.



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

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
# 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)
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.



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

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.



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

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.



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

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.



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

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