lib/eco/api/usecases/default/people/restore_db_case.rb in eco-helpers-2.6.4 vs lib/eco/api/usecases/default/people/restore_db_case.rb in eco-helpers-2.7.0
- old
+ new
@@ -1,10 +1,12 @@
+# @example
+# -restore-db-from backup.json -skip-api-policies -skip-batch-policy -include-excluded -simulate
class Eco::API::UseCases::Default::People::RestoreDBCase < Eco::API::Common::Loaders::UseCase
name "restore-db"
type :sync
- def main(entries, people, session, options, usecase)
+ def main(entries, people, session, options, usecase) # rubocop:disable Metrics/AbcSize
require_people_as_entries!(entries)
restart = session.new_job("main", "restart", :create, usecase) if options.dig(:include, :create)
update = session.new_job("main", "update", :update, usecase)
delete = session.new_job("main", "delete", :update, usecase)
@@ -17,18 +19,18 @@
re_starters = []
micro.with_each(entries, people, options) do |entry, person|
if person.new? && !options.dig(:include, :create)
- re_starters.push(entry);
+ re_starters.push(entry)
next
end
person.new? ? restart.add(person) : update.add(person)
- core_copy(entry, person) unless options.dig(:exclude, :core)
- person.details = entry.details unless options.dig(:exclude, :details)
+ core_copy(entry, person) unless options.dig(:exclude, :core)
+ person.details = entry.details unless options.dig(:exclude, :details)
unless options.dig(:exclude, :account) || !entry.account
person.account ||= {}
account_copy(entry.account, person.account)
end
@@ -46,48 +48,51 @@
person.supervisor_id = entry.supervisor_id unless options.dig(:exclude, :supervisor)
person.filter_tags = entry.filter_tags unless options.dig(:exclude, :filter_tags)
person.freemium = entry.freemium
end
- def account_copy(src, dst)
- if src
- dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
- dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
+ def account_copy(src, dst) # rubocop:disable Metrics/AbcSize
+ return unless src
+ dst.default_tag = src.default_tag unless options.dig(:exclude, :filter_tags)
+ dst.policy_group_ids = src.policy_group_ids unless options.dig(:exclude, :policy_groups)
+ dst.permissions_custom = src.permissions_custom unless options.dig(:exclude, :abilities)
- unless options.dig(:exclude, :abilities)
- dst.permissions_custom = src.permissions_custom
- end
+ unless options.dig(:exclude, :login_providers) || options[:source_enviro]
+ dst.login_provider_ids = src.login_provider_ids
+ end
- unless options.dig(:exclude, :login_providers) || options.dig(:source_enviro)
- dst.login_provider_ids = src.login_provider_ids
- end
+ if src.preferences # rubocop:disable Style/IfUnlessModifier
+ dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
+ end
- if src.preferences
- dst.doc["preferences"] = JSON.parse((src.doc["preferences"] || {}).to_json)
- end
-
- unless options.dig(:source_enviro)
- dst.starred_ids = src.starred_ids
- dst.landing_page_id = src.landing_page_id
- end
-
- dst&.send_invites = options[:send_invites] if options.key?(:send_invites)
+ unless options[:source_enviro]
+ dst.starred_ids = src.starred_ids
+ dst.landing_page_id = src.landing_page_id
end
+
+ dst&.send_invites = options[:send_invites] if options.key?(:send_invites)
end
def require_people_as_entries!(entries)
- unless entries.is_a?(Eco::API::Organization::People)
- logger.error("Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}")
- exit(1)
- end
+ return true if entries.is_a?(Eco::API::Organization::People)
+ log(:error) {
+ "Your input should be an 'Eco::API::Organization::People' object. Got: #{entries.class}"
+ }
+ exit(1)
end
def report_re_starters(re_starters)
- unless re_starters.empty?
- logger.error("There were #{re_starters.length} entries of the backup that do not exist in the (filtered?) people manager")
- logger.error("Some examples:")
- re_starters.slice(0, 4).each_with_index do |entry, i|
- logger.error("This person does not exist: #{entry.name} (#{entry.email})")
- end
+ return if re_starters.empty?
+ examples = re_starters.slice(0, 4).map do |entry|
+ "This person does not exist: '#{entry.name}' (#{entry.email})"
end
+
+ log(:error) {
+ msg = []
+ msg << "There were #{re_starters.length} entries of the backup "
+ msg << "that do not exist in the (filtered?) people manager."
+ msg << "Some examples:"
+ msg << " • #{examples.join("\n • ")}"
+ msg.join("\n")
+ }
end
end