ecoportal-api 0.10.7 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -1
- data/lib/ecoportal/api/common/base_class.rb +11 -12
- data/lib/ecoportal/api/common/base_model.rb +22 -8
- data/lib/ecoportal/api/common/batch_operation.rb +10 -10
- data/lib/ecoportal/api/common/batch_response.rb +1 -1
- data/lib/ecoportal/api/common/client/elastic_apm_integration.rb +9 -9
- data/lib/ecoportal/api/common/client/error/checks.rb +1 -1
- data/lib/ecoportal/api/common/client/with_retry.rb +1 -1
- data/lib/ecoportal/api/common/client.rb +13 -14
- data/lib/ecoportal/api/common/doc_helpers.rb +7 -6
- data/lib/ecoportal/api/common/hash_diff.rb +8 -5
- data/lib/ecoportal/api/common/logging.rb +1 -0
- data/lib/ecoportal/api/common/response.rb +1 -1
- data/lib/ecoportal/api/common/wrapped_response.rb +1 -1
- data/lib/ecoportal/api/internal/account.rb +18 -18
- data/lib/ecoportal/api/internal/people.rb +1 -1
- data/lib/ecoportal/api/internal/person.rb +24 -18
- data/lib/ecoportal/api/internal/person_details.rb +1 -1
- data/lib/ecoportal/api/internal/person_schema.rb +1 -1
- data/lib/ecoportal/api/internal/person_schemas.rb +1 -1
- data/lib/ecoportal/api/internal/policy_groups.rb +3 -2
- data/lib/ecoportal/api/internal/preferences.rb +13 -10
- data/lib/ecoportal/api/internal.rb +5 -5
- data/lib/ecoportal/api/logger.rb +8 -7
- data/lib/ecoportal/api/v1/job/awaiter/timer.rb +9 -7
- data/lib/ecoportal/api/v1/job/status.rb +2 -2
- data/lib/ecoportal/api/v1/job.rb +4 -4
- data/lib/ecoportal/api/v1/people.rb +12 -10
- data/lib/ecoportal/api/v1/person.rb +27 -15
- data/lib/ecoportal/api/v1/person_details.rb +7 -7
- data/lib/ecoportal/api/v1/person_schema.rb +5 -4
- data/lib/ecoportal/api/v1/person_schemas.rb +9 -6
- data/lib/ecoportal/api/v1/schema_field.rb +8 -8
- data/lib/ecoportal/api/v1/schema_field_value.rb +15 -15
- data/lib/ecoportal/api/v1.rb +4 -4
- data/lib/ecoportal/api/version.rb +1 -1
- data/lib/ecoportal/api.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6237e3c50a3316623f664b2f3fda405a276f893371f8ba4f194584374d9ed90f
|
4
|
+
data.tar.gz: 0f071968a7b8daf694b4553b55187d8c411beea2902e86079e0a4c39cb8b3693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67041fe9ebed8775b42189a2d4128b82653ccdb81edf22d8a8e9d66c95c771cf8c89b248cc2cb6c05e6801b3f67a6c444f0836848e17e236bf34fec0345374f0
|
7
|
+
data.tar.gz: 9fbb30e945184be0183a0280c61c7cedd8fc223806764de9dfaf000a135e37f00f9ceeab81f734e5c71e6ed101301e2c166a9392227322af468ec61408402725
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [0.10.
|
5
|
+
## [0.10.10] - 2025-03-xx
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
@@ -10,6 +10,35 @@ All notable changes to this project will be documented in this file.
|
|
10
10
|
|
11
11
|
### Fixed
|
12
12
|
|
13
|
+
## [0.10.9] - 2025-03-29
|
14
|
+
|
15
|
+
### Added
|
16
|
+
|
17
|
+
- `Ecoportal::API::V1::Person`, added usability methods:
|
18
|
+
- `#archived?`
|
19
|
+
- `archive!`
|
20
|
+
- `unarchive!`
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Substantial code tidy up
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- `Ecoportal::API::V1::PersonSchemas#each` called without block was loosing the parameters.
|
29
|
+
|
30
|
+
## [0.10.8] - 2024-12-16
|
31
|
+
|
32
|
+
### Changed
|
33
|
+
|
34
|
+
- `Ecoportal::API::Common::BaseModel` tidy up code
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
|
38
|
+
- `Ecoportal::API::V1::Job::Awaiter::Timer#time_left`
|
39
|
+
- To include `time_left_to_start` when not started.
|
40
|
+
- Remove call to `byebug`
|
41
|
+
|
13
42
|
## [0.10.7] - 2024-11-21
|
14
43
|
|
15
44
|
### Changed
|
@@ -8,25 +8,24 @@ module Ecoportal
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def class_resolver(name, klass)
|
11
|
-
define_singleton_method(name) { resolve_class(klass)
|
12
|
-
define_method(name)
|
11
|
+
define_singleton_method(name) { resolve_class(klass) }
|
12
|
+
define_method(name) { self.class.resolve_class(klass) }
|
13
13
|
end
|
14
14
|
|
15
15
|
def resolve_class(klass)
|
16
|
-
@resolved
|
16
|
+
@resolved ||= {}
|
17
17
|
@resolved[klass] ||=
|
18
18
|
case klass
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
when Class
|
20
|
+
klass
|
21
|
+
when String
|
22
|
+
Kernel.const_get(klass)
|
23
|
+
when Symbol
|
24
|
+
resolve_class(send(klass))
|
25
|
+
else
|
26
|
+
raise "Unknown class: #{klass}"
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -4,7 +4,7 @@ module Ecoportal
|
|
4
4
|
module Common
|
5
5
|
class BaseModel
|
6
6
|
class UnlinkedModel < StandardError
|
7
|
-
def initialize(msg =
|
7
|
+
def initialize(msg = 'Something went wrong when linking the document.', from: nil, key: nil)
|
8
8
|
msg << " From: #{from}." if from
|
9
9
|
msg << " key: #{key}." if key
|
10
10
|
super(msg)
|
@@ -17,9 +17,11 @@ module Ecoportal
|
|
17
17
|
def passthrough(*methods, to: :doc)
|
18
18
|
methods.each do |method|
|
19
19
|
method = method.to_s
|
20
|
+
|
20
21
|
define_method method do
|
21
22
|
send(to)[method]
|
22
23
|
end
|
24
|
+
|
23
25
|
define_method "#{method}=" do |value|
|
24
26
|
send(to)[method] = value
|
25
27
|
end
|
@@ -36,6 +38,7 @@ module Ecoportal
|
|
36
38
|
value = instance_variable_get(var)
|
37
39
|
return value unless nullable
|
38
40
|
return value if (value && doc[key]) || (!value && !doc[key])
|
41
|
+
|
39
42
|
remove_instance_variable(var)
|
40
43
|
end
|
41
44
|
|
@@ -44,8 +47,12 @@ module Ecoportal
|
|
44
47
|
return instance_variable_set(var, nil) unless doc[key]
|
45
48
|
|
46
49
|
self.class.resolve_class(klass).new(
|
47
|
-
doc[key],
|
48
|
-
|
50
|
+
doc[key],
|
51
|
+
parent: self,
|
52
|
+
key: key
|
53
|
+
).tap do |obj|
|
54
|
+
instance_variable_set(var, obj)
|
55
|
+
end
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
@@ -119,12 +126,16 @@ module Ecoportal
|
|
119
126
|
end
|
120
127
|
|
121
128
|
def dirty?
|
122
|
-
|
129
|
+
return false unless (json = as_update)
|
130
|
+
return false unless json.is_a?(Hash)
|
131
|
+
|
132
|
+
!json.empty?
|
123
133
|
end
|
124
134
|
|
125
135
|
# It consolidates all the changes carried by `doc` by setting it as `original_doc`.
|
126
136
|
def consolidate!
|
127
|
-
|
137
|
+
err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
|
138
|
+
raise err unless linked?
|
128
139
|
|
129
140
|
new_doc = JSON.parse(doc.to_json)
|
130
141
|
if is_root?
|
@@ -137,13 +148,15 @@ module Ecoportal
|
|
137
148
|
# It removes all the changes carried by `doc` by restoring `original_doc` into `doc`.
|
138
149
|
# @note
|
139
150
|
# 1. When there are nullable properties, it may be required to apply `reset!` from the parent
|
140
|
-
# i.e. `parent.reset!(
|
151
|
+
# i.e. `parent.reset!('child')` # when parent.child is `nil`
|
141
152
|
# 2. In such a case, only immediate childs are allowed to be reset
|
142
153
|
# @param key [String, Array<String>, nil] if given, it only resets the specified property
|
143
|
-
def reset!(key = nil) # rubocop:disable Metrics/AbcSize
|
154
|
+
def reset!(key = nil) # rubocop:disable Metrics/AbcSize
|
144
155
|
msg = "'key' should be a String. Given #{key}"
|
145
156
|
raise ArgumentError, msg unless !key || key.is_a?(String)
|
146
|
-
|
157
|
+
|
158
|
+
err = UnlinkedModel.new(from: "#{self.class}##{__method__}", key: _key)
|
159
|
+
raise err unless linked?
|
147
160
|
|
148
161
|
if key
|
149
162
|
if respond_to?(key) && (child = send(key)) && child.is_a?(Ecoportal::API::Common::BaseModel)
|
@@ -156,6 +169,7 @@ module Ecoportal
|
|
156
169
|
end
|
157
170
|
else
|
158
171
|
new_doc = JSON.parse(original_doc.to_json)
|
172
|
+
|
159
173
|
if is_root?
|
160
174
|
@doc = new_doc
|
161
175
|
else
|
@@ -26,20 +26,20 @@ module Ecoportal
|
|
26
26
|
|
27
27
|
def process_response(response)
|
28
28
|
unless response.success?
|
29
|
-
msg =
|
29
|
+
msg = 'Error: total failure in batch operation.'
|
30
30
|
log(:debug) { msg }
|
31
31
|
raise msg
|
32
32
|
end
|
33
33
|
|
34
|
-
log(:debug) {
|
34
|
+
log(:debug) { 'Processing batch responses' } if deep_logging?
|
35
35
|
|
36
36
|
body_data(response.body).each.with_index do |subresponse, idx|
|
37
|
-
status = subresponse[
|
37
|
+
status = subresponse['status']
|
38
38
|
method = @operations[idx][:method]
|
39
|
-
body = subresponse[
|
39
|
+
body = subresponse['response']
|
40
40
|
callback = @operations[idx][:callback]
|
41
41
|
|
42
|
-
if status == 200 && method ==
|
42
|
+
if status == 200 && method == 'GET'
|
43
43
|
batch_response = BatchResponse.new(status, body, @wrapper.new(body))
|
44
44
|
log_batch_response(@operations[idx], batch_response)
|
45
45
|
|
@@ -57,7 +57,7 @@ module Ecoportal
|
|
57
57
|
id = get_id(doc)
|
58
58
|
@operations << {
|
59
59
|
path: "#{@base_path}/#{CGI.escape(id)}",
|
60
|
-
method:
|
60
|
+
method: 'GET',
|
61
61
|
callback: block
|
62
62
|
}
|
63
63
|
end
|
@@ -67,7 +67,7 @@ module Ecoportal
|
|
67
67
|
body = get_body(doc)
|
68
68
|
@operations << {
|
69
69
|
path: "#{@base_path}/#{CGI.escape(id)}",
|
70
|
-
method:
|
70
|
+
method: 'PATCH',
|
71
71
|
body: body,
|
72
72
|
callback: block
|
73
73
|
}
|
@@ -78,7 +78,7 @@ module Ecoportal
|
|
78
78
|
body = get_body(doc)
|
79
79
|
@operations << {
|
80
80
|
path: "#{@base_path}/#{CGI.escape(id)}",
|
81
|
-
method:
|
81
|
+
method: 'POST',
|
82
82
|
body: body,
|
83
83
|
callback: block
|
84
84
|
}
|
@@ -88,7 +88,7 @@ module Ecoportal
|
|
88
88
|
id = get_id(doc)
|
89
89
|
@operations << {
|
90
90
|
path: "#{@base_path}/#{CGI.escape(id)}",
|
91
|
-
method:
|
91
|
+
method: 'DELETE',
|
92
92
|
callback: block
|
93
93
|
}
|
94
94
|
end
|
@@ -97,7 +97,7 @@ module Ecoportal
|
|
97
97
|
body = get_body(doc)
|
98
98
|
@operations << {
|
99
99
|
path: @base_path,
|
100
|
-
method:
|
100
|
+
method: 'POST',
|
101
101
|
body: body,
|
102
102
|
callback: block
|
103
103
|
}
|
@@ -31,13 +31,13 @@ module Ecoportal
|
|
31
31
|
close_elastic_apm = proc do |_id|
|
32
32
|
next unless ElasticAPM.running?
|
33
33
|
|
34
|
-
puts
|
34
|
+
puts 'Stopping ElasticAPM service'
|
35
35
|
ElasticAPM.stop
|
36
36
|
rescue StandardError
|
37
37
|
# Silent
|
38
38
|
end
|
39
39
|
|
40
|
-
ObjectSpace.define_finalizer(
|
40
|
+
ObjectSpace.define_finalizer('ElasticAPM', close_elastic_apm)
|
41
41
|
|
42
42
|
def elastic_apm_service
|
43
43
|
return false if @disable_apm
|
@@ -57,19 +57,19 @@ module Ecoportal
|
|
57
57
|
# http_compression: false,
|
58
58
|
transaction_sample_rate: 0.1,
|
59
59
|
transaction_max_spans: 100,
|
60
|
-
span_frames_min_duration:
|
60
|
+
span_frames_min_duration: '5ms'
|
61
61
|
}.tap do |options|
|
62
62
|
# next unless false
|
63
63
|
|
64
64
|
# options.merge!({
|
65
65
|
# log_level: ::Logger::DEBUG,
|
66
|
-
# log_path: File.join('log',
|
66
|
+
# log_path: File.join('log', 'elastic_apm.log')
|
67
67
|
# })
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
def elastic_apm_url
|
72
|
-
@elastic_apm_url ||=
|
72
|
+
@elastic_apm_url ||= 'https://'.tap do |url|
|
73
73
|
url << elastic_apm_account_id.to_s
|
74
74
|
url << ".#{elastic_apm_base_url}"
|
75
75
|
url << ":#{elastic_apm_port}"
|
@@ -89,17 +89,17 @@ module Ecoportal
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def elastic_apm_region
|
92
|
-
@elastic_apm_region ||= ENV['ELASTIC_APM_REGION'] ||
|
92
|
+
@elastic_apm_region ||= ENV['ELASTIC_APM_REGION'] || 'ap-southeast-2'
|
93
93
|
end
|
94
94
|
|
95
95
|
def elastic_apm_port
|
96
|
-
@elastic_apm_port ||= ENV['ELASTIC_APM_PORT'] ||
|
96
|
+
@elastic_apm_port ||= ENV['ELASTIC_APM_PORT'] || '443'
|
97
97
|
end
|
98
98
|
|
99
99
|
def environment
|
100
|
-
@environment ||=
|
100
|
+
@environment ||= 'unknown'.tap do |value|
|
101
101
|
next unless instance_variable_defined?(:@host)
|
102
|
-
next unless (env = @host.gsub(
|
102
|
+
next unless (env = @host.gsub('.ecoportal.com', ''))
|
103
103
|
|
104
104
|
value.clear << env
|
105
105
|
end
|
@@ -40,7 +40,7 @@ module Ecoportal
|
|
40
40
|
return response unless some_unexpected_error?(response)
|
41
41
|
|
42
42
|
# handle server errors (5xx) & server bugs (i.e. empty body)
|
43
|
-
msg =
|
43
|
+
msg = 're-attempting (remaining: '
|
44
44
|
msg << "#{remaining} attempts out of #{attempts})"
|
45
45
|
log(:debug) { msg }
|
46
46
|
|
@@ -61,8 +61,7 @@ module Ecoportal
|
|
61
61
|
return unless @api_key.nil? || @api_key.match(/\A\W*\z/)
|
62
62
|
return unless version
|
63
63
|
|
64
|
-
|
65
|
-
log(:error) { "Api-key missing!" }
|
64
|
+
log(:error) { 'Api-key missing!' }
|
66
65
|
end
|
67
66
|
|
68
67
|
# Sends an http `GET` request against the api version using `path` to complete the base url,
|
@@ -74,7 +73,7 @@ module Ecoportal
|
|
74
73
|
# @option params [String] :q some text to search. Omit this parameter to target all the entries.
|
75
74
|
# @return [Common::Reponse] the basic custom response object.
|
76
75
|
def get(path, params: {})
|
77
|
-
instrument(
|
76
|
+
instrument('GET', path, params) do
|
78
77
|
request do |http|
|
79
78
|
http.get(url_for(path), params: params)
|
80
79
|
end
|
@@ -88,7 +87,7 @@ module Ecoportal
|
|
88
87
|
# @param data [String] the body of the query in json format.
|
89
88
|
# @return [Common::Reponse] the basic custom response object.
|
90
89
|
def post(path, data:)
|
91
|
-
instrument(
|
90
|
+
instrument('POST', path, data) do
|
92
91
|
request do |http|
|
93
92
|
http.post(url_for(path), json: data)
|
94
93
|
end
|
@@ -102,7 +101,7 @@ module Ecoportal
|
|
102
101
|
# @param data [String] the body of the query in json format.
|
103
102
|
# @return [Common::Reponse] the basic custom response object.
|
104
103
|
def patch(path, data:)
|
105
|
-
instrument(
|
104
|
+
instrument('PATCH', path, data) do
|
106
105
|
request do |http|
|
107
106
|
http.patch(url_for(path), json: data)
|
108
107
|
end
|
@@ -113,7 +112,7 @@ module Ecoportal
|
|
113
112
|
# @param path [String] the tail that completes the url of the request.
|
114
113
|
# @return [Common::Reponse] the basic custom response object.
|
115
114
|
def delete(path)
|
116
|
-
instrument(
|
115
|
+
instrument('DELETE', path) do
|
117
116
|
request do |http|
|
118
117
|
http.delete(url_for(path))
|
119
118
|
end
|
@@ -144,10 +143,10 @@ module Ecoportal
|
|
144
143
|
def base_request
|
145
144
|
@base_request ||=
|
146
145
|
case @version
|
147
|
-
when
|
148
|
-
HTTP.headers(
|
146
|
+
when 'v2'
|
147
|
+
HTTP.headers('X-ECOPORTAL-API-KEY' => @api_key).accept(:json)
|
149
148
|
else
|
150
|
-
HTTP.headers(
|
149
|
+
HTTP.headers('X-ApiKey' => @api_key).accept(:json)
|
151
150
|
end
|
152
151
|
end
|
153
152
|
|
@@ -161,7 +160,7 @@ module Ecoportal
|
|
161
160
|
private
|
162
161
|
|
163
162
|
def instrument(method, path, data = nil, &block)
|
164
|
-
raise
|
163
|
+
raise 'Expected block' unless block_given?
|
165
164
|
|
166
165
|
start_time = Time.now.to_f
|
167
166
|
|
@@ -193,10 +192,10 @@ module Ecoportal
|
|
193
192
|
|
194
193
|
# Logger interface.
|
195
194
|
# @example:
|
196
|
-
# log(:info) {
|
197
|
-
# log(:warn) {
|
198
|
-
# log(:error) {
|
199
|
-
# log(:fatal) {
|
195
|
+
# log(:info) {'General information on what's going on'}
|
196
|
+
# log(:warn) {'This is a warning that something is likely to have gone amiss'}
|
197
|
+
# log(:error) {'Something went wrong'}
|
198
|
+
# log(:fatal) {'An unrecoverable error has happend'}
|
200
199
|
# @param level [Symbol] the level that the message should be logged.
|
201
200
|
# @yield [] generates the message.
|
202
201
|
# @yieldreturn [String] the generated message.
|
@@ -14,12 +14,13 @@ module Ecoportal
|
|
14
14
|
|
15
15
|
def get_id(doc)
|
16
16
|
id = nil
|
17
|
-
id ||= doc.id
|
18
|
-
id ||= doc.external_id
|
19
|
-
id ||= doc[
|
20
|
-
id ||= doc[
|
21
|
-
id ||= doc
|
22
|
-
|
17
|
+
id ||= doc.id if doc.respond_to?(:id)
|
18
|
+
id ||= doc.external_id if doc.respond_to?(:external_id)
|
19
|
+
id ||= doc['id'] if doc.is_a?(Hash)
|
20
|
+
id ||= doc['external_id'] if doc.is_a?(Hash)
|
21
|
+
id ||= doc if doc.is_a?(String)
|
22
|
+
|
23
|
+
id or raise 'No ID has been given!'
|
23
24
|
id
|
24
25
|
end
|
25
26
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
+
# rubocop:disable Naming/MethodParameterName
|
1
2
|
module Ecoportal
|
2
3
|
module API
|
3
4
|
module Common
|
4
5
|
module HashDiff
|
5
|
-
ID_KEYS = %w[id]
|
6
|
+
ID_KEYS = %w[id].freeze
|
6
7
|
|
7
8
|
class << self
|
8
|
-
|
9
9
|
def diff(a, b, ignore: [])
|
10
10
|
case a
|
11
11
|
when Hash
|
@@ -14,16 +14,17 @@ module Ecoportal
|
|
14
14
|
b_value = b && b[key]
|
15
15
|
no_changes = (a_value == b_value) || ignore.include?(key)
|
16
16
|
next if !ID_KEYS.include?(key) && no_changes
|
17
|
+
|
17
18
|
diffed[key] = diff(a_value, b_value, ignore: ignore)
|
18
19
|
diffed.delete(key) if diffed[key] == {}
|
19
20
|
end
|
21
|
+
|
20
22
|
# All keys are IDs, so it's actually blank
|
21
|
-
if (diffed.keys - ID_KEYS).empty?
|
22
|
-
return {}
|
23
|
-
end
|
23
|
+
return {} if (diffed.keys - ID_KEYS).empty?
|
24
24
|
end
|
25
25
|
when Array
|
26
26
|
return a unless b.is_a?(Array) && a.length == b.length
|
27
|
+
|
27
28
|
a.map.with_index do |a_value, idx|
|
28
29
|
b_value = b[idx]
|
29
30
|
diff(a_value, b_value, ignore: ignore)
|
@@ -39,3 +40,5 @@ module Ecoportal
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
43
|
+
|
44
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -11,11 +11,11 @@ module Ecoportal
|
|
11
11
|
|
12
12
|
passthrough(*PROPERTIES.map(&:to_sym))
|
13
13
|
|
14
|
-
class_resolver :preferences_class,
|
15
|
-
class_resolver :permissions_class,
|
14
|
+
class_resolver :preferences_class, 'Ecoportal::API::Internal::Preferences'
|
15
|
+
class_resolver :permissions_class, 'Ecoportal::API::Internal::Permissions'
|
16
16
|
|
17
|
-
embeds_one :permissions, key:
|
18
|
-
embeds_one :perms_merged, key:
|
17
|
+
embeds_one :permissions, key: 'permissions_custom', klass: :permissions_class
|
18
|
+
embeds_one :perms_merged, key: 'permissions_merged', klass: :permissions_class
|
19
19
|
embeds_one :preferences, klass: :preferences_class
|
20
20
|
|
21
21
|
# Sets the `default_tag` of the user
|
@@ -32,60 +32,60 @@ module Ecoportal
|
|
32
32
|
end
|
33
33
|
value = value.upcase
|
34
34
|
end
|
35
|
-
doc[
|
35
|
+
doc['default_tag'] = value
|
36
36
|
end
|
37
37
|
|
38
38
|
# Sets the `policy_group_ids`
|
39
39
|
# @note it preserves the original order
|
40
40
|
# @param value [Array<String>] the policy group ids to be set.
|
41
41
|
def policy_group_ids=(value)
|
42
|
-
set_uniq_array_keep_order(
|
42
|
+
set_uniq_array_keep_order('policy_group_ids', value)
|
43
43
|
end
|
44
44
|
|
45
45
|
# @return [Array<String>] the policy group ids of this user.
|
46
46
|
def policy_group_ids
|
47
|
-
doc[
|
47
|
+
doc['policy_group_ids'] ||= []
|
48
48
|
end
|
49
49
|
|
50
50
|
# Sets the `login_provider_ids`
|
51
51
|
def login_provider_ids=(value)
|
52
|
-
set_uniq_array_keep_order(
|
52
|
+
set_uniq_array_keep_order('login_provider_ids', value)
|
53
53
|
end
|
54
54
|
|
55
55
|
# @return [Array<String>] the login provider ids of this user.
|
56
56
|
def login_provider_ids
|
57
|
-
doc[
|
57
|
+
doc['login_provider_ids'] ||= []
|
58
58
|
end
|
59
59
|
|
60
60
|
# Sets the `starred_ids`
|
61
61
|
def starred_ids=(value)
|
62
|
-
set_uniq_array_keep_order(
|
62
|
+
set_uniq_array_keep_order('starred_ids', value)
|
63
63
|
end
|
64
64
|
|
65
65
|
# @return [Array<String>] the starred page ids of this user.
|
66
66
|
def starred_ids
|
67
|
-
doc[
|
67
|
+
doc['starred_ids'] ||= []
|
68
68
|
end
|
69
69
|
|
70
70
|
# It preserves the values of keys that are not defined in `value`.
|
71
71
|
# @param value [Hash] the abilities that you want to update.
|
72
72
|
def permissions_custom=(value)
|
73
|
-
doc[
|
74
|
-
doc[
|
73
|
+
doc['permissions_custom'] ||= {}
|
74
|
+
doc['permissions_custom'].merge!(value)
|
75
75
|
end
|
76
76
|
|
77
77
|
# It preserves the values of keys that are not defined in `value`.
|
78
78
|
# @param value [Hash] the preferences that you want to update.
|
79
79
|
def preferences=(value)
|
80
|
-
doc[
|
81
|
-
doc[
|
80
|
+
doc['preferences'] ||= {}
|
81
|
+
doc['preferences'].merge!(value)
|
82
82
|
end
|
83
83
|
|
84
84
|
def as_json
|
85
85
|
super.tap do |hash|
|
86
|
-
hash[
|
87
|
-
hash[
|
88
|
-
hash[
|
86
|
+
hash['permissions_custom'] = permissions.as_json
|
87
|
+
hash['permissions_merged'] = perms_merged.as_json
|
88
|
+
hash['preferences'] = preferences.as_json
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|