How-to: Import Users by their role

How to Import Users by their role

Environment

UCS@school environment
You can only import on the master, so configuration needs to be done there

Configure the import by role

Step 1: Backup the actual config

root@UCS:~ # cp /var/lib/ucs-school-import/configs/user_import.json /var/lib/ucs-school-import/configs/user_import.json_backup20210126

Step 2: Include role import

Edit the configuration file with your preferred editor f.e. vi

root@UCS:~ # vi /var/lib/ucs-school-import/configs/user_import.json

This is an example of my configuration file:

{ 
  "include": {
    "by_role": {
      "student": "/var/lib/ucs-school-import/configs/students.json",
      "teacher": "/var/lib/ucs-school-import/configs/teachers.json"
    }
  },
  "maildomain": "mytestschool.intranet",

  "scheme": {
    "username": {
      "default": "<firstname:umlauts,alphanum>[0].<lastname:umlauts,alphanum>[0:14]<:lower>[COUNTER2]",
      "student": "<firstname:umlauts,alphanum>[0:10].<lastname:umlauts,alphanum>[0]<:lower>[COUNTER2]"
    }
  },
  "output": {
    "user_import_summary": "/var/lib/ucs-school-import/summary/%Y/%m/user_import_summary_%Y-%m-%d_%H:%M:%S.csv",
    "new_user_passwords": "/var/lib/ucs-school-import/passwords/%Y/%m/new_user_passwords_%Y-%m-%d_%H:%M:%S.csv"
  },
  "password_length": 8
}

Important is the first part of configuration file; the include statement.

Step 3: Create role files

Create the configuration file with your preferred editor f.e. vi

root@UCS:~ # vi /var/lib/ucs-school-import/configs/students.json

This is an example of my students.json:

{  
  "csv": {
    "allowed_missing_columns": ["Mobil","Telefon","serviceprovider","networkAccess"],
    "header_lines": 1,
    "incell-delimiter": {
      "default": ","
    },
    "mapping": {
      "Nummer": "record_uid",
      "Quelle": "source_uid",
      "Vorname": "firstname",
      "Nachname": "lastname",
      "Geburtsdatum": "birthday",
      "Telefon": "phone",
      "disabled": "disabled",
      "Schule": "school",
      "Klasse": "school_classes"
    }
  },

  "scheme": {
    "nextcloudQuota": "2GB"
  }
}

In this way you can import teacher and students with different settings.
You can configure all UDM attributes. You find the names, that differ from the ldap names by executing

python -c 'from univention.admin.handlers.users.user import mapping;print("\n".join(map("{0[0]:>30s} {0[1][0]:<30s}".format, sorted(mapping._map.items()))))'

on the left hand of the output.

Step 3: Activate the hook

you need to copy the hook ext_config_dep_on_role.py from /usr/share/ucs-school-import/pyhooks-available/ to /usr/share/ucs-school-import/pyhooks/

root@UCS:~ # cp -p /usr/share/ucs-school-import/pyhooks-available/ext_config_dep_on_role.py /usr/share/ucs-school-import/pyhooks/ext_config_dep_on_role.py
3 Likes
Mastodon