ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength cnf.usecases do |cases| # rubocop:disable Metrics/BlockLength desc = "It exports to a CSV the (filtered) people" cases.add("-people-to-csv", :export, desc) do |people, session, options| file = SCR.get_file("-people-to-csv", required: true, should_exist: false) options.deep_merge!(export: {file: {name: file, format: :csv}}) case_name = options.dig(:export, :options, :detailed) ? "to-csv-detailed" : "to-csv" session.usecases.case(case_name) end.add_option("-nice-header", "Outputs more descriptive standard headers") do |options| options.deep_merge!(export: {options: {nice_header: true}}) end.add_option("-internal-names", "It is the most raw export. Useful to see all the data when name mappings override/overlap") do |options| options.deep_merge!(export: {options: {internal_names: true}}) end.add_option("-detailed", "Includes much more information to the file (i.e. permissions_merged abilities, preferences)") do |options| options.deep_merge!(export: {options: {detailed: true}}) end.add_option("-permissions-custom", "Used with -detailed. Adds the permissions_custom abilities") do |options| options.deep_merge!(export: {options: {permissions_custom: true}}) end.add_option("-split-schemas", "It will generate 1 file per each schema") do |options| options.deep_merge!(export: {options: {split_schemas: true}}) end desc = "Forces a change of email in the same org. It won't succeed if email taken by an org member user" cases.add("-change-email-from", :sync, desc, case_name: "change-email") desc = "Sets to -new-super the supervisor_id of the -old-super's subordinates" cases.add("-switch-supervisor", :transform, desc, case_name: "switch-supervisor") do |people, session, options| unless options[:super]&.key?(:old) msg = "You must specify an -old-super to target whose supervisor is changing" session.log(:error) { msg } exit(1) end unless options[:super]&.key?(:new) msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil." session.log(:error) { msg } exit(1) end end.add_option("-old-super", "The supervisor id to be replaced on the subordinates") do |options| if old_id = SCR.get_arg("-old-super", with_param: true) old_id = old_id == "nil"? nil : old_id options.deep_merge!(super: {old: old_id}) end end.add_option("-new-super", "The new supervisor id") do |options| if new_id = SCR.get_arg("-new-super", with_param: true) new_id = new_id == "nil"? nil : new_id options.deep_merge!(super: {new: new_id}) end end desc = "Input file dump into a CSV as is." cases.add("-entries-to-csv", :import, desc, case_name: "entries-to-csv") .add_option("-out") do |options| file = SCR.get_file("-out") options.deep_merge!(export: {file: file}) end desc = "Clears the `permissions_custom`, provided that Policy Group abilities alone apply." desc += " Please be mindfull if you use this option (there may be users that have been upgraded in ad-hoc manner)." cases.add("-clear-abilities", :transform, desc, case_name: "clear-abilities") desc = "Deletes everybody that has been filtered from the people manager" cases.add("-delete", :transform, desc, case_name: "delete") desc = "Deletes the people specified in the input data" cases.add("-delete-from", :sync, desc, case_name: "delete") desc = "Re-freshes the default_tag of users" cases.add("-set-default-tag", :transform, desc, case_name: "set-default-tag") desc = "Creates people with with details and account" as1 = "During the run, if new people is created, they are included in the People object of the current session." as1 << " This makes them available to find them (i.e. via 'external-id') before they exist" cases.add("-create-from", :sync, desc, case_name: "create") .add_option("-append-starters", as1) do |options| options.deep_merge!(people: {append_created: true}) end desc = "It just adds everybody to an update job without doing any change. If the org has policies, it will refresh" cases.add("-refresh", :transform, desc, case_name: "refresh") desc = "Updates the people specified in the input data" cases.add("-update-from", :sync, desc, case_name: "update") desc = "Does an actual transfer of USER from id|external_id account to 'destination-id' person" cases.add("-transfer-account-from", :sync, desc, case_name: "transfer-account") .add_option("-include-email", "Specifies if the email should also be moved. Otherwise it only moves the account") do |options| options.deep_merge!(include: {email: true}) end desc = "Tries to find the input entries and update them. It creates them if not found" cases.add("-upsert-from", :sync, desc, case_name: "upsert") .add_option("-append-starters", as1) do |options| options.deep_merge!(people: {append_created: true}) end desc = "It does like -upsert-from and additionally removes account and supervisor of those in people that are not in the entries (leavers)" cases.add("-hris-from", :sync, desc, case_name: "hris") .add_option("-append-starters", as1) do |options| options.deep_merge!(people: {append_created: true}) end # Ooze cases desc = "APIv2 Case: Exports the target register into a CSV" cases.add("-export-register", :other, desc, case_name: "export-register") do |session, options, usecase| file = SCR.get_file("-export-register", required: false, should_exist: false) options.deep_merge!(export: {file: {name: file || "RegisterExport.csv", format: :csv}}) unless options.dig(:source, :register_id) session.log(:error) { "You should specify the target register id" } exit(1) end end.add_option("-register-id", "Target register id") do |options| reg_id = SCR.get_arg("-register-id", with_param: true) options.deep_merge!(source: {register_id: reg_id}) end.add_option("-include-deindexed", "Tells if deindexed fields should be included") do |options| options.deep_merge!(export: {options: {include: {deindexed: true}}}) end.add_option("-include-unnamed", "Tells if unnamed fields should be included") do |options| options.deep_merge!(export: {options: {include: {unnamed: true}}}) end.add_option("-include-unhashed", "Tells if fields with no hash reference (very short label) should be included") do |options| options.deep_merge!(export: {options: {include: {unhashed: true}}}) end.add_option("-delimiter", "Sets the delimiter to be used in fields multi value") do |options| str = SCR.get_arg("-delimiter", with_param: true) options.deep_merge!(export: {options: {delimiter: str}}) end.add_option("-created-from", "Filters the register to the entries created FROM the specified date") do |options| str = SCR.get_arg("-created-from", with_param: true) date = Time.parse(str) options.deep_merge!(export: {options: {filters: {created_at: {from: date}}}}) end.add_option("-created-to", "Filters the register to the entries created up TO the specified date") do |options| str = SCR.get_arg("-created-to", with_param: true) date = Time.parse(str) options.deep_merge!(export: {options: {filters: {created_at: {to: date}}}}) end.add_option("-updated-from", "Filters the register by entries updated FROM the specified date") do |options| str = SCR.get_arg("-updated-from", with_param: true) date = Time.parse(str) options.deep_merge!(export: {options: {filters: {updated_at: {from: date}}}}) end.add_option("-updated-to", "Filters the register by entries updated up TO the specified date") do |options| str = SCR.get_arg("-updated-to", with_param: true) date = Time.parse(str) options.deep_merge!(export: {options: {filters: {updated_at: {to: date}}}}) end.add_option("-all-tags", "Filters the register to entries with ALL specified tags (| separator)") do |options| str = SCR.get_arg("-all-tags", with_param: true) tags = str.split("|") options.deep_merge!(export: {options: {filters: {tags: {all: tags}}}}) end.add_option("-any-tags", "Filters the register to entries with ANY specified tags (| separator)") do |options| str = SCR.get_arg("-all-tags", with_param: true) tags = str.split("|") options.deep_merge!(export: {options: {filters: {tags: {any: tags}}}}) end end end