eco-helpers 2.0.56 → 2.0.59

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9227a13716393bdd79a7bdf3d4729dbc2b426f43e16d1525001ffd0a2c58bb4
4
- data.tar.gz: 00adb8c5c5abc08e53e4130a1cdf9ff03cf4307ac86c4cbe8e84ebffd8ba2458
3
+ metadata.gz: aec1ba6cc48e340c576f141bec3e128afcb0fe7e072051c8a6da5a6e0fb9c3b1
4
+ data.tar.gz: a592079366217bd0ec34fbae8a659ed971cc79bdac762a26f5f36e2346f0f944
5
5
  SHA512:
6
- metadata.gz: 0c69583967b50677bf012fdd354d3fb17abf521fcceb702f71ccfbfd942fb1e11963ff50b103f351e9cbebcfd531751dc9c54094e6b645c40b0e77d5ef6c7d8b
7
- data.tar.gz: 60a0e1e311f8a3aae34bbfcf1f4c5dccf3bd541dfaef0ab60b3f7b557a69bc6b5f7a74febdea0a85aa4db658c508da69fef99753c89459db0eab58112c577bc2
6
+ metadata.gz: e612ff67ebd1148cffc40c064bdcb6e61d119c021b5b1261210699d1f1114bf5d42479822a54545f67947b6f0eee6293607a61947d5e245195cd7a60e1c5d56a
7
+ data.tar.gz: 2ff3fd08e0f4780a9f0891081357b1e3723ef341c8d038e2f3b3fa508b59349a21ea4bc30f7b71633cdabd73f8d7bd1032b189c67efd7c1316ae64b955d69e25
data/CHANGELOG.md CHANGED
@@ -1,7 +1,52 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.56] - 2022-04-xx
4
+ ## [2.0.59] - 2022-06-xx
5
+
6
+ ### Added
7
+ - `Eco::API::Organization::TagTree#leafs` new method to spot tags with no children.
8
+
9
+ ### Changed
10
+ - `Eco::API::MicroCases#core_excluded`
11
+ - when person is `new?`, you should still be able to exclude `filter_tags`
12
+
13
+ ### Fixed
14
+ - `Eco::API::Policies::DefaultPolicies::UserAccess`
15
+ - `-exclude-account` should leave it untouched
16
+
17
+ ## [2.0.58] - 2022-05-31
18
+
19
+ ### Added
20
+ - **Usecase**`Eco::API::UseCases::DefaultCases::ClearAbilitiesTransCase`
21
+ - invokable with `clear-abilities`
22
+ - `Eco::API::Session::Config::People` added
23
+ - `default_login_method` helpers
24
+ - `Eco::API::Session::Config#default_login_method=` added
25
+ - `Eco::API::Common::Loaders::Base#abort` method to log an error and raise an exception
26
+ - **patched** `Ecoportal::API::Internal::Person`
27
+ - Added a couple of handy helpers: `#replace_doc` and `#replace_original_doc`
28
+
29
+ ### Changed
30
+ - `Eco::API::Common::Session::SFTP#move` new parameter `override:` (default: `true`)
31
+ - If there was an error, it would delete the destination remote file and retry to move the file
32
+ - upgraded `ecoportal-api-v2` gem to `0.8.28`
33
+ - `Eco::API::Organization::LoginProviders#login_provider`
34
+ - Added support to fetch based on type (i.e. password, sso)
35
+ - `Eco::API::Policies::DefaultPolicies::UserAccess`
36
+ - Added support for `config.default_login_method`
37
+
38
+ ### Fixed
39
+ - `Eco::API::Common::People::EntryFactory`
40
+ - Max allowed enconding errors was not working (it was just fixing all).
41
+
42
+ ## [2.0.57] - 2022-04-29
43
+
44
+ ### Changed
45
+ - `Eco::API::UseCases::DefaultCases::HrisCase`
46
+ - Made it so the `leavers` batch runs first
47
+ - This aims to prevent some errors such as `cyclic supervisor` or `email already taken`
48
+
49
+ ## [2.0.56] - 2022-04-25
5
50
 
6
51
  ### Added
7
52
  - `Eco::API::UseCases::OozeSamples::OozeBaseCase#add_field_by_doc`
@@ -31,7 +76,6 @@ All notable changes to this project will be documented in this file.
31
76
  ### Added
32
77
  - `Eco::API::UseCases::DefaultCases::Samples::Sftp` should tell where the files went in the local.
33
78
 
34
-
35
79
  ## [2.0.53] - 2022-04-04
36
80
 
37
81
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.27', '< 0.9'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.8.28', '< 0.9'
35
35
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
36
36
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
37
37
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
@@ -51,6 +51,14 @@ module Eco
51
51
  session.micro
52
52
  end
53
53
 
54
+ def abort(msg, raising: true)
55
+ logger.error(msg)
56
+ if raising
57
+ raise msg
58
+ else
59
+ exit(1)
60
+ end
61
+ end
54
62
  end
55
63
  end
56
64
  end
@@ -11,7 +11,7 @@ class Eco::API::Common::People::DefaultParsers::BooleanParser < Eco::API::Common
11
11
 
12
12
  private
13
13
 
14
- def truthy (value)
14
+ def truthy(value)
15
15
  %w[true y yes x].include?(value.to_s.strip.downcase)
16
16
  end
17
17
 
@@ -208,6 +208,7 @@ module Eco
208
208
  logger.error("There were more than 5 encoding errors in the file '#{file}'.")
209
209
  return content
210
210
  else
211
+ tolerance -= 1
211
212
  logger.error("Encoding problem in file '#{file}': '#{replacement}'.")
212
213
  replacement
213
214
  end
@@ -56,8 +56,14 @@ module Eco
56
56
  end
57
57
 
58
58
  # @see Net::SFTP::Session#rename
59
- def move(fullname_source, fullname_dest, flags=0x0001, &callback)
60
- sftp_session.rename!(fullname_source, fullname_dest, flags, &callback)
59
+ def move(fullname_source, fullname_dest, flags=0x0001, override: true, &callback)
60
+ begin
61
+ sftp_session.rename!(fullname_source, fullname_dest, flags, &callback)
62
+ rescue Net::SFTP::StatusException => e
63
+ raise unless override
64
+ sftp_session.remove(fullname_dest)
65
+ sftp_session.rename!(fullname_source, fullname_dest, flags, &callback)
66
+ end
61
67
  end
62
68
 
63
69
  # Downloads the files specified to a local folder
@@ -14,6 +14,23 @@ module Ecoportal
14
14
  account && !ref_doc["account"]
15
15
  end
16
16
 
17
+ # It replaces `doc` by `new_doc`
18
+ # @return [Hash] `doc` before change
19
+ def replace_doc!(new_doc)
20
+ raise UnlinkedModel.new(from: "#{self.class}#replace_doc", key: _key) unless linked?
21
+ @doc.tap do
22
+ @doc = new_doc
23
+ end
24
+ end
25
+
26
+ # It replaces `original_doc` by `new_doc`
27
+ # @return [Hash] `original_doc` before change
28
+ def replace_original_doc!(new_doc)
29
+ raise UnlinkedModel.new(from: "#{self.class}#replace_original_doc", key: _key) unless linked?
30
+ @original_doc.tap do
31
+ @original_doc = new_doc
32
+ end
33
+ end
17
34
  end
18
35
  end
19
36
  end
@@ -7,12 +7,11 @@ module Eco
7
7
  # @return [Array<String>] the core parameters that should not be included.
8
8
  def core_excluded(person, options)
9
9
  ["supervisor_id"].tap do |core_excluded|
10
- unless person.new?
11
- exclusions = ["name", "external_id", "email", "filter_tags"].select do |attr|
12
- options.dig(:exclude, attr.to_sym)
13
- end
14
- core_excluded.concat(exclusions)
10
+ can_exclude = person.new?? ["filter_tags"] : ["name", "external_id", "email", "filter_tags"]
11
+ exclusions = can_exclude.select do |attr|
12
+ options.dig(:exclude, attr.to_sym)
15
13
  end
14
+ core_excluded.concat(exclusions)
16
15
  end
17
16
  end
18
17
  end
@@ -3,7 +3,7 @@ module Eco
3
3
  class MicroCases
4
4
  # Unique access point to set the `supervisor_id` value on a person.
5
5
  # @note
6
- # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of hemselves)
6
+ # - It prevents the basic cyclic supervisor case (supervisor to be supervisor of themselves)
7
7
  # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
8
8
  # @param sup_id [nil, String] the **supervisor id** we should set on the `person`.
9
9
  # @param people [Eco::API::Organization::People] _People_ involved in the current update.
@@ -56,27 +56,41 @@ module Eco
56
56
  end
57
57
  end
58
58
 
59
- def login_provider(id_name)
60
- @by_id.fetch(login_provider_id(id_name), nil)
59
+ # @param id_name_type [String, Symbol]
60
+ # - `String` to refer to the login provider `name` or `id`
61
+ # - `Symbol` to refer to the login providr type (i.e. `:password`, `:sso`)
62
+ def login_provider(id_name_type)
63
+ @by_id[login_provider_id(id_name_type)]
61
64
  end
62
65
 
63
66
  private
64
67
 
65
- def login_provider_name(id_name)
66
- (@by_id[id_name] || @by_name[id_name&.downcase])&.name&.downcase
67
- end
68
-
69
- def login_provider_id(id_name)
70
- (@by_name[id_name&.downcase] || @by_id[id_name])&.id
68
+ def login_provider_id(value)
69
+ case value
70
+ when Symbol
71
+ value = value.to_s.downcase.to_sym
72
+ @by_type[value]&.id
73
+ when String
74
+ value = value.strip.downcase
75
+ @by_name[value]&.id || @by_id[value]&.id
76
+ end
71
77
  end
72
78
 
73
79
  def init_caches
74
80
  return if @caches_init
75
- @by_id = self.map { |pg| [pg.id, pg] }.to_h
76
- @by_name = self.map { |pg| [pg.name&.downcase, pg] }.to_h
81
+ enabled_lps = self.select {|lp| lp.enabled_for != "disabled"}
82
+ @by_id = enabled_lps.each_with_object({}) do |lp, hash|
83
+ hash[lp.id.downcase] = lp
84
+ end
85
+ @by_name = enabled_lps.each_with_object({}) do |lp, hash|
86
+ hash[lp.name.downcase] = lp
87
+ end
88
+ @by_type = enabled_lps.each_with_object({}) do |lp, hash|
89
+ hash[lp.type.downcase.to_sym] = lp
90
+ hash[:sso] = lp if (!hash.key?(:sso) && lp.type == "saml")
91
+ end
77
92
  @caches_init = true
78
93
  end
79
-
80
94
  end
81
95
  end
82
96
  end
@@ -124,6 +124,14 @@ module Eco
124
124
  subtags.include?(key&.upcase)
125
125
  end
126
126
 
127
+ # Returns all the tags with no children
128
+ # @return [Array<String>]
129
+ def leafs
130
+ tags.select do |tag|
131
+ node(tag).children_count == 0
132
+ end
133
+ end
134
+
127
135
  # Verifies if a tag exists in the tree.
128
136
  # @param key [String] tag to verify.
129
137
  # @return [Boolean]
@@ -1,3 +1,7 @@
1
+ # Default policy:
2
+ # 1. Removes the account if the email is empty
3
+ # 2. Adds the defined default_usergroup if user does not have policy groups
4
+ # 3. Adds the defined default_login_method if update includes empty login methods
1
5
  class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loaders::Policy
2
6
  name "default-user-access"
3
7
 
@@ -10,8 +14,13 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
10
14
  self.account_removed_count = 0
11
15
 
12
16
  people.each do |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)
17
+ remove_account_when_no_email!(person) if person.email.to_s.empty?
18
+ next unless account = person.account
19
+ next if options.dig(:exclude, :account)
20
+ if account.policy_group_ids.empty? && def_pg
21
+ account.policy_group_ids = [def_pg]
22
+ end
23
+ add_login_method_if_applicable!(account)
15
24
  end
16
25
 
17
26
  warn_account_removal!
@@ -39,20 +48,34 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
39
48
  return !!person.original_doc["account"]
40
49
  end
41
50
 
42
- def no_policy_group_ids?(person)
43
- (account = person.account) && account.policy_group_ids.empty?
51
+ def add_login_method_if_applicable!(account)
52
+ return unless account.as_update.key?("login_provider_ids")
53
+ if account.login_provider_ids.empty? && def_login
54
+ account.login_provider_ids = [def_login]
55
+ end
56
+ end
57
+
58
+ def def_pg
59
+ @def_pg ||= policy_groups.to_id(default_group)
44
60
  end
45
61
 
46
- def defid
47
- @defid ||= policy_groups.to_id([default_group]).compact
62
+ def def_login
63
+ @def_login ||= login_providers.to_id(default_login)
48
64
  end
49
65
 
50
66
  def default_group
51
- session.config.people.default_usergroup
67
+ config.people.default_usergroup
68
+ end
69
+
70
+ def default_login
71
+ config.people.default_login_method
72
+ end
73
+
74
+ def login_providers
75
+ session.login_providers
52
76
  end
53
77
 
54
78
  def policy_groups
55
79
  session.policy_groups
56
80
  end
57
-
58
81
  end
@@ -86,7 +86,19 @@ module Eco
86
86
  def default_schema?
87
87
  !!self["default_schema"]
88
88
  end
89
-
89
+
90
+ def default_login_method=(name)
91
+ self["default_login_method"] = name
92
+ end
93
+
94
+ def default_login_method
95
+ self["default_login_method"]
96
+ end
97
+
98
+ def default_login_method?
99
+ !!self["default_login_method"]
100
+ end
101
+
90
102
  # @return [Hash] with defined pairs format `key` and Person parsers.
91
103
  def parsers
92
104
  self["parsers"] ||= {}
@@ -297,6 +297,11 @@ module Eco
297
297
  people.default_schema = name
298
298
  end
299
299
 
300
+ # Set the **default login method** that users should acquire.
301
+ def default_login_method=(name)
302
+ people.default_login_method = name
303
+ end
304
+
300
305
  # @see Eco::API::Session::Config::People
301
306
  # @param (see Eco::API::Session::Config::People)
302
307
  # @return [Eco::API::Common::People::PersonParser] parser/serializer for the defined `format`.
@@ -0,0 +1,22 @@
1
+ class Eco::API::UseCases::DefaultCases::ClearAbilitiesTransCase < Eco::API::Common::Loaders::UseCase
2
+ name "clear-abilities"
3
+ type :transform
4
+
5
+ def main(people, session, options, usecase)
6
+ clear_abilities(people.users, session, options, usecase)
7
+ end
8
+
9
+ private
10
+
11
+ def clear_abilities(users, session, options, usecase)
12
+ update = session.new_job("main", "clear-abilities", :update, usecase, :account)
13
+ users.each do |person|
14
+ person.account.permissions_custom = nil_abilities.dup
15
+ update.add(person)
16
+ end
17
+ end
18
+
19
+ def nil_abilities
20
+ @nil_abilities ||= Eco::API::Organization::PresetsFactory.all_abilities
21
+ end
22
+ end
@@ -9,10 +9,10 @@ class Eco::API::UseCases::DefaultCases::HrisCase < Eco::API::Common::Loaders::Us
9
9
  @session = session; @options = options; @people = people
10
10
  require_only_one_schema!
11
11
  micro = session.micro
12
+ @leavers = session.new_job("pre", "leavers", :update, usecase, :account)
12
13
  @creation = session.new_job("main", "create", :create, usecase)
13
14
  @update = session.new_job("main", "update", :update, usecase)
14
15
  @supers = session.new_job("post", "supers", :update, usecase, :core)
15
- @leavers = session.new_job("post", "leavers", :update, usecase, :account)
16
16
 
17
17
  micro.with_each_leaver(entries, people, options) do |person|
18
18
  leavers.add(person, &method(:leavers_callback))
@@ -15,6 +15,7 @@ require_relative 'default_cases/analyse_people_case'
15
15
  require_relative 'default_cases/append_usergroups_case'
16
16
  require_relative 'default_cases/change_email_case'
17
17
  require_relative 'default_cases/clean_unknown_tags_case'
18
+ require_relative 'default_cases/clear_abilities_case'
18
19
  require_relative 'default_cases/codes_to_tags_case'
19
20
  require_relative 'default_cases/create_case'
20
21
  require_relative 'default_cases/create_details_case'
@@ -196,6 +196,10 @@ ASSETS.cli.config do |cnf|
196
196
  options.deep_merge!(force: {invite: true})
197
197
  end
198
198
 
199
+ desc = "Clears the `permissions_custom`, provided that Policy Group abilities alone apply."
200
+ desc += " Please be mindfull if you use this option (there may be users that have been upgraded in ad-hoc manner)."
201
+ cases.add("-clear-abilities", :transform, desc, case_name: "clear-abilities")
202
+
199
203
  desc = "Deletes everybody that has been filtered from the people manager"
200
204
  cases.add("-delete", :transform, desc, case_name: "delete")
201
205
  desc = "Deletes the people specified in the input data"
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.56"
2
+ VERSION = "2.0.59"
3
3
  end
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: 2.0.56
4
+ version: 2.0.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 0.8.27
139
+ version: 0.8.28
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.9'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.8.27
149
+ version: 0.8.28
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'
@@ -528,6 +528,7 @@ files:
528
528
  - lib/eco/api/usecases/default_cases/append_usergroups_case.rb
529
529
  - lib/eco/api/usecases/default_cases/change_email_case.rb
530
530
  - lib/eco/api/usecases/default_cases/clean_unknown_tags_case.rb
531
+ - lib/eco/api/usecases/default_cases/clear_abilities_case.rb
531
532
  - lib/eco/api/usecases/default_cases/codes_to_tags_case.rb
532
533
  - lib/eco/api/usecases/default_cases/create_case.rb
533
534
  - lib/eco/api/usecases/default_cases/create_details_case.rb