Import regular admins from a CSV file

Gobierto Admin module implements a Rake task to import administrators from a CSV file and assign them to groups.

Loading CSV data files

Log into the server where Gobierto is hosted (you can use it even in your computer for the development environment) and call this rake task with the site domain and csv file path as arguments:

rails gobierto_admin:import_admins[site_domain,csv_path,send_invitation]

Arguments

  • site_domain: The domain of the site where admins will be imported (e.g., madrid.gobierto.es)
  • csv_path: The path to the CSV file containing the admin data
  • send_invitation: (optional) If set to true, admins will be created via invitation email. Defaults to false, which creates admin records directly without sending an invitation

CSV File Format

The CSV file must contain the following columns:

  • Email: Column containing the admin's email address (required)
  • Name: Column containing the admin's name (required)
  • Groups: Column containing comma-separated group names to assign to the admin (required)

Example CSV file:

Email,Name,Groups
[email protected],John Doe,"Editors, Managers"
[email protected],Jane Smith,Editors
[email protected],Bob Johnson,"Managers, Reviewers"

Important Notes

  • Group names must match exactly with groups defined in the site. The task will search for groups by name in the specified site.
  • If a group name is not found in the site, a warning message will be displayed: Group "[group_name]" not found in site [site_domain] and that group will be skipped for that admin.
  • Admins with an email that already exists in the system will be skipped. A message will be displayed: Skipping already existing admin with email [email]...
  • The task will create the admin, associate them with the site, and assign the valid groups found.
  • At the end, the task returns a summary with the number of admins created: [END] Created [loaded] users of [count]

Error Handling

The task will exit with an error if:

  • The site domain is not found: [ERROR] No site found for domain: [site_domain]
  • The CSV file path is invalid or the file doesn't exist: [ERROR] No CSV file found: [csv_path]