ecoportal-api 0.5.7 → 0.7.2
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 +68 -1
- data/ecoportal-api.gemspec +1 -1
- data/lib/ecoportal/api/common/base_model.rb +11 -3
- data/lib/ecoportal/api/common/batch_response.rb +3 -3
- data/lib/ecoportal/api/common/response.rb +2 -2
- data/lib/ecoportal/api/common/wrapped_response.rb +3 -3
- data/lib/ecoportal/api/internal/account.rb +33 -1
- data/lib/ecoportal/api/internal/permissions.rb +4 -1
- data/lib/ecoportal/api/internal/preferences.rb +5 -9
- data/lib/ecoportal/api/v1/people.rb +20 -7
- data/lib/ecoportal/api/v1/person.rb +18 -3
- data/lib/ecoportal/api/version.rb +1 -1
- metadata +6 -9
- data/lib/ecoportal/api/internal/.git-keep +0 -0
- data/lib/ecoportal/api/v1/.git-keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1976e2e6000be3719f3cd7d9d0524ecdd4d005691f4c214e9ad77bbe9b33d09
|
4
|
+
data.tar.gz: 577313f39edd82846a9050ae8acbadf9f3b79ca2f1ebbedec9ee598973ff1fed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6706dcf4968d94c9e1daedff8e2325699b4da5403d758c79474a7dff618e9dd36d31d566003be66bb685fc633e0100a2c08a80ba5edd9c4d8433b2e5c56ac00f
|
7
|
+
data.tar.gz: 20004f26d098f579cc5b7269bb06eb8bf41284506b291882ff81ff7794db2612162df8f010e24a41240a82d30f6b48a48ae8e54c60375c3d5f79228f95ef76b8
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,74 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [0.
|
4
|
+
## [0.7.2] - 2020-10-30
|
5
|
+
|
6
|
+
### Added
|
7
|
+
- `Ecoportal::API::V1::Person#email=`:
|
8
|
+
- do a minimum validation (no blanks in the email)
|
9
|
+
- set in lower case (as this is how it's in the server)
|
10
|
+
### Fixed
|
11
|
+
- `Ecoportal::API::V1::People#each`: when `silent` it shouldn't print a blank line
|
12
|
+
- fixed so they return empty array `[]` when `nil`:
|
13
|
+
- `Ecoportal::API::V1::Person#filter_tags`
|
14
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids`
|
15
|
+
- `Ecoportal::API::Internal::Account#login_provider_ids`
|
16
|
+
- `Ecoportal::API::Internal::Account#starred_ids`
|
17
|
+
### Changed
|
18
|
+
- made it so some methods the `Array` with `uniq` values:
|
19
|
+
- `Ecoportal::API::V1::Person#filter_tags=`
|
20
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`
|
21
|
+
- made it so it only updates the keys defined in the `Hash` passed to the setter:
|
22
|
+
- `Ecoportal::API::Internal::Account#permissions_custom=`
|
23
|
+
- `Ecoportal::API::Internal::Account#preferences=`
|
24
|
+
|
25
|
+
|
26
|
+
## [0.7.1] - 2020-09-30
|
27
|
+
|
28
|
+
### Added
|
29
|
+
- `Ecoportal::API::Internal::Permissions`: **update for new ability `tasks` of ecoPortal release `1.5.3`**
|
30
|
+
- `Ecoportal::API::V1::People#each`: added keyword argument `silent:` to display download progress
|
31
|
+
### Fixed
|
32
|
+
- `Ecoportal::API::V1::People#each`: when no block provided, it was creating an `Enumarator` without preserving the parameters (i.e. `:q` or `per_page` were lost)
|
33
|
+
|
34
|
+
## [0.7.0] - 2020-09-11
|
35
|
+
|
36
|
+
### Added
|
37
|
+
### Changed
|
38
|
+
- `Ecoportal::API::Internal::Permissions`: **update for new abilities of ecoPortal release `1.5.2`**
|
39
|
+
- decoupled abilities: `person_core` into `person_core_create`, `person_core_edit`
|
40
|
+
### Fixed
|
41
|
+
|
42
|
+
|
43
|
+
## [0.6.0] - 2020-07-14
|
44
|
+
|
45
|
+
### Added
|
46
|
+
- `Ecoportal::API::Common::BaseModel#initial_doc`: `#consolidate!` modifies `original_doc`
|
47
|
+
- this helper allows to know what was the initial document the object was created with
|
48
|
+
- `Ecoportal::API::Common::BaseModel#as_update`: added parameter (default: `:last` => compare with `original_doc`)
|
49
|
+
- calling it with `:total` will compare the current `doc` with the `initial_doc`
|
50
|
+
### Changed
|
51
|
+
- `Ecoportal::API::Internal::Permissions`: **update for new abilities of ecoPortal release `1.5.0`**
|
52
|
+
- added abilities: `person_core`, `person_account`, `person_details`
|
53
|
+
- removed ability: `people`
|
54
|
+
- renamed `print` to `pretty_print` to avoid overriding `$stdout.print`, on:
|
55
|
+
- `Ecoportal::API::Common::BaseModel`
|
56
|
+
- `Ecoportal::API::Common::BatchReponse`
|
57
|
+
- `Ecoportal::API::Common::Response`
|
58
|
+
- `Ecoportal::API::Common::WrappedResponse`
|
59
|
+
### Fixed
|
60
|
+
- `Ecoportal::API::Internal::Preferences`: **kiosk** settings should default to `false` (`nil`)
|
61
|
+
|
62
|
+
## [0.5.8] - 2020-06-23
|
63
|
+
|
64
|
+
### Added
|
65
|
+
### Changed
|
66
|
+
### Fixed
|
67
|
+
- `Ecoportal::API::V1::Person#filter_tags=`: `original_doc["filter_tags"]` is `nil` when creating a person
|
68
|
+
- `Ecoportal::API::Internal::Account#policy_group_ids=`: `original_doc["account"]` is `nil` when creating a person
|
69
|
+
|
70
|
+
|
71
|
+
## [0.5.7] - 2020-06-22
|
5
72
|
|
6
73
|
### Added
|
7
74
|
- `Ecoportal::API::V1::PersonSchema`: added `enable_tags` & `tags` properties
|
data/ecoportal-api.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rspec", "~> 3", ">= 3.9"
|
26
26
|
spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
|
27
27
|
spec.add_development_dependency "redcarpet", "~> 3.5", ">= 3.5.0"
|
28
|
-
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "pry" , "~> 0.13"
|
29
29
|
|
30
30
|
spec.add_dependency 'http', '~> 3'
|
31
31
|
spec.add_dependency 'hash-polyfill', '~> 0'
|
@@ -48,6 +48,7 @@ module Ecoportal
|
|
48
48
|
if !_parent || !_key
|
49
49
|
@doc = doc
|
50
50
|
@original_doc = JSON.parse(@doc.to_json)
|
51
|
+
@initial_doc = JSON.parse(@doc.to_json)
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -63,6 +64,12 @@ module Ecoportal
|
|
63
64
|
_parent.original_doc.dig(*[_key].flatten)
|
64
65
|
end
|
65
66
|
|
67
|
+
def initial_doc
|
68
|
+
raise UnlinkedModel.new unless linked?
|
69
|
+
return @initial_doc if is_root?
|
70
|
+
_parent.initial_doc.dig(*[_key].flatten)
|
71
|
+
end
|
72
|
+
|
66
73
|
def as_json
|
67
74
|
doc
|
68
75
|
end
|
@@ -71,9 +78,10 @@ module Ecoportal
|
|
71
78
|
doc.to_json(*args)
|
72
79
|
end
|
73
80
|
|
74
|
-
def as_update
|
81
|
+
def as_update(ref = :last)
|
75
82
|
new_doc = as_json
|
76
|
-
|
83
|
+
ref_doc = ref == :total ? initial_doc : original_doc
|
84
|
+
Common::HashDiff.diff(new_doc, ref_doc)
|
77
85
|
end
|
78
86
|
|
79
87
|
def dirty?
|
@@ -100,7 +108,7 @@ module Ecoportal
|
|
100
108
|
end
|
101
109
|
end
|
102
110
|
|
103
|
-
def
|
111
|
+
def pretty_print
|
104
112
|
puts JSON.pretty_generate(as_json)
|
105
113
|
self
|
106
114
|
end
|
@@ -13,16 +13,34 @@ module Ecoportal
|
|
13
13
|
embeds_one :preferences, klass: :preferences_class
|
14
14
|
|
15
15
|
# Sets the `policy_group_ids`
|
16
|
+
# @note it preserves the original order
|
17
|
+
# @param value [Array<String>] the policy group ids to be set.
|
16
18
|
def policy_group_ids=(value)
|
17
19
|
unless value.is_a?(Array)
|
18
20
|
raise "policy_group_ids= needs to be passed an Array, got #{value.class}"
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
value.uniq!
|
24
|
+
ini_ids = (original_doc && original_doc["policy_group_ids"]) || []
|
22
25
|
# preserve original order to avoid false updates
|
23
26
|
doc["policy_group_ids"] = (ini_ids & value) + (value - ini_ids)
|
24
27
|
end
|
25
28
|
|
29
|
+
# @return [Array<String>] the policy group ids of this user.
|
30
|
+
def policy_group_ids
|
31
|
+
doc["policy_group_ids"] ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Array<String>] the login provider ids of this user.
|
35
|
+
def login_provider_ids
|
36
|
+
doc["login_provider_ids"] ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array<String>] the starred page ids of this user.
|
40
|
+
def starred_ids
|
41
|
+
doc["starred_ids"] ||= []
|
42
|
+
end
|
43
|
+
|
26
44
|
# Sets the `permissions_preset`.
|
27
45
|
# @note basically the same as `permissions_preset=` but when `"custom"`, it's changed to `nil`
|
28
46
|
# @param value [nil, String] preset name.
|
@@ -37,6 +55,20 @@ module Ecoportal
|
|
37
55
|
self.permissions_preset.nil? ? "custom" : self.permissions_preset
|
38
56
|
end
|
39
57
|
|
58
|
+
# It preserves the values of keys that are not defined in `value`.
|
59
|
+
# @param value [Hash] the abilities that you want to update.
|
60
|
+
def permissions_custom=(value)
|
61
|
+
doc["permissions_custom"] ||= {}
|
62
|
+
doc["permissions_custom"].merge!(value)
|
63
|
+
end
|
64
|
+
|
65
|
+
# It preserves the values of keys that are not defined in `value`.
|
66
|
+
# @param value [Hash] the preferences that you want to update.
|
67
|
+
def preferences=(value)
|
68
|
+
doc["preferences"] ||= {}
|
69
|
+
doc["preferences"].merge!(value)
|
70
|
+
end
|
71
|
+
|
40
72
|
def as_json
|
41
73
|
super.tap do |hash|
|
42
74
|
if preset == "custom"
|
@@ -2,7 +2,10 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class Internal
|
4
4
|
class Permissions < Common::BaseModel
|
5
|
-
passthrough :files, :data, :reports
|
5
|
+
passthrough :files, :data, :reports
|
6
|
+
passthrough :organization, :person_core, :person_core_create, :person_core_edit
|
7
|
+
passthrough :person_account, :person_details
|
8
|
+
passthrough :pages, :page_editor, :registers, :tasks
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
@@ -2,21 +2,17 @@ module Ecoportal
|
|
2
2
|
module API
|
3
3
|
class Internal
|
4
4
|
class Preferences < Common::BaseModel
|
5
|
+
passthrough :kiosk_enabled, :kiosk_workflow_message, :kiosk_create_button_label,
|
6
|
+
:kiosk_create_button_help, :kiosk_return_button_label, :kiosk_return_button_help,
|
7
|
+
:kiosk_dashboard_button_label, :kiosk_dashboard_button_help
|
8
|
+
|
5
9
|
[
|
6
10
|
:show_sidebar,
|
7
11
|
:show_shortcuts,
|
8
12
|
:show_coming_soon,
|
9
13
|
:show_recently_visited_forms,
|
10
14
|
:show_tasks,
|
11
|
-
:show_task_bubbles
|
12
|
-
:kiosk_enabled,
|
13
|
-
:kiosk_workflow_message,
|
14
|
-
:kiosk_create_button_label,
|
15
|
-
:kiosk_create_button_help,
|
16
|
-
:kiosk_return_button_label,
|
17
|
-
:kiosk_return_button_help,
|
18
|
-
:kiosk_dashboard_button_label,
|
19
|
-
:kiosk_dashboard_button_help
|
15
|
+
:show_task_bubbles
|
20
16
|
].map(&:to_s).each do |field|
|
21
17
|
define_method(field) do
|
22
18
|
if doc.key?(field)
|
@@ -27,15 +27,27 @@ module Ecoportal
|
|
27
27
|
# @param params [Hash]
|
28
28
|
# @option params [String] :per_page the number of people you get per request.
|
29
29
|
# @option params [String] :q some text to search. Omit this parameter to target all the people.
|
30
|
+
# @param silent [Boolean] `false` to show percentage of progress.
|
30
31
|
# @yield [person] does some stuff with the person.
|
31
32
|
# @yieldparam person [Person]
|
32
|
-
def each(params: {}, &block)
|
33
|
-
return to_enum(:each) unless block
|
34
|
-
cursor_id = nil
|
33
|
+
def each(params: {}, silent: false, &block)
|
34
|
+
return to_enum(:each, params: params, silent: silent) unless block
|
35
|
+
cursor_id = nil; results = 0
|
36
|
+
puts "\n" unless silent
|
35
37
|
loop do
|
36
38
|
params.update(cursor_id: cursor_id) if cursor_id
|
37
39
|
response = client.get("/people", params: params)
|
38
|
-
raise "Request failed." unless response.success?
|
40
|
+
raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
|
41
|
+
|
42
|
+
unless silent || (total = response.body["total_results"]) == 0
|
43
|
+
results += response.body["results"].length
|
44
|
+
percent = results * 100 / total
|
45
|
+
msg = "People GET"
|
46
|
+
msg += " (search=#{params[:q]})" if params.key?(:q)
|
47
|
+
print "#{msg}: #{percent.round}% (of #{total})\r"
|
48
|
+
$stdout.flush
|
49
|
+
end
|
50
|
+
|
39
51
|
response.body["results"].each do |person|
|
40
52
|
yield person_class.new(person)
|
41
53
|
end
|
@@ -45,13 +57,14 @@ module Ecoportal
|
|
45
57
|
end
|
46
58
|
|
47
59
|
# Gets all the people via api requests.
|
48
|
-
# @note it ignores the key `:
|
60
|
+
# @note it ignores the key `:cursor_id` in `params:`.
|
49
61
|
# @param params [Hash]
|
50
62
|
# @option params [Integer] :per_page the number of people you get per request.
|
51
63
|
# @option params [String] :q some text to search.
|
64
|
+
# @param silent [Boolean] `false` to show percentage of progress.
|
52
65
|
# @return [Array<Person>] the array of people got via api.
|
53
|
-
def get_all(params: {})
|
54
|
-
each(params: params).to_a
|
66
|
+
def get_all(params: {}, silent: false)
|
67
|
+
each(params: params, silent: silent).to_a
|
55
68
|
end
|
56
69
|
|
57
70
|
# Gets a person via api.
|
@@ -15,6 +15,7 @@ module Ecoportal
|
|
15
15
|
embeds_one :details, nullable: true, klass: :person_details_class
|
16
16
|
|
17
17
|
VALID_TAG_REGEX = /^[A-Za-z0-9 &_'\/-]+$/
|
18
|
+
VALID_EMAIL_REGEX = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
|
18
19
|
|
19
20
|
# Gets the supervisor (`Person`) of this person, with given his `supervisor_id`.
|
20
21
|
#
|
@@ -41,8 +42,17 @@ module Ecoportal
|
|
41
42
|
self.supervisor_id = person&.id || person&.external_id
|
42
43
|
end
|
43
44
|
|
45
|
+
# Sets the email of a person.
|
46
|
+
# @param email [String, nil] the email of this person.
|
47
|
+
def email=(value)
|
48
|
+
unless !value || value.match(VALID_EMAIL_REGEX)
|
49
|
+
raise "Invalid email #{email.inspect}"
|
50
|
+
end
|
51
|
+
doc["email"] = value&.downcase
|
52
|
+
end
|
53
|
+
|
44
54
|
# Validates the string tags of the array, and sets the `filter_tags` property of the account.
|
45
|
-
# @note all is set in upper case.
|
55
|
+
# @note all is set in upper case and preserves the original order.
|
46
56
|
# @raise [Exception] if there was any invalid string tag.
|
47
57
|
# @param value [Array<String>] array of tags.
|
48
58
|
def filter_tags=(value)
|
@@ -54,13 +64,18 @@ module Ecoportal
|
|
54
64
|
raise "Invalid filter tag #{tag.inspect}"
|
55
65
|
end
|
56
66
|
tag.upcase
|
57
|
-
end
|
67
|
+
end.uniq
|
58
68
|
|
59
|
-
ini_tags = original_doc["filter_tags"] || []
|
69
|
+
ini_tags = (original_doc && original_doc["filter_tags"]) || []
|
60
70
|
# preserve original order to avoid false updates
|
61
71
|
doc["filter_tags"] = (ini_tags & end_tags) + (end_tags - ini_tags)
|
62
72
|
end
|
63
73
|
|
74
|
+
# @return [Array<String>] the filter tags of this person.
|
75
|
+
def filter_tags
|
76
|
+
doc["filter_tags"] ||= []
|
77
|
+
end
|
78
|
+
|
64
79
|
def as_json
|
65
80
|
super.merge "details" => details&.as_json
|
66
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecoportal-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tapio Saarinen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,16 +108,16 @@ dependencies:
|
|
108
108
|
name: pry
|
109
109
|
requirement: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- - "
|
111
|
+
- - "~>"
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0'
|
113
|
+
version: '0.13'
|
114
114
|
type: :development
|
115
115
|
prerelease: false
|
116
116
|
version_requirements: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- - "
|
118
|
+
- - "~>"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: '0'
|
120
|
+
version: '0.13'
|
121
121
|
- !ruby/object:Gem::Dependency
|
122
122
|
name: http
|
123
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +163,6 @@ files:
|
|
163
163
|
- ".yardopts"
|
164
164
|
- CHANGELOG.md
|
165
165
|
- Gemfile
|
166
|
-
- Gemfile.lock
|
167
166
|
- LICENSE
|
168
167
|
- README.md
|
169
168
|
- Rakefile
|
@@ -183,7 +182,6 @@ files:
|
|
183
182
|
- lib/ecoportal/api/common/response.rb
|
184
183
|
- lib/ecoportal/api/common/wrapped_response.rb
|
185
184
|
- lib/ecoportal/api/internal.rb
|
186
|
-
- lib/ecoportal/api/internal/.git-keep
|
187
185
|
- lib/ecoportal/api/internal/account.rb
|
188
186
|
- lib/ecoportal/api/internal/login_provider.rb
|
189
187
|
- lib/ecoportal/api/internal/login_providers.rb
|
@@ -200,7 +198,6 @@ files:
|
|
200
198
|
- lib/ecoportal/api/internal/schema_field_value.rb
|
201
199
|
- lib/ecoportal/api/logger.rb
|
202
200
|
- lib/ecoportal/api/v1.rb
|
203
|
-
- lib/ecoportal/api/v1/.git-keep
|
204
201
|
- lib/ecoportal/api/v1/people.rb
|
205
202
|
- lib/ecoportal/api/v1/person.rb
|
206
203
|
- lib/ecoportal/api/v1/person_details.rb
|
File without changes
|
File without changes
|