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
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)}
end
class RedmineMailHandler
- VERSION = '0.2.1'
+ VERSION = '0.2.2'
- attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
+ attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check, :url, :key, :no_check_certificate
def initialize
self.issue_attributes = {}
opts.on("-k", "--key KEY", "Redmine API key") {|v| self.key = v}
opts.separator("")
opts.separator("General options:")
- opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
- "ACTION can be one of the following values:",
- "* ignore: email is ignored (default)",
- "* accept: accept as anonymous user",
- "* create: create a user account") {|v| self.unknown_user = v}
opts.on("--no-permission-check", "disable permission checking when receiving",
"the email") {self.no_permission_check = '1'}
opts.on("--key-file FILE", "path to a file that contains the Redmine",
opts.on("-v", "--verbose", "show extra information") {self.verbose = true}
opts.on("-V", "--version", "show version information and exit") {puts VERSION; exit}
opts.separator("")
+ opts.separator("User creation options:")
+ opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
+ "ACTION can be one of the following values:",
+ "* ignore: email is ignored (default)",
+ "* accept: accept as anonymous user",
+ "* create: create a user account") {|v| self.unknown_user = v}
+ opts.on("--default-group GROUP", "add created user to GROUP (none by default)",
+ "GROUP can be a comma separated list of groups") { |v| self.default_group = v}
+ opts.separator("")
opts.separator("Issue attributes control options:")
opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v}
opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v}
data = { 'key' => key, 'email' => email,
'allow_override' => allow_override,
'unknown_user' => unknown_user,
+ 'default_group' => default_group,
'no_permission_check' => no_permission_check}
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
end
end
+ def test_created_user_should_be_added_to_groups
+ group1 = Group.generate!
+ group2 = Group.generate!
+
+ assert_difference 'User.count' do
+ submit_email(
+ 'ticket_by_unknown_user.eml',
+ :issue => {:project => 'ecookbook'},
+ :unknown_user => 'create',
+ :default_group => "#{group1.name},#{group2.name}"
+ )
+ end
+ user = User.order('id DESC').first
+ assert_same_elements [group1, group2], user.groups
+ end
+
def test_add_issue_without_from_header
Role.anonymous.add_permission!(:add_issues)
assert_equal false, submit_email('ticket_without_from_header.eml')