Skip to content

vindia/discourse_user_importer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discourse User Importer

This script will create users for a Discourse installation given a CSV file with users.

🚨 Deprecation Warning 🚨

Please be aware that this script is quite old and Discourse has evolved since then. If you want to add users to your Discourse installation automatically, please check out the following options:

There are a few different programs that help automate the process using the API. For example:

As well as various helpful threads on the Discourse forum:

Thanks to @safisher for these tips

Some features include:

  • Password is automatically generated, but your users need to reset it
  • Imported users are automatically approved by the system user (id: -1)
  • Imported users are automatically granted trust_level: 1 permissions, just like invited users
  • Users can be automatically assigned to one or more predefined groups
  • If a user already exists, but has new groups in the CSV-file, these groups will be automatically added to the existing user
  • Special task to check if usernames already exist

Caveats:

  • Error handling may be a little rough. Please check beforehand if all data in your CSV-file is correct, e.g. that the groups you want to use already exist.

Import file format

email;name;username;title;groups
Field Required Description
email Yes The email address of the user
name Yes The user's full name
username No The user's user name. If none is supplied, this will be generated from the email address.
title No The user's title, e.g. Vice President of Engineering
groups No A comma separated list of groups a user should be added to. When left empty, the user will not be added to any specific groups.

On passwords

For each user a random password is generated using SecureRandom.hex. Users are able to set their own password after importing by using the password reset function in Discourse.

Running it

Add this file to your lib/tasks and run one of the following tasks:

To check if one or more usernames already exists, without importing:

$ rake user_importer:check[/path/to/users.csv]

To import all the users in the file:

$ rake user_importer:import[/path/to/users.csv]

After running this script

Since users are automatically approved, they can log in right away after running this script. Because the user's password is an automatically generated random string, a newly imported user can only log in by generating a new password through the password reset function in Discourse. They will then receive a link to set a new password in their email.

About

A tiny script to import users from a CSV file into Discourse

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages