@@ -30,6 +30,7 class Group < Principal | |||||
30 | before_destroy :remove_references_before_destroy |
|
30 | before_destroy :remove_references_before_destroy | |
31 |
|
31 | |||
32 | scope :sorted, lambda { order("#{table_name}.lastname ASC") } |
|
32 | scope :sorted, lambda { order("#{table_name}.lastname ASC") } | |
|
33 | scope :named, lambda {|arg| where("LOWER(#{table_name}.lastname) = LOWER(?)", arg.to_s.strip)} | |||
33 |
|
34 | |||
34 | safe_attributes 'name', |
|
35 | safe_attributes 'name', | |
35 | 'user_ids', |
|
36 | 'user_ids', |
@@ -97,6 +97,7 class MailHandler < ActionMailer::Base | |||||
97 | if logger && logger.info |
|
97 | if logger && logger.info | |
98 | logger.info "MailHandler: [#{@user.login}] account created" |
|
98 | logger.info "MailHandler: [#{@user.login}] account created" | |
99 | end |
|
99 | end | |
|
100 | add_user_to_group(@@handler_options[:default_group]) | |||
100 | Mailer.account_information(@user, @user.password).deliver |
|
101 | Mailer.account_information(@user, @user.password).deliver | |
101 | else |
|
102 | else | |
102 | if logger && logger.error |
|
103 | if logger && logger.error | |
@@ -463,6 +464,19 class MailHandler < ActionMailer::Base | |||||
463 | end |
|
464 | end | |
464 | end |
|
465 | end | |
465 |
|
466 | |||
|
467 | # Adds the newly created user to default group | |||
|
468 | def add_user_to_group(default_group) | |||
|
469 | if default_group.present? | |||
|
470 | default_group.split(',').each do |group_name| | |||
|
471 | if group = Group.named(group_name).first | |||
|
472 | group.users << @user | |||
|
473 | elsif logger | |||
|
474 | logger.warn "MailHandler: could not add user to [#{group_name}], group not found" | |||
|
475 | end | |||
|
476 | end | |||
|
477 | end | |||
|
478 | end | |||
|
479 | ||||
466 | # Removes the email body of text after the truncation configurations. |
|
480 | # Removes the email body of text after the truncation configurations. | |
467 | def cleanup_body(body) |
|
481 | def cleanup_body(body) | |
468 | delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} |
|
482 | delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} |
@@ -23,9 +23,9 module Net | |||||
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | class RedmineMailHandler |
|
25 | class RedmineMailHandler | |
26 |
VERSION = '0.2. |
|
26 | VERSION = '0.2.2' | |
27 |
|
27 | |||
28 | attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate |
|
28 | attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check, :url, :key, :no_check_certificate | |
29 |
|
29 | |||
30 | def initialize |
|
30 | def initialize | |
31 | self.issue_attributes = {} |
|
31 | self.issue_attributes = {} | |
@@ -40,11 +40,6 class RedmineMailHandler | |||||
40 | opts.on("-k", "--key KEY", "Redmine API key") {|v| self.key = v} |
|
40 | opts.on("-k", "--key KEY", "Redmine API key") {|v| self.key = v} | |
41 | opts.separator("") |
|
41 | opts.separator("") | |
42 | opts.separator("General options:") |
|
42 | opts.separator("General options:") | |
43 | opts.on("--unknown-user ACTION", "how to handle emails from an unknown user", |
|
|||
44 | "ACTION can be one of the following values:", |
|
|||
45 | "* ignore: email is ignored (default)", |
|
|||
46 | "* accept: accept as anonymous user", |
|
|||
47 | "* create: create a user account") {|v| self.unknown_user = v} |
|
|||
48 | opts.on("--no-permission-check", "disable permission checking when receiving", |
|
43 | opts.on("--no-permission-check", "disable permission checking when receiving", | |
49 | "the email") {self.no_permission_check = '1'} |
|
44 | "the email") {self.no_permission_check = '1'} | |
50 | opts.on("--key-file FILE", "path to a file that contains the Redmine", |
|
45 | opts.on("--key-file FILE", "path to a file that contains the Redmine", | |
@@ -56,6 +51,15 class RedmineMailHandler | |||||
56 | opts.on("-v", "--verbose", "show extra information") {self.verbose = true} |
|
51 | opts.on("-v", "--verbose", "show extra information") {self.verbose = true} | |
57 | opts.on("-V", "--version", "show version information and exit") {puts VERSION; exit} |
|
52 | opts.on("-V", "--version", "show version information and exit") {puts VERSION; exit} | |
58 | opts.separator("") |
|
53 | opts.separator("") | |
|
54 | opts.separator("User creation options:") | |||
|
55 | opts.on("--unknown-user ACTION", "how to handle emails from an unknown user", | |||
|
56 | "ACTION can be one of the following values:", | |||
|
57 | "* ignore: email is ignored (default)", | |||
|
58 | "* accept: accept as anonymous user", | |||
|
59 | "* create: create a user account") {|v| self.unknown_user = v} | |||
|
60 | opts.on("--default-group GROUP", "add created user to GROUP (none by default)", | |||
|
61 | "GROUP can be a comma separated list of groups") { |v| self.default_group = v} | |||
|
62 | opts.separator("") | |||
59 | opts.separator("Issue attributes control options:") |
|
63 | opts.separator("Issue attributes control options:") | |
60 | opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v} |
|
64 | opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v} | |
61 | opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v} |
|
65 | opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v} | |
@@ -95,6 +99,7 class RedmineMailHandler | |||||
95 | data = { 'key' => key, 'email' => email, |
|
99 | data = { 'key' => key, 'email' => email, | |
96 | 'allow_override' => allow_override, |
|
100 | 'allow_override' => allow_override, | |
97 | 'unknown_user' => unknown_user, |
|
101 | 'unknown_user' => unknown_user, | |
|
102 | 'default_group' => default_group, | |||
98 | 'no_permission_check' => no_permission_check} |
|
103 | 'no_permission_check' => no_permission_check} | |
99 | issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value } |
|
104 | issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value } | |
100 |
|
105 |
@@ -304,6 +304,22 class MailHandlerTest < ActiveSupport::TestCase | |||||
304 | end |
|
304 | end | |
305 | end |
|
305 | end | |
306 |
|
306 | |||
|
307 | def test_created_user_should_be_added_to_groups | |||
|
308 | group1 = Group.generate! | |||
|
309 | group2 = Group.generate! | |||
|
310 | ||||
|
311 | assert_difference 'User.count' do | |||
|
312 | submit_email( | |||
|
313 | 'ticket_by_unknown_user.eml', | |||
|
314 | :issue => {:project => 'ecookbook'}, | |||
|
315 | :unknown_user => 'create', | |||
|
316 | :default_group => "#{group1.name},#{group2.name}" | |||
|
317 | ) | |||
|
318 | end | |||
|
319 | user = User.order('id DESC').first | |||
|
320 | assert_same_elements [group1, group2], user.groups | |||
|
321 | end | |||
|
322 | ||||
307 | def test_add_issue_without_from_header |
|
323 | def test_add_issue_without_from_header | |
308 | Role.anonymous.add_permission!(:add_issues) |
|
324 | Role.anonymous.add_permission!(:add_issues) | |
309 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
325 | assert_equal false, submit_email('ticket_without_from_header.eml') |
General Comments 0
You need to be logged in to leave comments.
Login now