ASSETS.cli.config do |cnf| cnf.usecases do |cases| 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}}) options.deep_merge!(export: {options: {nice_header: true}}) if SCR.get_arg("-nice-header") case_name = SCR.get_arg("-detailed")? "to-csv-detailed" : "to-csv" session.usecases.case(case_name) end desc = "Adds a column 'ecoPortalTag' to the input CSV with the tags that the location codes map to" cases.add("-codes-to-tags-from", :other, desc, case_name: "codes-to-tags-from") do |session, options| file = SCR.get_file("-codes-to-tags-from", required: true, should_exist: true) options.deep_merge!(other: {file: {name: file, format: :csv}}) col_codes = SCR.get_arg("-column", with_param: true) options.deep_merge!(other: {file: {codes_column: col_codes}}) end desc = "Removes the landing page" cases.add("-reset-landing-page", :transform, desc, case_name: "reset-landing-page") desc = "Sets as external_id the email of the person" cases.add("-email-as-id", :transform, desc, case_name: "email-as-id") desc = "Sets the external_id to the one given in the input CSV" cases.add("-new-id-from", :sync, desc, case_name: "new-id") desc = "Sets the email of people. It won't succeed if email taken by any other user in eP" cases.add("-new-email-from", :sync, desc, case_name: "new-email") 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 the supervisor_id" cases.add("-set-supervisor-from", :sync, desc, case_name: "set-supervisor") 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 old_id = SCR.get_arg("-old-super", with_param: true) msg = "You must specify an -old-super to target whose supervisor is changing" session.logger.error(msg) exit(1) end options.deep_merge!(super: {old: old_id}) unless new_id = SCR.get_arg("-new-super", with_param: true) msg = "You must specify the -new-super id. To reset to nil the supervisor, please, specify nil." session.logger.error(msg) exit(1) end new_id = new_id == "nil"? nil : new_id options.deep_merge!(super: {new: new_id}) end desc = "Usage '-org-data-convert backup.json -restore-db-from'." desc += " Transforms an input .json file to the values of the destination environment " desc += " (names missmatch won't solve: i.e. usergroups)" cases.add("-org-data-convert", :import, desc, case_name: "org-data-convert") do |input, session, options| unless input && input.is_a?(Eco::API::Organization::People) file = SCR.get_file("-org-data-convert", required: true) input = Eco::API::Organization::People.new(JSON.parse(File.read(file))) session.logger.info("Source DB: loaded #{input.length} entries.") end if source_enviro = SCR.get_arg("-source-enviro", with_param: true) options.merge!(source_enviro: source_enviro) else session.logger.error("You need to specify a -source-enviro for the conversion to work out") exit(1) end options.deep_merge!(ignore: {missing: {policy_groups: true}}) if SCR.get_arg("-ignore-missing-policy-groups") end desc = "Restores the people manager by using a backup.json file" cases.add("-restore-db-from", :sync, desc, case_name: "restore-db") do |input, people, session, options| unless input && input.is_a?(Eco::API::Organization::People) file = SCR.get_file("-restore-db-from", required: true) input = Eco::API::Organization::People.new(JSON.parse(File.read(file))) session.logger.info("Source DB: loaded #{input.length} entries.") end options.deep_merge!(include: {delete: true}) if SCR.get_arg("-include-delete") options.deep_merge!(include: {create: true}) if SCR.get_arg("-include-create") end desc = "Re-sends invites to all filtered users that have not accepted the invite as yet" cases.add("-reinvite", :transform, desc, case_name: "reinvite") desc = "Re-sends invites to target users that have not accepted the invite as yet" cases.add("-reinvite-from", :sync, desc, case_name: "reinvite") 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 = "Removes the account of everybody that has been filtered from the people manager" cases.add("-remove-account", :transform, desc, case_name: "remove-account") desc = "Removes the people specified in the input data" cases.add("-remove-account-from", :sync, desc, case_name: "remove-account") 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" cases.add("-create-from", :sync, desc, case_name: "create") desc = "Creates people with only details" cases.add("-create-details-from", :sync, desc, case_name: "create-details") 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 = "Remaps the abilities of every user based on their usergroups mappings thereof in the org api configuration" cases.add("-refresh-abilities", :transform, desc, case_name: "refresh-abilities") desc = "Updates details and core (including supervisor) to target people" cases.add("-update-details-from", :sync, desc, case_name: "update-details") desc = "Appends the policy_group_ids column to the people with account specified in the input data" cases.add("-append-usergroups-from", :sync, desc, case_name: "append-usergroups") 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") do |input, people, session, options| options.deep_merge!(include: {email: SCR.get_arg("-include-email")}) 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") 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") end end