Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import CSV users into redmine
# csv_import_users.rake
# Bulk user provisioning for Redmine using CSV file
# Copyright (C) 2010 - Adrian Perez <adrianperez.deb@gmail.com>
# Licensed under GPL 3.
require 'csv'
namespace :redmine do
task :csv_import_users => :environment do
@first_row = true
$PROJECT = Project.find_by_identifier('myproject')
$GROUP = Group.find_by_lastname('mygroup')
$PASSWORD = 'mypassword'
CSV.open('~/my_users.csv', 'r') do |row|
if not @first_row
username = row[0]
firstname = row[1]
lastname = row[2]
email = row[3]
puts "Creating user '#{username}'..."
@user = User.new
@user.login = username
@user.firstname = firstname
@user.lastname = lastname
@user.password = $PASSWORD
@user.password_confirmation = $PASSWORD
@user.mail = email
@user.language = 'tr'
# add to project and group
@user.groups << $GROUP
@user.save!
# TODO: add user role
end
@first_row = nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment