Problem
When creating user accounts via the command:
/usr/share/ucs-school-import/scripts/ucs-school-user-import
the user_import.json
configuration file can be used to define the path of the output file for the user passwords. For example:
"output": {
"new_user_passwords": "/var/lib/ucs-school-import/summary/%Y/passwords_%Y%m%d_%H:%M:%S.csv"
}
The generated CSV file contains the following columns per default:
"username","password","role","lastname","firstname","schools","classes"
The question is: How can this output be extended to include the user’s email address?
Solution
The script responsible for writing the CSV export is located here:
/usr/lib/python3/dist-packages/ucsschool/importer/writer/new_user_password_csv_exporter.py
In this file, the list of fields is defined in two places:
field_names
→ defines the column headers.- The return dictionary → defines the values written to the CSV.
To add the email address, extend both sections with your desired field.
For example:
field_names = ("username", "password", "role", "lastname", "firstname", "schools", "classes", "email")
[...]
return {
"username": user.name,
"password": user.password,
"role": user.role_string,
"lastname": user.lastname,
"firstname": user.firstname,
"schools": ",".join(user.schools),
"classes": user.school_classes_as_str,
"email": user.email,
}
After this modification, the exported CSV file will include an additional column email
containing the user’s email address.