diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-03-03 07:59:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-03-03 07:59:29 +0000 |
commit | b25d496c246702a72f236e88f5a974282b902fa4 (patch) | |
tree | 0bbe31ff09bd42bcb160687118f7311761b9fcdb /app | |
parent | d5ca5146888f01d710091dc5ddb160cf653ffcbd (diff) | |
download | redmine-b25d496c246702a72f236e88f5a974282b902fa4.tar.gz redmine-b25d496c246702a72f236e88f5a974282b902fa4.zip |
Mail handler: adds --default-group option to add created user to one or more groups (#13340).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11522 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/group.rb | 1 | ||||
-rw-r--r-- | app/models/mail_handler.rb | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index fd0f583f7..d1b2cb966 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -30,6 +30,7 @@ class Group < Principal before_destroy :remove_references_before_destroy scope :sorted, lambda { order("#{table_name}.lastname ASC") } + scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)} safe_attributes 'name', 'user_ids', diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 0e07f1069..f85b50d73 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -97,6 +97,7 @@ class MailHandler < ActionMailer::Base if logger && logger.info logger.info "MailHandler: [#{@user.login}] account created" end + add_user_to_group(@@handler_options[:default_group]) Mailer.account_information(@user, @user.password).deliver else if logger && logger.error @@ -463,6 +464,19 @@ class MailHandler < ActionMailer::Base end end + # Adds the newly created user to default group + def add_user_to_group(default_group) + if default_group.present? + default_group.split(',').each do |group_name| + if group = Group.named(group_name).first + group.users << @user + elsif logger + logger.warn "MailHandler: could not add user to [#{group_name}], group not found" + end + end + end + end + # Removes the email body of text after the truncation configurations. def cleanup_body(body) delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} |