Feature #8643 ยป mail-create-group.diff
app/models/mail_handler.rb (working copy) | ||
---|---|---|
65 | 65 |
if @user |
66 | 66 |
logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info |
67 | 67 |
Mailer.deliver_account_information(@user, @user.password) |
68 |
if !@@handler_options[:unknown_user_group].nil? |
|
69 |
# Fetch specified group. |
|
70 |
@group = Group.find_by_name(@@handler_options[:unknown_user_group]) |
|
71 |
if !@group.nil? |
|
72 |
# Attach the group to user. |
|
73 |
@group.users << @user |
|
74 |
end |
|
75 |
end |
|
68 | 76 |
else |
69 | 77 |
logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error |
70 | 78 |
return false |
app/models/group.rb (working copy) | ||
---|---|---|
24 | 24 |
validates_presence_of :lastname |
25 | 25 |
validates_uniqueness_of :lastname, :case_sensitive => false |
26 | 26 |
validates_length_of :lastname, :maximum => 30 |
27 | ||
28 |
# Fetch group name. |
|
29 |
def self.find_by_name(lastname) |
|
30 |
find(:first, :conditions => ["LOWER(lastname) = ?", lastname.to_s.downcase]) |
|
31 |
end |
|
27 | 32 |
|
28 | 33 |
def to_s |
29 | 34 |
lastname.to_s |
extra/mail_handler/rdm-mailhandler.rb (working copy) | ||
---|---|---|
20 | 20 |
# ignore: email is ignored (default) |
21 | 21 |
# accept: accept as anonymous user |
22 | 22 |
# create: create a user account |
23 |
# --unknown-user-group=.... name of new user primary group |
|
23 | 24 |
# --no-permission-check disable permission checking when receiving |
24 | 25 |
# the email |
25 | 26 |
# -h, --help show this help |
... | ... | |
72 | 73 |
class RedmineMailHandler |
73 | 74 |
VERSION = '0.1' |
74 | 75 |
|
75 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key |
|
76 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :unknown_user_group, :no_permission_check, :url, :key
|
|
76 | 77 | |
77 | 78 |
def initialize |
78 | 79 |
self.issue_attributes = {} |
... | ... | |
90 | 91 |
[ '--priority', GetoptLong::REQUIRED_ARGUMENT], |
91 | 92 |
[ '--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT], |
92 | 93 |
[ '--unknown-user', GetoptLong::REQUIRED_ARGUMENT], |
94 |
[ '--unknown-user-group', GetoptLong::REQUIRED_ARGUMENT], |
|
93 | 95 |
[ '--no-permission-check', GetoptLong::NO_ARGUMENT] |
94 | 96 |
) |
95 | 97 | |
... | ... | |
111 | 113 |
self.allow_override = arg.dup |
112 | 114 |
when '--unknown-user' |
113 | 115 |
self.unknown_user = arg.dup |
116 |
when '--unknown-user-group' |
|
117 |
self.unknown_user_group = arg.dup |
|
114 | 118 |
when '--no-permission-check' |
115 | 119 |
self.no_permission_check = '1' |
116 | 120 |
end |
... | ... | |
127 | 131 |
data = { 'key' => key, 'email' => email, |
128 | 132 |
'allow_override' => allow_override, |
129 | 133 |
'unknown_user' => unknown_user, |
134 |
'unknown_user_group' => unknown_user_group, |
|
130 | 135 |
'no_permission_check' => no_permission_check} |
131 | 136 |
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value } |
132 | 137 |
|