eco-helpers 1.0.5 → 1.0.6

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: db7768619b97c307a3bed9edede57a9cc0fc32defce50ddbe43972544cc5b915
4
- data.tar.gz: f4c69c66654881629ce0d070f1b912982d73df87d3b608e428cd12182c5f3729
3
+ metadata.gz: a87a05e0b6be791a7cb630afb3fce8405447aca9f130a4940d3a042b8ccf0720
4
+ data.tar.gz: fc315306e49cfe9be73c67b61b9a2bd1f59fbc6b74850e82400399ebd6255377
5
5
  SHA512:
6
- metadata.gz: e2d69f4364ad41db88ceb7d7876251d0fc560dbd027cc79e5e6f7640c7f830a3680722c482eaed2c8647938bb7e6d8961b336c195ec0d53192ec856ec332440e
7
- data.tar.gz: de56af0c58ef50d7caadc1162cf30a04137c8fd35af6453c0a970473be9e9c98ff3192c29460fbc2085805d4a914706dfe0e34c37f9b2defe790765a11188690
6
+ metadata.gz: 18f83a3a064dd30033519d3df486e1d9839a87abc1161bf9f2d42b1378dcfe4ae20b40d018968c5fed6b8e3e6310202f2545dd4a2c2de85281de93a8d7b662f5
7
+ data.tar.gz: 2ac3597409e546f5d931264b5cfa8a4f39b3ad4665c4d37f5349da12bbf3af9d42fe3f261b379f0c0e74cbcc8399a1d832578e83b26eeca4f0c419024a59cacd
@@ -63,7 +63,10 @@ module Eco
63
63
  encoding ||= Eco::API::Common::Session::FileManager.encoding(file)
64
64
  file_content = File.read(file, encoding: encoding)
65
65
  arr_hash = @person_parser.parse(format, file_content)
66
+ else
67
+ @logger.warn("File does not exist: #{file}")
66
68
  end
69
+
67
70
  entries(data: arr_hash)
68
71
  else
69
72
  Entries.new(data, klass: PersonEntry, factory: self)
@@ -2,7 +2,7 @@ module Ecoportal
2
2
  module API
3
3
  class Internal
4
4
  class Person
5
-
5
+
6
6
  def reset_account!
7
7
  doc["account"] = JSON.parse(original_doc["account"])
8
8
  end
@@ -11,22 +11,6 @@ module Ecoportal
11
11
  original_doc["account"] = JSON.parse(doc["account"])
12
12
  end
13
13
 
14
- def account=(value)
15
- case value
16
- when NilClass
17
- doc["account"] = nil
18
- when Internal::Account
19
- doc["account"] = JSON.parse(value.to_json)
20
- when Hash
21
- doc["account"] = value.slice(*%w[policy_group_ids landing_page_id permissions_preset permissions_custom preferences prefilter filter_tags default_tag login_provider_ids starred_ids])
22
- else
23
- # TODO
24
- raise "Invalid set on account: Need nil, Account or Hash; got #{value.class}"
25
- end
26
- remove_instance_variable("@account") if defined?(@account)
27
- return account
28
- end
29
-
30
14
  end
31
15
  end
32
16
  end
@@ -30,8 +30,9 @@ module Eco
30
30
  @match = /#{@str_err}/
31
31
  end
32
32
  class EmailTaken < Eco::API::Error
33
- @str_err = "user email already taken"
34
- @match = /#{@str_err}/
33
+ @str_err = "user email already taken"
34
+ @str_err2 = "Email is already taken"
35
+ @match = /(?:#{@str_err}|#{@str_err2})/
35
36
  end
36
37
  class SupervisorNotFound < Eco::API::Error
37
38
  @str_err = "Supervisor not found"
@@ -51,13 +51,13 @@ module Eco
51
51
  def person(id: nil, external_id: nil, email: nil, strict: false)
52
52
  init_caches
53
53
  pers = @by_id[id]&.first if id
54
- pers = @by_external_id[external_id&.strip]&.first if !pers && !external_id.to_s.strip.empty?
54
+ pers = @by_external_id[external_id&.strip]&.first if !pers && !external_id.to_s.strip.empty?
55
55
 
56
56
  # strict prevents taking existing user for searched person with same email
57
57
  # specially useful if the organisation ensures all have external id (no need for email search)
58
58
  if !pers && (!strict || external_id.to_s.strip.empty?)
59
59
  # person still not found and either not strict or no external_id provided
60
- pers = @by_users_email[email&.downcase.strip]&.first if !email.to_s.strip.empty?
60
+ pers = @by_users_email[email&.downcase.strip]&.first if !email.to_s.strip.empty?
61
61
 
62
62
  if !pers && !strict && !email.to_s.strip.empty?
63
63
  candidates = @by_non_users_email[email&.downcase.strip] || []
@@ -66,7 +66,7 @@ module Eco
66
66
  end
67
67
 
68
68
  end
69
- pers = @by_external_id[email&.downcase.strip]&.first if !pers && !email.to_s.strip.empty?
69
+ pers = @by_external_id[email&.downcase.strip]&.first if !pers && !email.to_s.strip.empty?
70
70
 
71
71
  pers
72
72
  end
@@ -102,6 +102,10 @@ module Eco
102
102
  exclude_people(into_a(object), strict: strict)
103
103
  end
104
104
 
105
+ def exclude!(object, strict: false)
106
+ self < exclude(object, strict: strict).to_a
107
+ end
108
+
105
109
  def exclude_people(list, strict: false)
106
110
  discarded = list.map do |person|
107
111
  find(person, strict: strict)
@@ -46,10 +46,16 @@ module Eco
46
46
  @has_tags.empty?
47
47
  end
48
48
 
49
- # List of tag nodes of the entire subtree.
49
+ # @param depth [Integer] if empty, returns the list of tag nodes of that level. Otherwise the list of tag nodes of the entire subtree.
50
50
  # @return [Array<String>]
51
- def tags
52
- @hash_tags.keys
51
+ def tags(depth: nil)
52
+ if !depth || depth < 0
53
+ @hash_tags.keys
54
+ else
55
+ @hash_tags.select do |t, n|
56
+ n.depth == depth
57
+ end.keys
58
+ end
53
59
  end
54
60
 
55
61
  # Verifies if a tag exists in the tree.
@@ -91,18 +91,18 @@ module Eco
91
91
  end
92
92
 
93
93
  def launch(simulate: false)
94
- queue = processed_queue
95
- launch_feedback(queue, simulate ? 2500 : 800)
94
+ pqueue = processed_queue
95
+ launch_feedback(pqueue, simulate ? 2500 : 800)
96
96
 
97
97
  if !simulate
98
- if queue.length > 0
99
- backup_update(queue)
100
- @status = session.batch.launch(queue, method: type)
98
+ if pqueue.length > 0
99
+ backup_update(pqueue)
100
+ @status = session.batch.launch(pqueue, method: type)
101
101
  @status.root = self
102
102
  end
103
103
  end
104
104
 
105
- post_launch(queue: queue, simulate: simulate)
105
+ post_launch(queue: pqueue, simulate: simulate)
106
106
 
107
107
  logger.info("Simulate: this would have launched: '#{type}'") if simulate
108
108
  @pending = false
@@ -113,7 +113,7 @@ module Eco
113
113
 
114
114
  def processed_queue
115
115
  @queue.each {|e| @callbacks[e].call(e) if @callbacks.key?(e) }
116
- apply_policies(@queue).select {|e| !as_update(e).empty?}
116
+ apply_policies(api_included(@queue)).select {|e| !as_update(e).empty?}
117
117
  end
118
118
 
119
119
  def post_launch(queue: [], simulate: false)
@@ -128,9 +128,9 @@ module Eco
128
128
  handlers = session.config.error_handlers
129
129
  if @status.errors.any? && !handlers.empty?
130
130
  err_types = @status.errors.by_type
131
- handlers.each do |hd|
132
- if entries = err_types[hd.name]
133
- hd.launch(people: people(entries), session: session, options: options)
131
+ handlers.each do |handler|
132
+ if entries = err_types[handler.name]
133
+ handler.launch(people: people(entries), session: session, options: options)
134
134
  end
135
135
  end
136
136
  end
@@ -141,11 +141,21 @@ module Eco
141
141
  end
142
142
  end
143
143
 
144
+ # if there is a config definition to exclude entries
145
+ # and the current batch is not a creation batch
146
+ # - filter out excluded entries from the api update
147
+ def api_included(full_queue)
148
+ return full_queue if type == :create
149
+ return full_queue unless excluded = session.config.people.api_excluded
150
+ full_queue.select {|entry| !excluded.call(entry, session, options, self)}
151
+ end
152
+
144
153
  def apply_policies(pre_queue)
145
- pre_queue.tap do |entries|
154
+ #pre_queue.tap do |entries|
155
+ people(pre_queue).tap do |entries|
146
156
  policies = session.config.policies
147
157
  unless policies.empty?
148
- policies.launch(people: people(entries), session: session, options: options)
158
+ policies.launch(people: entries, session: session, options: options)
149
159
  end
150
160
  end
151
161
  end
@@ -39,6 +39,12 @@ module Eco
39
39
  self["discarded_file"]
40
40
  end
41
41
 
42
+ # with given a person what is the criteria of exclusion
43
+ def api_excluded
44
+ return self["api_excluded"] unless block_given?
45
+ self["api_excluded"] = Proc.new
46
+ end
47
+
42
48
  # internal-external fields map
43
49
  def fields_mapper=(file)
44
50
  self["fields_mapper"] = file
@@ -56,7 +62,7 @@ module Eco
56
62
  def default_usergroup
57
63
  self["default_usergroup"]
58
64
  end
59
-
65
+
60
66
  def default_schema=(name)
61
67
  self["default_schema"] = name
62
68
  end
@@ -18,7 +18,7 @@ module Eco
18
18
  if !person
19
19
  session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
20
20
  else
21
- unless entry.email.to_s.strip.downcase == person.email
21
+ unless entry.email.to_s.strip.downcase == person.email.to_s.strip.downcase
22
22
 
23
23
  super_id = person.supervisor_id
24
24
  s_account_doc = person.account&.doc
@@ -7,6 +7,7 @@ module Eco
7
7
  def process
8
8
  @cases.define("create", type: :sync) do |entries, people, session, options, usecase|
9
9
  creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
10
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
10
11
 
11
12
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
13
  pgs = session.policy_groups
@@ -55,6 +56,23 @@ module Eco
55
56
  end
56
57
 
57
58
  creation.add(person)
59
+
60
+ # set supervisor
61
+ unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
62
+ if !(sup_id = entry.supervisor_id)
63
+ person.supervisor_id = nil
64
+ else
65
+ if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
66
+ person.supervisor_id = supervisor.id
67
+ else
68
+ # delay setting supervisor if does not exit
69
+ supers.add(person) do |person|
70
+ person.supervisor_id = sup_id
71
+ end
72
+ end
73
+ end
74
+ end
75
+
58
76
  end
59
77
  end
60
78
  end
@@ -31,10 +31,7 @@ module Eco
31
31
  else
32
32
  # delay setting supervisor if does not exit
33
33
  supers.add(person) do |person|
34
- #person = session.new_person(person: person.doc)
35
- person.sync
36
34
  person.supervisor_id = sup_id
37
- person
38
35
  end
39
36
  end
40
37
  end
@@ -6,44 +6,78 @@ module Eco
6
6
 
7
7
  def process
8
8
  @cases.define("hris", type: :sync) do |entries, people, session, options, usecase|
9
- # IMPORTANT: this two lines ensure that key users are preserved (only manually maintained)
10
- #people = people.exclude(session.discarded_entries)
11
- #entries = entries.exclude(session.discarded_entries)
12
-
13
9
  creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
14
10
  update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
15
11
  supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
16
- #remove = session.job_group("post").new("remove_account", type: :update, sets: :account)
12
+ remove = session.job_group("post").new("remove_account", usecase: usecase, type: :update, sets: :account)
17
13
 
18
- #people.users.each_with_index do |person, i|
19
- # if !entries.find(person)
20
- # remove.add(person) do |person|
21
- # person.account = nil
22
- # person
23
- # end
24
- # end
25
- #end
14
+ people.users.each_with_index do |person, i|
15
+ if !entries.find(person)
16
+ remove.add(person) do |person|
17
+ person.supervisor_id = nil
18
+ person.account = nil
19
+ end
20
+ end
21
+ end
26
22
 
27
23
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
24
+ pgs = session.policy_groups
28
25
 
29
- entries.each.with_index do |entry, i|
26
+ entries.each_with_index do |entry, i|
30
27
  person = people.find(entry, strict: strict_search)
31
28
  person = session.new_person if create = !person
32
29
 
33
- entry.set_core(person, exclude: "supervisor_id")
34
- entry.set_details(person)
35
- entry.set_account(person) #if !remove.people.find(entry)
36
- person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
30
+ unless options.dig(:exclude, :core) && !create
31
+ ini_tags = person.filter_tags || []
32
+
33
+ core_attrs = ["name", "external_id", "email", "filter_tags"]
34
+ core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
35
+ core_excluded.push("supervisor_id")
36
+
37
+ entry.set_core(person, exclude: core_excluded)
38
+ if session.tagtree && !options.dig(:exclude, :filter_tags)
39
+ person.filter_tags = session.tagtree.user_tags(
40
+ initial: ini_tags,
41
+ final: person.filter_tags,
42
+ preserve_custom: true,
43
+ add_custom: true
44
+ )
45
+ end
46
+ end
47
+
48
+ entry.set_details(person) unless options.dig(:exclude, :details)
49
+
50
+ unless options.dig(:exclude, :account)
51
+ ini_pg_ids = person.account&.policy_group_ids || []
37
52
 
38
- person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
53
+ account_excluded = []
54
+ account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
39
55
 
40
- person.account.default_tag = person.filter_tags.first if person.filter_tags.length == 1
56
+ entry.set_account(person, exclude: account_excluded)
41
57
 
58
+ person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
59
+
60
+ unless options.dig(:exclude, :policy_groups) && !create
61
+ person.account.policy_group_ids = pgs.user_pg_ids(
62
+ initial: ini_pg_ids,
63
+ final: person.account.policy_group_ids
64
+ )
65
+ end
66
+
67
+ person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
68
+
69
+ if session.tagtree
70
+ person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
71
+ else
72
+ tags = person.filter_tags
73
+ person.account.default_tag = tags.first unless tags.length > 1
74
+ end
75
+
76
+ end
42
77
 
43
78
  creation.add(person) if create
44
79
  update.add(person) unless create
45
80
 
46
- # set supervisor
47
81
  # set supervisor
48
82
  unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
49
83
  if !(sup_id = entry.supervisor_id)
@@ -54,9 +88,7 @@ module Eco
54
88
  else
55
89
  # delay setting supervisor if does not exit
56
90
  supers.add(person) do |person|
57
- person.consolidate!
58
91
  person.supervisor_id = sup_id
59
- person
60
92
  end
61
93
  end
62
94
  end
@@ -65,6 +97,8 @@ module Eco
65
97
  end
66
98
 
67
99
  end
100
+
101
+
68
102
  end
69
103
 
70
104
  end
@@ -24,25 +24,50 @@ module Eco
24
24
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
25
25
  pgs = session.policy_groups
26
26
 
27
+ not_exist = []
28
+
27
29
  entries.each.with_index do |entry, i|
28
30
  create = ! (person = people.find(entry, strict: strict_search))
29
31
 
30
32
  if create && !options.dig(:include, :create)
31
- session.logger.error("Entry(#{i}) - this person does not exist: #{entry.name} (#{entry.email})")
33
+ not_exist.push(entry);
32
34
  else
33
35
  person = session.new_person if create
34
36
 
35
37
  unless options.dig(:exclude, :core)
36
- person.external_id = entry.external_id
37
- person.name = entry.name
38
- person.email = entry.email unless options.dig(:exclude, :email)
38
+ person.external_id = entry.external_id unless options.dig(:exclude, :external_id)
39
+ person.name = entry.name unless options.dig(:exclude, :name)
40
+ person.email = entry.email unless options.dig(:exclude, :email)
39
41
  person.supervisor_id = entry.supervisor_id unless options.dig(:exclude, :supervisor)
40
- person.filter_tags = entry.filter_tags || []
42
+ person.filter_tags = entry.filter_tags || [] unless options.dig(:exclude, :filter_tags)
41
43
  end
42
44
 
43
45
  unless options.dig(:exclude, :account)
44
- person.account = entry.account
45
- person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
46
+ #person.account = entry.account
47
+ if eaccount = entry.account
48
+ person.account ||= {}
49
+ person.account.default_tag = eaccount.default_tag unless options.dig(:exclude, :filter_tags)
50
+
51
+ unless options.dig(:exclude, :policy_groups) && person.account.policy_group_ids
52
+ person.account.policy_group_ids = eaccount.policy_group_ids
53
+ end
54
+
55
+ unless options.dig(:exclude, :abilities) && (person.account.permissions_preset || person.account.permissions_custom)
56
+ person.account.permissions_preset = eaccount.permissions_preset if eaccount.permissions_preset
57
+ person.account.permissions_custom = eaccount.permissions_custom
58
+ end
59
+ person.account.login_provider_ids = eaccount.login_provider_ids if eaccount.login_provider_ids
60
+ person.account.accept_eula = eaccount.accept_eula if eaccount.accept_eula
61
+
62
+ if eaccount.preferences
63
+ person.account.doc["preferences"] = JSON.parse((eaccount.doc["preferences"] || {}).to_json)
64
+ end
65
+
66
+ person.account.starred_ids = eaccount.starred_ids if eaccount.landing_page_id
67
+ person.account.landing_page_id = eaccount.landing_page_id if eaccount.landing_page_id
68
+
69
+ person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
70
+ end
46
71
  end
47
72
 
48
73
  unless options.dig(:exclude, :details)
@@ -53,6 +78,15 @@ module Eco
53
78
  update.add(person) unless create
54
79
  end
55
80
  end
81
+
82
+ unless not_exist.empty?
83
+ session.logger.error("There were #{not_exist.length} entries of the back up that do not exist in the (filtered?) people manager")
84
+ session.logger.error("Some examples:")
85
+ not_exist.slice(0, 4).each_with_index do |entry, i|
86
+ session.logger.error("Entry(#{i}) - this person does not exist: #{entry.name} (#{entry.email})")
87
+ end
88
+ end
89
+
56
90
  end
57
91
  end
58
92
 
@@ -13,6 +13,23 @@ module Eco
13
13
  end
14
14
  invite
15
15
  end
16
+
17
+ @cases.define("reinvite", type: :sync) do |entries, people, session, options, usecase|
18
+ invite = session.job_group("main").new("invite", usecase: usecase, type: :update, sets: :account)
19
+
20
+ users = people.users
21
+ strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
22
+
23
+ entries.each_with_index do |entry, i|
24
+ if person = people.find(entry, strict: strict_search)
25
+ person.account.send_invites = true
26
+ invite.add(person)
27
+ else
28
+ session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
29
+ end
30
+ end
31
+
32
+ end
16
33
  end
17
34
 
18
35
  end
@@ -5,18 +5,9 @@ module Eco
5
5
  class UpdateCase < DefaultCase
6
6
 
7
7
  def process
8
- #opts = CLI::Options.new do |p|
9
- # p.option :exclude, "Allows to exclude certain options"
10
- # p.suboption :exclude, :core, "Excludes core details from the update.", optional: true
11
- # p.suboption :exclude, :details, "Excludes schema details from the update.", optional: true
12
- # p.suboption :exclude, :account, "Excludes account details from the update.", optional: true
13
- # p.suboption :exclude, :email, "Excludes core email from the update.", optional: true
14
- # p.suboption :exclude, :supervisor, "Excludes supervisor_id from the update.", optional: true
15
- # p.suboption :exclude, :abilities, "Excludes the abilities from the update.", optional: true
16
- #end
17
-
18
8
  @cases.define("update", type: :sync) do |entries, people, session, options, usecase|
19
9
  update = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details, :account])
10
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
20
11
 
21
12
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
22
13
  pgs = session.policy_groups
@@ -24,14 +15,16 @@ module Eco
24
15
  entries.each.with_index do |entry, i|
25
16
  if person = people.find(entry, strict: strict_search)
26
17
 
27
- core_excluded = ["supervisor_id"]
28
- core_excluded.push("email") if options.dig(:exclude, :email)
29
-
30
18
  unless options.dig(:exclude, :core)
31
19
  ini_tags = person.filter_tags || []
20
+
21
+ core_attrs = ["name", "external_id", "email", "filter_tags"]
22
+ core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
23
+ core_excluded.push("supervisor_id")
24
+
32
25
  entry.set_core(person, exclude: core_excluded)
33
26
 
34
- if session.tagtree
27
+ if session.tagtree && !options.dig(:exclude, :filter_tags)
35
28
  person.filter_tags = session.tagtree.user_tags(
36
29
  initial: ini_tags,
37
30
  final: person.filter_tags,
@@ -40,31 +33,56 @@ module Eco
40
33
  )
41
34
  end
42
35
  end
43
-
36
+
44
37
  entry.set_details(person) unless options.dig(:exclude, :details)
45
38
 
46
39
  unless options.dig(:exclude, :account)
47
40
  ini_pg_ids = person.account&.policy_group_ids || []
48
- entry.set_account(person)
49
41
 
50
- person.account.policy_group_ids = pgs.user_pg_ids(
51
- initial: ini_pg_ids,
52
- final: person.account.policy_group_ids
53
- )
42
+ account_excluded = []
43
+ account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups)
54
44
 
55
- person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
45
+ entry.set_account(person, exclude: account_excluded)
56
46
 
57
- if session.tagtree
58
- person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
59
- else
60
- tags = person.filter_tags
61
- person.account.default_tag = tags.first unless tags.length > 1
47
+ person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
48
+
49
+ unless options.dig(:exclude, :policy_groups)
50
+ person.account.policy_group_ids = pgs.user_pg_ids(
51
+ initial: ini_pg_ids,
52
+ final: person.account.policy_group_ids
53
+ )
62
54
  end
63
55
 
64
- person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
56
+ person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
57
+
58
+ unless options.dig(:exclude, :filter_tags)
59
+ if session.tagtree
60
+ person.account.default_tag = session.tagtree.default_tag(*person.filter_tags)
61
+ else
62
+ tags = person.filter_tags
63
+ person.account.default_tag = tags.first unless tags.length > 1
64
+ end
65
+ end
65
66
 
66
67
  end
67
68
  update.add(person)
69
+
70
+ # set supervisor
71
+ unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
72
+ if !(sup_id = entry.supervisor_id)
73
+ person.supervisor_id = nil
74
+ else
75
+ if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
76
+ person.supervisor_id = supervisor.id
77
+ else
78
+ # delay setting supervisor if does not exit
79
+ supers.add(person) do |person|
80
+ person.supervisor_id = sup_id
81
+ end
82
+ end
83
+ end
84
+ end
85
+
68
86
  else
69
87
  session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
70
88
  end
@@ -6,18 +6,50 @@ module Eco
6
6
 
7
7
  def process
8
8
  @cases.define("update-details", type: :sync) do |entries, people, session, options, usecase|
9
- job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details])
9
+ job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: [:core, :details])
10
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
10
11
 
11
12
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
12
13
 
13
14
  entries.each.with_index do |entry, i|
14
15
  if person = people.find(entry, strict: strict_search)
15
- core_excluded = ["supervisor_id"]
16
- core_excluded.push("email") if options.dig(:exclude, :email)
17
- entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
16
+ unless options.dig(:exclude, :core)
17
+ core_attrs = ["name", "external_id", "email", "filter_tags"]
18
+ core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
19
+ core_excluded.push("supervisor_id")
20
+
21
+ entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
22
+
23
+ if session.tagtree && !options.dig(:exclude, :filter_tags)
24
+ person.filter_tags = session.tagtree.user_tags(
25
+ initial: ini_tags,
26
+ final: person.filter_tags,
27
+ preserve_custom: true,
28
+ add_custom: true
29
+ )
30
+ end
31
+ end
32
+
18
33
  entry.set_details(person)
19
34
 
20
35
  job.add(person)
36
+
37
+ # set supervisor
38
+ unless options.dig(:exclude, :core) || options.dig(:exclude, :supervisor)
39
+ if !(sup_id = entry.supervisor_id)
40
+ person.supervisor_id = nil
41
+ else
42
+ if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)
43
+ person.supervisor_id = supervisor.id
44
+ else
45
+ # delay setting supervisor if does not exit
46
+ supers.add(person) do |person|
47
+ person.supervisor_id = sup_id
48
+ end
49
+ end
50
+ end
51
+ end
52
+
21
53
  else
22
54
  session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
23
55
  end
@@ -11,19 +11,21 @@ module Eco
11
11
  supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
12
12
 
13
13
  strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
14
- pgs = session.policy_groups
14
+ pgs = session.policy_groups
15
15
 
16
- entries.each.with_index do |entry, i|
17
- create = ! (person = people.find(entry, strict: strict_search))
18
- person = session.new_person if create
19
-
20
- core_excluded = ["supervisor_id"]
21
- core_excluded.push("email") if options.dig(:exclude, :email) && !create
16
+ entries.each_with_index do |entry, i|
17
+ person = people.find(entry, strict: strict_search)
18
+ person = session.new_person if create = !person
22
19
 
23
20
  unless options.dig(:exclude, :core) && !create
24
21
  ini_tags = person.filter_tags || []
25
- entry.set_core(person, exclude: core_excluded)
26
- if session.tagtree
22
+
23
+ core_attrs = ["name", "external_id", "email", "filter_tags"]
24
+ core_excluded = core_attrs.map(&:to_sym).select {|attr| options.dig(:exclude, attr)}
25
+ core_excluded.push("supervisor_id")
26
+
27
+ entry.set_core(person, exclude: core_excluded)
28
+ if session.tagtree && !options.dig(:exclude, :filter_tags)
27
29
  person.filter_tags = session.tagtree.user_tags(
28
30
  initial: ini_tags,
29
31
  final: person.filter_tags,
@@ -37,14 +39,20 @@ module Eco
37
39
 
38
40
  unless options.dig(:exclude, :account)
39
41
  ini_pg_ids = person.account&.policy_group_ids || []
40
- entry.set_account(person)
42
+
43
+ account_excluded = []
44
+ account_excluded.push("policy_group_ids") if options.dig(:exclude, :policy_groups) && !create
45
+
46
+ entry.set_account(person, exclude: account_excluded)
41
47
 
42
48
  person.account.send_invites = options[:send_invites] if options.key?(:send_invites)
43
49
 
44
- person.account.policy_group_ids = pgs.user_pg_ids(
45
- initial: ini_pg_ids,
46
- final: person.account.policy_group_ids
47
- )
50
+ unless options.dig(:exclude, :policy_groups) && !create
51
+ person.account.policy_group_ids = pgs.user_pg_ids(
52
+ initial: ini_pg_ids,
53
+ final: person.account.policy_group_ids
54
+ )
55
+ end
48
56
 
49
57
  person.account.permissions_custom = session.new_preset(person) unless !create && options.dig(:exclude, :abilities)
50
58
 
@@ -70,9 +78,7 @@ module Eco
70
78
  else
71
79
  # delay setting supervisor if does not exit
72
80
  supers.add(person) do |person|
73
- person.consolidate!
74
81
  person.supervisor_id = sup_id
75
- person
76
82
  end
77
83
  end
78
84
  end
@@ -28,18 +28,32 @@ ASSETS.cli.config do |cnf|
28
28
  options_set.add("-exclude-core") do |options|
29
29
  options.deep_merge!(exclude: {core: true})
30
30
  end
31
+ options_set.add("-exclude-filter-tags") do |options|
32
+ options.deep_merge!(exclude: {filter_tags: true})
33
+ end
34
+ options_set.add("-exclude-external-id") do |options|
35
+ options.deep_merge!(exclude: {external_id: true})
36
+ end
31
37
  options_set.add("-exclude-supervisor") do |options|
32
38
  options.deep_merge!(exclude: {supervisor: true})
33
39
  end
34
40
  options_set.add("-exclude-email") do |options|
35
41
  options.deep_merge!(exclude: {email: true})
36
42
  end
43
+ options_set.add("-exclude-name") do |options|
44
+ options.deep_merge!(exclude: {name: true})
45
+ end
46
+
37
47
  options_set.add("-exclude-details") do |options|
38
48
  options.deep_merge!(exclude: {details: true})
39
49
  end
50
+
40
51
  options_set.add("-exclude-account") do |options|
41
52
  options.deep_merge!(exclude: {account: true})
42
53
  end
54
+ options_set.add("-exclude-policy-groups") do |options|
55
+ options.deep_merge!(exclude: {policy_groups: true})
56
+ end
43
57
  options_set.add("-exclude-abilities") do |options|
44
58
  options.deep_merge!(exclude: {abilities: true})
45
59
  end
@@ -37,6 +37,7 @@ ASSETS.cli.config do |cnf|
37
37
  cases.add("-create-details-from", :sync, case_name: "create-details")
38
38
  cases.add("-update-details-from", :sync, case_name: "update-details")
39
39
  cases.add("-reinvite", :transform, case_name: "reinvite")
40
+ cases.add("-reinvite-from", :sync, case_name: "reinvite")
40
41
  cases.add("-set-default-tag", :transform, case_name: "set-default-tag")
41
42
 
42
43
  cases.add("-recover-db-from", :sync, case_name: "recover-db") do |input, people, session, options|
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
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: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura