eco-helpers 1.5.14 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -1
- data/eco-helpers.gemspec +31 -29
- data/lib/eco/api.rb +1 -1
- data/lib/eco/api/common/class_helpers.rb +45 -1
- data/lib/eco/api/common/loaders/error_handler.rb +2 -0
- data/lib/eco/api/common/loaders/parser.rb +4 -0
- data/lib/eco/api/common/loaders/use_case.rb +2 -0
- data/lib/eco/api/common/people/person_parser.rb +10 -3
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +9 -0
- data/lib/eco/api/microcases/people_cache.rb +7 -0
- data/lib/eco/api/microcases/people_load.rb +29 -21
- data/lib/eco/api/microcases/people_refresh.rb +6 -0
- data/lib/eco/api/microcases/people_search.rb +33 -8
- data/lib/eco/api/policies/default_policies/99_user_access_policy.rb +16 -28
- data/lib/eco/api/session/batch.rb +0 -3
- data/lib/eco/api/session/config/workflow.rb +1 -0
- data/lib/eco/api/usecases.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples.rb +11 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_update_case.rb +131 -0
- data/lib/eco/version.rb +1 -1
- metadata +38 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caef8b4ee689f202db51c1be9ea77c1c2e3b21cf16dcaebdf7fd838a260b5e26
|
4
|
+
data.tar.gz: ad27f525af9bceff0342e5676f898a9da1dbb486c6aad796f2bb3646ccf5cb68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4780834f301910259cb8958c1277de1972ac710f59f7803d34ed2263dc777c18a7a2503e3d6b36879b131b2625b657832a78a27471b690a5d9da8025d381df9f
|
7
|
+
data.tar.gz: 28b74a9f5d8fe22aadb053fbed4af2e35e4700a04e87fbfc201bd2336521f04814e25c0cbac7f48426172f4b21a05f8b4e4b551eaaffd4067c49609fce0dac92
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,66 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
-
## [
|
4
|
+
## [2.0.5] - 2021-02-24
|
5
|
+
|
6
|
+
### Added
|
7
|
+
### Changed
|
8
|
+
### Fixed
|
9
|
+
- `Eco::API::Common::People::PersonParser#symbol_keys` to use `Array#select`
|
10
|
+
- as `Array#filter` was introduced in ruby `2.5.5`
|
11
|
+
|
12
|
+
## [2.0.4] - 2021-02-23
|
13
|
+
|
14
|
+
### Added
|
15
|
+
### Changed
|
16
|
+
- `Eco::API::Common::People::PersonParser#defined_attrs` to include virtual attributes
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
|
20
|
+
## [2.0.3] - 2021-02-23
|
21
|
+
|
22
|
+
### Added
|
23
|
+
- `Eco::API::UseCases::OozeSamples::OozeUpdateCase`: added integration to update page instances (non-templates)
|
24
|
+
|
25
|
+
### Changed
|
26
|
+
### Fixed
|
27
|
+
- `Eco::API::Policies::DefaultPolicies::UserAccess` complete default policy code.
|
28
|
+
|
29
|
+
## [2.0.2] - 2021-02-22
|
30
|
+
|
31
|
+
### Added
|
32
|
+
### Changed
|
33
|
+
- upgraded dependencies with `ecoportal-api`
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
|
37
|
+
|
38
|
+
## [2.0.1] - 2021-02-22
|
39
|
+
|
40
|
+
### Added
|
41
|
+
### Changed
|
42
|
+
- upgraded dependencies with `ecoportal-api-oozes` to `ecoportal-api-v2`
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
|
46
|
+
## [1.5.15] - 2021-02-17
|
47
|
+
|
48
|
+
### Added
|
49
|
+
- `Eco::API::Common::ClassHelpers` added support for class methods inheritance
|
50
|
+
- this is key to be able to define usecase models to inherit from
|
51
|
+
- `Eco::API::UseCases::OozeSamples::OozeUpdateCase`: added this sample to inherit from (simplifying use cases code)
|
52
|
+
- `Eco::API::Common::ClassHelpers` added inheritable attribute values
|
53
|
+
- added benchmarking to people loaders:
|
54
|
+
- `Eco::API::MicroCases#people_load`
|
55
|
+
- `Eco::API::MicroCases#people_cache`
|
56
|
+
- `Eco::API::MicroCases#people_search`
|
57
|
+
- `Eco::API::MicroCases#refresh`
|
58
|
+
|
59
|
+
### Changed
|
60
|
+
### Fixed
|
61
|
+
- `Eco::API::Policies::DefaultPolicies::UserAccess` typos in default api policy
|
62
|
+
|
63
|
+
## [1.5.14] - 2021-02-05
|
5
64
|
|
6
65
|
### Added
|
7
66
|
- `Eco::API::Policies::DefaultPolicies` policies that are run always (after the custom policies)
|
data/eco-helpers.gemspec
CHANGED
@@ -3,37 +3,39 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
require "./lib/eco/version"
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eco-helpers"
|
8
|
+
spec.version = Eco::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Oscar Segura"]
|
11
|
+
spec.email = ["oscar@ecoportal.co.nz"]
|
12
|
+
spec.date = %q{2018-09-05}
|
13
|
+
spec.summary = %q{eco-helpers to manage people api cases}
|
14
|
+
spec.homepage = "https://www.ecoportal.com"
|
15
|
+
spec.licenses = %w[MIT]
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.4.4'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
20
|
f.match(%r{^(test|spec|features)/})
|
20
21
|
end
|
21
22
|
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
23
|
+
#spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
#spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", ">= 2.2.11", "< 2.3"
|
28
|
+
spec.add_development_dependency "rspec", ">= 3.10.0", "< 3.11"
|
29
|
+
spec.add_development_dependency "rake", ">= 13.0.3", "< 13.1"
|
30
|
+
spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
|
31
|
+
spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
|
32
|
+
|
33
|
+
spec.add_dependency 'ecoportal-api', '>= 0.8.1', '< 0.9'
|
34
|
+
#spec.add_dependency 'ecoportal-api', '>= 0.7.5', '< 0.8'
|
35
|
+
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.3', '< 0.9'
|
36
|
+
spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
|
37
|
+
spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
|
38
|
+
spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
|
39
|
+
spec.add_dependency 'net-sftp', '>= 3.0.0', '< 3.1'
|
38
40
|
|
39
41
|
end
|
data/lib/eco/api.rb
CHANGED
@@ -3,7 +3,7 @@ module Eco
|
|
3
3
|
module Common
|
4
4
|
module ClassHelpers
|
5
5
|
|
6
|
-
# Creates
|
6
|
+
# Creates a class and instance object methods with name `name` to resolve `klass` name
|
7
7
|
def class_resolver(name, klass)
|
8
8
|
define_singleton_method(name) { resolve_class(klass) }
|
9
9
|
define_method(name) { self.class.resolve_class(klass) }
|
@@ -39,6 +39,15 @@ module Eco
|
|
39
39
|
end.join("")
|
40
40
|
end
|
41
41
|
|
42
|
+
# Helper to create an instance variable `name`
|
43
|
+
# @param [String, Symbol] the name of the variable
|
44
|
+
# @reutrn [String] the name of the created instance variable
|
45
|
+
def instance_variable_name(name)
|
46
|
+
str = name.to_s
|
47
|
+
str = "@#{str}" unless str.start_with?("@")
|
48
|
+
str
|
49
|
+
end
|
50
|
+
|
42
51
|
# If the class for `name` exists, it returns it. Otherwise it generates it.
|
43
52
|
# @param name [String, Symbol] the name of the new class
|
44
53
|
# @param inherits [Class] the parent class to _inherit_ from
|
@@ -92,6 +101,41 @@ module Eco
|
|
92
101
|
descendants(parent_class: parent_class, direct: direct).length > 0
|
93
102
|
end
|
94
103
|
|
104
|
+
# Keeps track on class instance variables that should be inherited by child classes.
|
105
|
+
# @note
|
106
|
+
# - subclasses will inherit the value as is at that moment
|
107
|
+
# - any change afterwards will be only on the specific class (in line with class instance variables)
|
108
|
+
# - adapted from https://stackoverflow.com/a/10729812/4352306
|
109
|
+
# TODO: this separates the logic of the method to the instance var. Think if would be possible to join them somehow.
|
110
|
+
def inheritable_class_vars(*vars)
|
111
|
+
@inheritable_class_vars ||= [:inheritable_class_vars]
|
112
|
+
@inheritable_class_vars += vars
|
113
|
+
end
|
114
|
+
|
115
|
+
# Builds the attr_reader and attr_writer of `attrs` and registers the associated instance variable as inheritable.
|
116
|
+
def inheritable_attrs(*attrs)
|
117
|
+
attrs.each do |attr|
|
118
|
+
class_eval %(
|
119
|
+
class << self; attr_accessor :#{attr} end
|
120
|
+
)
|
121
|
+
end
|
122
|
+
inheritable_class_vars(*attrs)
|
123
|
+
end
|
124
|
+
|
125
|
+
# This callback method is called whenever a subclass of the current class is created.
|
126
|
+
# @note
|
127
|
+
# - values of the instance variables are copied as they are (no dups or clones)
|
128
|
+
# - the above means: avoid methods that change the state of the mutable object on it
|
129
|
+
# - mutating methods would reflect the changes on other classes as well
|
130
|
+
# - therefore, `freeze` will be called on the values that are inherited.
|
131
|
+
def inherited(subclass)
|
132
|
+
inheritable_class_vars.each do |var|
|
133
|
+
instance_var = instance_variable_name(var)
|
134
|
+
value = instance_variable_get(instance_var)
|
135
|
+
subclass.instance_variable_set(instance_var, value.freeze)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
95
139
|
end
|
96
140
|
end
|
97
141
|
end
|
@@ -60,6 +60,8 @@ module Eco
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
private
|
64
|
+
|
63
65
|
# Helper to obtain the current internal named attributes of the data
|
64
66
|
# @param source_data [Array<String>, Hash] if `Array` those are already the `keys`, if `Hash` it gets the `keys`
|
65
67
|
# @return [Array<String>] `keys` of `source_data`
|
@@ -76,6 +78,8 @@ module Eco
|
|
76
78
|
|
77
79
|
end
|
78
80
|
|
81
|
+
inheritable_class_vars :attribute
|
82
|
+
|
79
83
|
def initialize(person_parser)
|
80
84
|
raise "Expected Eco::API::Common::People::PersonParser. Given #{policies.class}" unless person_parser.is_a?(Eco::API::Common::People::PersonParser)
|
81
85
|
person_parser.define_attribute(self.attribute, dependencies: self.class.dependencies) do |attr_parser|
|
@@ -14,6 +14,8 @@ module Eco
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
inheritable_class_vars :type
|
18
|
+
|
17
19
|
def initialize(usecases)
|
18
20
|
raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases)
|
19
21
|
usecases.define(self.name, type: self.type, &self.method(:main))
|
@@ -99,9 +99,16 @@ module Eco
|
|
99
99
|
# - the list is sorted according `CORE_ATTRS` + `ACCOUNT_ATTRS` + schema attrs
|
100
100
|
# @return [Array<String>] list of all attribute defined parsers.
|
101
101
|
def defined_attrs
|
102
|
-
defined
|
103
|
-
defined
|
104
|
-
defined -
|
102
|
+
defined = @parsers.keys
|
103
|
+
defined = (all_attrs | defined) & defined
|
104
|
+
defined - symbol_keys
|
105
|
+
end
|
106
|
+
|
107
|
+
# Symbol keys are type or import parsers (that do not belong to the model)
|
108
|
+
# @note this was introduced to boost virtual fields to treat in different phases of the parsing process
|
109
|
+
# @return [Array<Symbol>] all the parsers defined as Symbol
|
110
|
+
def symbol_keys
|
111
|
+
@parsers.keys.select {|k| k.is_a?(Symbol)}
|
105
112
|
end
|
106
113
|
|
107
114
|
# Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
|
@@ -13,6 +13,15 @@ module Ecoportal
|
|
13
13
|
original_doc["details"] = JSON.parse(doc["details"])
|
14
14
|
end
|
15
15
|
|
16
|
+
def identify
|
17
|
+
if entry
|
18
|
+
entry.to_s(:identify)
|
19
|
+
else
|
20
|
+
str_id = id ? "id: '#{id}'; " : ""
|
21
|
+
"#{name}' (#{str_id}ext_id: '#{external_id}'; email: '#{email}')"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
@@ -6,7 +6,14 @@ module Eco
|
|
6
6
|
# @return [Eco::API::Organization::People] the `People` object with the data.
|
7
7
|
def people_cache(filename = enviro.config.people.cache)
|
8
8
|
logger.info("Going to get all the people via API")
|
9
|
+
|
10
|
+
start = Time.now
|
9
11
|
people = session.batch.get_people
|
12
|
+
secs = Time.now - start
|
13
|
+
cnt = people.count
|
14
|
+
per_sec = (cnt.to_f / secs).floor
|
15
|
+
logger.info("Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)")
|
16
|
+
|
10
17
|
file = file_manager.save_json(people, filename, :timestamp)
|
11
18
|
logger.info("#{people.length} people loaded and saved locally to #{file}.")
|
12
19
|
Eco::API::Organization::People.new(people)
|
@@ -18,27 +18,35 @@ module Eco
|
|
18
18
|
def people_load(filename = enviro.config.people.cache, modifier: [:newest, :api])
|
19
19
|
modifier = [modifier].flatten
|
20
20
|
load_file = [:file, :newest].any? {|flag| modifier.include?(flag)}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
21
|
+
case
|
22
|
+
when filename && load_file
|
23
|
+
if file = people_load_filename(filename, newest: modifier.include?(:newest))
|
24
|
+
file_manager.load_json(file).tap do |people|
|
25
|
+
logger.info("#{people&.length} people loaded from file #{file}") if people.is_a?(Array)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
logger.error("could not find the file #{file_manager.dir.file(filename)}")
|
29
|
+
exit unless modifier.include?(:api)
|
30
|
+
people_load(modifier: modifier - [:newest, :file])
|
31
|
+
end
|
32
|
+
when modifier.include?(:api)
|
33
|
+
logger.info("Going to get all the people via API")
|
34
|
+
|
35
|
+
start = Time.now
|
36
|
+
session.batch.get_people.tap do |people|
|
37
|
+
secs = Time.now - start
|
38
|
+
cnt = people.count
|
39
|
+
per_sec = (cnt.to_f / secs).floor
|
40
|
+
logger.info("Loaded #{cnt} people in #{secs} seconds (#{per_sec} people/sec)")
|
41
|
+
|
42
|
+
if modifier.include?(:save) && people && people.length > 0
|
43
|
+
file = file_manager.save_json(people, filename, :timestamp)
|
44
|
+
logger.info("#{people.length } people saved to file #{file}.")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end.yield_self do |people|
|
48
|
+
Eco::API::Organization::People.new(people)
|
49
|
+
end
|
42
50
|
end
|
43
51
|
|
44
52
|
private
|
@@ -18,7 +18,13 @@ module Eco
|
|
18
18
|
msg = "Going to refresh #{people.length} people with server data"
|
19
19
|
msg += " (including #{created} that were created)" if created > 0
|
20
20
|
logger.info(msg)
|
21
|
+
|
22
|
+
start = Time.now
|
21
23
|
entries = session.batch.get_people(people, silent: true)
|
24
|
+
secs = Time.now - start
|
25
|
+
cnt = entries.count
|
26
|
+
per_sec = (cnt.to_f / secs).floor
|
27
|
+
logger.info("Re-loaded #{cnt} people (out of #{people.length}) in #{secs} seconds (#{per_sec} people/sec)")
|
22
28
|
|
23
29
|
missing = people.length - entries.length
|
24
30
|
logger.error("Missed to obtain #{missing} people during the refresh") if missing > 0
|
@@ -11,24 +11,49 @@ module Eco
|
|
11
11
|
# @return [Eco::API::Organization::People] the `People` object with the found persons.
|
12
12
|
def people_search(data, options: {}, silent: true)
|
13
13
|
session.logger.info("Going to api get #{data.length} entries...")
|
14
|
-
|
15
|
-
|
16
|
-
session.
|
14
|
+
|
15
|
+
start = Time.now
|
16
|
+
people = session.batch.search(data, silent: silent).yield_self do |status|
|
17
|
+
secs = Time.now - start
|
18
|
+
Eco::API::Organization::People.new(status.people).tap do |people|
|
19
|
+
cnt = people.count
|
20
|
+
per_sec = (cnt.to_f / secs).floor
|
21
|
+
msg = "... could get #{cnt} people (out of #{data.length} entries) in #{secs} seconds (#{per_sec} people/sec)"
|
22
|
+
session.logger.info(msg)
|
23
|
+
end
|
24
|
+
end
|
17
25
|
|
18
26
|
# get the supervisors of found people (current supervisors)
|
19
27
|
supers = people_search_prepare_supers_request(people)
|
20
28
|
if supers.length > 0
|
21
29
|
session.logger.info(" Going to api get #{supers.length} current supervisors...")
|
22
|
-
|
23
|
-
people =
|
30
|
+
start = Time.now
|
31
|
+
people = session.batch.search(supers, silent: silent).yield_self do |status|
|
32
|
+
secs = Time.now - start
|
33
|
+
found = status.people
|
34
|
+
cnt = found.count
|
35
|
+
per_sec = (cnt.to_f / secs).floor
|
36
|
+
msg = "... could find #{cnt} current supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
37
|
+
session.logger.info(msg)
|
38
|
+
people.merge(found, strict: micro.strict_search?(options))
|
39
|
+
end
|
24
40
|
end
|
25
41
|
|
26
42
|
# get the supervisors referred in the input data (future supervisors)
|
27
43
|
supers = people_search_prepare_supers_request(data, people)
|
28
44
|
if supers.length > 0
|
29
|
-
session.logger.info(" Going to api get #{supers.length} supervisors as per entries...")
|
30
|
-
|
31
|
-
|
45
|
+
session.logger.info(" Going to api get #{supers.length} supervisors as per input entries...")
|
46
|
+
start = Time.now
|
47
|
+
|
48
|
+
people = session.batch.search(supers, silent: silent).yield_self do |status|
|
49
|
+
secs = Time.now - start
|
50
|
+
found = status.people
|
51
|
+
cnt = found.count
|
52
|
+
per_sec = (cnt.to_f / secs).floor
|
53
|
+
msg = "... could find #{cnt} input supers (out of #{supers.length}) in #{secs} seconds (#{per_sec} people/sec)"
|
54
|
+
session.logger.info(msg)
|
55
|
+
people.merge(found, strict: micro.strict_search?(options))
|
56
|
+
end
|
32
57
|
end
|
33
58
|
|
34
59
|
session.logger.info("Finally got #{people.length} people (out of #{data.length} entries)")
|
@@ -1,18 +1,18 @@
|
|
1
1
|
class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loaders::Policy
|
2
2
|
name "default-user-access"
|
3
3
|
|
4
|
-
attr_reader
|
4
|
+
attr_reader :session, :options, :job
|
5
5
|
attr_accessor :account_removed_count
|
6
6
|
|
7
7
|
def main(people, session, options, policy, job)
|
8
|
-
@session = session; @options = options
|
8
|
+
@session = session; @options = options; @job = job
|
9
9
|
|
10
10
|
self.account_removed_count = 0
|
11
11
|
|
12
12
|
people.each do |person|
|
13
|
-
remove_account_when_no_email!(person)
|
14
|
-
account.policy_group_ids =
|
15
|
-
refresh_abilities!(person
|
13
|
+
remove_account_when_no_email!(person) if person.email.to_s.empty?
|
14
|
+
person.account.policy_group_ids = defid if no_policy_group_ids?(person)
|
15
|
+
refresh_abilities!(person)
|
16
16
|
end
|
17
17
|
|
18
18
|
warn_account_removal!
|
@@ -22,14 +22,14 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
22
22
|
|
23
23
|
def warn_account_removal!
|
24
24
|
if account_removed_count > 0
|
25
|
-
msg = "Removed account to #{account_removed_count} people"
|
25
|
+
msg = "(DefaultPolicy on job '#{job.name}') Removed account to #{account_removed_count} people"
|
26
26
|
session.logger.warn(msg)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def remove_account_when_no_email!(person)
|
31
31
|
if person.account
|
32
|
-
account_removed_count += 1 if had_account?(person)
|
32
|
+
self.account_removed_count += 1 if had_account?(person)
|
33
33
|
person.account = nil
|
34
34
|
end
|
35
35
|
end
|
@@ -40,23 +40,11 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
40
40
|
return !!person.original_doc["account"]
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if no_abilities?(person)
|
50
|
-
account.permissions_custom = min_abilities
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def refresh_abilities!(account)
|
58
|
-
return nil unless account
|
59
|
-
|
43
|
+
def refresh_abilities!(person)
|
44
|
+
return nil if options.dig(:exclude, :abilities)
|
45
|
+
return nil unless account = person.account
|
46
|
+
account.permissions_custom = session.new_preset(person)
|
47
|
+
account.permissions_custom = min_abilities if no_abilities?(person)
|
60
48
|
end
|
61
49
|
|
62
50
|
def no_policy_group_ids?(person)
|
@@ -64,8 +52,8 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
64
52
|
end
|
65
53
|
|
66
54
|
def no_abilities?(person)
|
67
|
-
person.account
|
68
|
-
|
55
|
+
return true unless account = person.account
|
56
|
+
account.permissions_custom && account.permissions_custom.values.all?(&:nil?)
|
69
57
|
end
|
70
58
|
|
71
59
|
def min_abilities
|
@@ -86,14 +74,14 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
|
|
86
74
|
end
|
87
75
|
|
88
76
|
def defid
|
89
|
-
@defid ||= policy_groups.to_id(default_group)
|
77
|
+
@defid ||= policy_groups.to_id([default_group]).compact
|
90
78
|
end
|
91
79
|
|
92
80
|
def default_group
|
93
81
|
session.config.people.default_usergroup
|
94
82
|
end
|
95
83
|
|
96
|
-
def
|
84
|
+
def policy_groups
|
97
85
|
session.policy_groups
|
98
86
|
end
|
99
87
|
|
@@ -88,10 +88,7 @@ module Eco
|
|
88
88
|
|
89
89
|
def get(params: {}, silent: false)
|
90
90
|
fatal "cannot batch get without api connnection, please provide a valid api connection!" unless people_api = api&.people
|
91
|
-
|
92
91
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
93
|
-
client = people_api.client
|
94
|
-
|
95
92
|
return people_api.get_all(params: params, silent: silent)
|
96
93
|
end
|
97
94
|
|
@@ -195,6 +195,7 @@ module Eco
|
|
195
195
|
# @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
|
196
196
|
# @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
|
197
197
|
def run(key = nil, io:, &block)
|
198
|
+
raise "Missing BaseIO object" unless io.is_a?(Eco::API::UseCases::BaseIO)
|
198
199
|
begin
|
199
200
|
if key
|
200
201
|
io = stage(key).run(io: io, &block)
|
data/lib/eco/api/usecases.rb
CHANGED
@@ -0,0 +1,131 @@
|
|
1
|
+
class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::Common::Loaders::UseCase
|
2
|
+
name "single-ooze-case"
|
3
|
+
type :other
|
4
|
+
|
5
|
+
attr_reader :session, :options, :usecase
|
6
|
+
|
7
|
+
SAVE_PATCH = "ooze_patch_update.json"
|
8
|
+
|
9
|
+
def main(session, options, usecase)
|
10
|
+
@session = session; @options = options; @usecase = usecase
|
11
|
+
yield
|
12
|
+
end_script!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def end_script!
|
18
|
+
exit_if_no_changes!
|
19
|
+
backup_patch!
|
20
|
+
launch_request unless options[:simulate]
|
21
|
+
exit(0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def ooze_id
|
25
|
+
options.dig(:source, :ooze_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stage_id
|
29
|
+
options.dig(:source, :stage_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stage(id_name = stage_id)
|
33
|
+
if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
|
34
|
+
return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
|
35
|
+
if stage
|
36
|
+
new_target(stage)
|
37
|
+
logger.info("Got #{object_reference(stage)} from #{object_reference(ooze)}")
|
38
|
+
else
|
39
|
+
logger.error("Could not get stage '#{id_name}' in ooze '#{ooze_id}'")
|
40
|
+
exit(1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
raise "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
|
45
|
+
end
|
46
|
+
|
47
|
+
def ooze
|
48
|
+
@ooze ||= apiv2.pages.get(ooze_id).tap do |ooze|
|
49
|
+
if ooze
|
50
|
+
new_target(ooze)
|
51
|
+
logger.info("Got #{object_reference(ooze)}")
|
52
|
+
else
|
53
|
+
logger.error("Could not get ooze '#{ooze_id}'")
|
54
|
+
exit(1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def launch_request
|
60
|
+
prompt_to_confirm!
|
61
|
+
|
62
|
+
apiv2.pages.update(target).tap do |response|
|
63
|
+
if response.success?
|
64
|
+
logger.info("All went OK")
|
65
|
+
else
|
66
|
+
logger.error(response.body)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def exit_if_no_changes!
|
72
|
+
unless changes = !!patch_doc["page"]
|
73
|
+
logger.warn "No Changes!!"
|
74
|
+
exit(0)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def apiv2
|
79
|
+
@apiv2 ||= session.api(version: :oozes)
|
80
|
+
end
|
81
|
+
|
82
|
+
def target
|
83
|
+
@target
|
84
|
+
end
|
85
|
+
|
86
|
+
def new_target(object)
|
87
|
+
if @target && patch_doc["page"]
|
88
|
+
logger.warn "You you are switching to a new target #{object_reference(object)} after doing unsaved changes to #{object_reference(@target)}"
|
89
|
+
end
|
90
|
+
@target = object
|
91
|
+
end
|
92
|
+
|
93
|
+
def object_reference(obj)
|
94
|
+
return "No reference" unless obj
|
95
|
+
"".tap do |ref|
|
96
|
+
case obj
|
97
|
+
when Ecoportal::API::V2::Page::Stage
|
98
|
+
ref << "Stage "
|
99
|
+
when Ecoportal::API::V2::Pages::PageStage
|
100
|
+
ref << "StagePage "
|
101
|
+
when Ecoportal::API::V2::Page
|
102
|
+
ref << "Page "
|
103
|
+
end
|
104
|
+
ref << "'#{obj.name}' " if obj.respond_to?(:name)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def patch_doc
|
110
|
+
apiv2.pages.get_body(target)
|
111
|
+
end
|
112
|
+
|
113
|
+
def backup_patch!
|
114
|
+
# store the request
|
115
|
+
File.open(SAVE_PATCH, "w") do |file|
|
116
|
+
#file << (patch_doc || {}).to_json
|
117
|
+
file << JSON.pretty_generate(patch_doc || {})
|
118
|
+
end
|
119
|
+
puts "Saved patch at: #{File.expand_path(SAVE_PATCH)}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def logger
|
123
|
+
session.logger
|
124
|
+
end
|
125
|
+
|
126
|
+
def prompt_to_confirm!
|
127
|
+
print "\nDo you want to proceed (y/N)? "
|
128
|
+
exit(1) unless $stdin.gets.chomp.to_s.downcase == "y"
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -16,67 +16,67 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.11
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '2.
|
22
|
+
version: '2.3'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 2.2.11
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '2.
|
32
|
+
version: '2.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 3.10.0
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '3.11'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 3.10.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '3.11'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: rake
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 13.0.3
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '13'
|
62
|
+
version: '13.1'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 13.0.3
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '13'
|
72
|
+
version: '13.1'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: yard
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.9.
|
79
|
+
version: 0.9.26
|
80
80
|
- - "<"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.10'
|
@@ -86,7 +86,7 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.9.
|
89
|
+
version: 0.9.26
|
90
90
|
- - "<"
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0.10'
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 3.5.
|
99
|
+
version: 3.5.1
|
100
100
|
- - "<"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '3.6'
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 3.5.
|
109
|
+
version: 3.5.1
|
110
110
|
- - "<"
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '3.6'
|
@@ -116,47 +116,47 @@ dependencies:
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: 0.
|
119
|
+
version: 0.8.1
|
120
120
|
- - "<"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '0.
|
122
|
+
version: '0.9'
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 0.
|
129
|
+
version: 0.8.1
|
130
130
|
- - "<"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: '0.
|
132
|
+
version: '0.9'
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
|
-
name: ecoportal-api-
|
134
|
+
name: ecoportal-api-v2
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.
|
139
|
+
version: 0.8.3
|
140
140
|
- - "<"
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
-
version: '0.
|
142
|
+
version: '0.9'
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
145
|
version_requirements: !ruby/object:Gem::Requirement
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.
|
149
|
+
version: 0.8.3
|
150
150
|
- - "<"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '0.
|
152
|
+
version: '0.9'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: aws-sdk-s3
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.83.0
|
160
160
|
- - "<"
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '2'
|
@@ -166,7 +166,7 @@ dependencies:
|
|
166
166
|
requirements:
|
167
167
|
- - ">="
|
168
168
|
- !ruby/object:Gem::Version
|
169
|
-
version: 1.
|
169
|
+
version: 1.83.0
|
170
170
|
- - "<"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '2'
|
@@ -176,7 +176,7 @@ dependencies:
|
|
176
176
|
requirements:
|
177
177
|
- - ">="
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 1.
|
179
|
+
version: 1.36.0
|
180
180
|
- - "<"
|
181
181
|
- !ruby/object:Gem::Version
|
182
182
|
version: '2'
|
@@ -186,7 +186,7 @@ dependencies:
|
|
186
186
|
requirements:
|
187
187
|
- - ">="
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: 1.
|
189
|
+
version: 1.36.0
|
190
190
|
- - "<"
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: '2'
|
@@ -196,7 +196,7 @@ dependencies:
|
|
196
196
|
requirements:
|
197
197
|
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version: 2.7.
|
199
|
+
version: 2.7.6
|
200
200
|
- - "<"
|
201
201
|
- !ruby/object:Gem::Version
|
202
202
|
version: '2.8'
|
@@ -206,7 +206,7 @@ dependencies:
|
|
206
206
|
requirements:
|
207
207
|
- - ">="
|
208
208
|
- !ruby/object:Gem::Version
|
209
|
-
version: 2.7.
|
209
|
+
version: 2.7.6
|
210
210
|
- - "<"
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '2.8'
|
@@ -216,20 +216,20 @@ dependencies:
|
|
216
216
|
requirements:
|
217
217
|
- - ">="
|
218
218
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
219
|
+
version: 3.0.0
|
220
220
|
- - "<"
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: '
|
222
|
+
version: '3.1'
|
223
223
|
type: :runtime
|
224
224
|
prerelease: false
|
225
225
|
version_requirements: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - ">="
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
229
|
+
version: 3.0.0
|
230
230
|
- - "<"
|
231
231
|
- !ruby/object:Gem::Version
|
232
|
-
version: '
|
232
|
+
version: '3.1'
|
233
233
|
description:
|
234
234
|
email:
|
235
235
|
- oscar@ecoportal.co.nz
|
@@ -405,6 +405,8 @@ files:
|
|
405
405
|
- lib/eco/api/usecases/default_cases/update_case.rb
|
406
406
|
- lib/eco/api/usecases/default_cases/update_details_case.rb
|
407
407
|
- lib/eco/api/usecases/default_cases/upsert_case.rb
|
408
|
+
- lib/eco/api/usecases/ooze_samples.rb
|
409
|
+
- lib/eco/api/usecases/ooze_samples/ooze_update_case.rb
|
408
410
|
- lib/eco/api/usecases/use_case.rb
|
409
411
|
- lib/eco/api/usecases/use_case_chain.rb
|
410
412
|
- lib/eco/api/usecases/use_case_io.rb
|