@@ -0,0 +1,2 | |||||
|
1 | <p><%= l(:notice_account_activated) %></p> | |||
|
2 | <p><%= l(:label_login) %>: <%= link_to @login_url, @login_url %></p> |
@@ -1,104 +1,108 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class UsersController < ApplicationController |
|
18 | class UsersController < ApplicationController | |
19 | before_filter :require_admin |
|
19 | before_filter :require_admin | |
20 |
|
20 | |||
21 | helper :sort |
|
21 | helper :sort | |
22 | include SortHelper |
|
22 | include SortHelper | |
23 | helper :custom_fields |
|
23 | helper :custom_fields | |
24 | include CustomFieldsHelper |
|
24 | include CustomFieldsHelper | |
25 |
|
25 | |||
26 | def index |
|
26 | def index | |
27 | list |
|
27 | list | |
28 | render :action => 'list' unless request.xhr? |
|
28 | render :action => 'list' unless request.xhr? | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def list |
|
31 | def list | |
32 | sort_init 'login', 'asc' |
|
32 | sort_init 'login', 'asc' | |
33 | sort_update %w(login firstname lastname mail admin created_on last_login_on) |
|
33 | sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
34 |
|
34 | |||
35 | @status = params[:status] ? params[:status].to_i : 1 |
|
35 | @status = params[:status] ? params[:status].to_i : 1 | |
36 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) |
|
36 | c = ARCondition.new(@status == 0 ? "status <> 0" : ["status = ?", @status]) | |
37 |
|
37 | |||
38 | unless params[:name].blank? |
|
38 | unless params[:name].blank? | |
39 | name = "%#{params[:name].strip.downcase}%" |
|
39 | name = "%#{params[:name].strip.downcase}%" | |
40 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name] |
|
40 | c << ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", name, name, name] | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | @user_count = User.count(:conditions => c.conditions) |
|
43 | @user_count = User.count(:conditions => c.conditions) | |
44 | @user_pages = Paginator.new self, @user_count, |
|
44 | @user_pages = Paginator.new self, @user_count, | |
45 | per_page_option, |
|
45 | per_page_option, | |
46 | params['page'] |
|
46 | params['page'] | |
47 | @users = User.find :all,:order => sort_clause, |
|
47 | @users = User.find :all,:order => sort_clause, | |
48 | :conditions => c.conditions, |
|
48 | :conditions => c.conditions, | |
49 | :limit => @user_pages.items_per_page, |
|
49 | :limit => @user_pages.items_per_page, | |
50 | :offset => @user_pages.current.offset |
|
50 | :offset => @user_pages.current.offset | |
51 |
|
51 | |||
52 | render :action => "list", :layout => false if request.xhr? |
|
52 | render :action => "list", :layout => false if request.xhr? | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def add |
|
55 | def add | |
56 | if request.get? |
|
56 | if request.get? | |
57 | @user = User.new(:language => Setting.default_language) |
|
57 | @user = User.new(:language => Setting.default_language) | |
58 | else |
|
58 | else | |
59 | @user = User.new(params[:user]) |
|
59 | @user = User.new(params[:user]) | |
60 | @user.admin = params[:user][:admin] || false |
|
60 | @user.admin = params[:user][:admin] || false | |
61 | @user.login = params[:user][:login] |
|
61 | @user.login = params[:user][:login] | |
62 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id |
|
62 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id | |
63 | if @user.save |
|
63 | if @user.save | |
64 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] |
|
64 | Mailer.deliver_account_information(@user, params[:password]) if params[:send_information] | |
65 | flash[:notice] = l(:notice_successful_create) |
|
65 | flash[:notice] = l(:notice_successful_create) | |
66 | redirect_to :action => 'list' |
|
66 | redirect_to :action => 'list' | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end | |
69 | @auth_sources = AuthSource.find(:all) |
|
69 | @auth_sources = AuthSource.find(:all) | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def edit |
|
72 | def edit | |
73 | @user = User.find(params[:id]) |
|
73 | @user = User.find(params[:id]) | |
74 | if request.post? |
|
74 | if request.post? | |
75 | @user.admin = params[:user][:admin] if params[:user][:admin] |
|
75 | @user.admin = params[:user][:admin] if params[:user][:admin] | |
76 | @user.login = params[:user][:login] if params[:user][:login] |
|
76 | @user.login = params[:user][:login] if params[:user][:login] | |
77 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id |
|
77 | @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id | |
78 |
|
|
78 | @user.attributes = params[:user] | |
|
79 | # Was the account actived ? (do it before User#save clears the change) | |||
|
80 | was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |||
|
81 | if @user.save | |||
|
82 | Mailer.deliver_account_activated(@user) if was_activated | |||
79 | flash[:notice] = l(:notice_successful_update) |
|
83 | flash[:notice] = l(:notice_successful_update) | |
80 | # Give a string to redirect_to otherwise it would use status param as the response code |
|
84 | # Give a string to redirect_to otherwise it would use status param as the response code | |
81 | redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page])) |
|
85 | redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page])) | |
82 | end |
|
86 | end | |
83 | end |
|
87 | end | |
84 | @auth_sources = AuthSource.find(:all) |
|
88 | @auth_sources = AuthSource.find(:all) | |
85 | @roles = Role.find_all_givable |
|
89 | @roles = Role.find_all_givable | |
86 | @projects = Project.active.find(:all, :order => 'lft') |
|
90 | @projects = Project.active.find(:all, :order => 'lft') | |
87 | @membership ||= Member.new |
|
91 | @membership ||= Member.new | |
88 | @memberships = @user.memberships |
|
92 | @memberships = @user.memberships | |
89 | end |
|
93 | end | |
90 |
|
94 | |||
91 | def edit_membership |
|
95 | def edit_membership | |
92 | @user = User.find(params[:id]) |
|
96 | @user = User.find(params[:id]) | |
93 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user) |
|
97 | @membership = params[:membership_id] ? Member.find(params[:membership_id]) : Member.new(:user => @user) | |
94 | @membership.attributes = params[:membership] |
|
98 | @membership.attributes = params[:membership] | |
95 | @membership.save if request.post? |
|
99 | @membership.save if request.post? | |
96 | redirect_to :action => 'edit', :id => @user, :tab => 'memberships' |
|
100 | redirect_to :action => 'edit', :id => @user, :tab => 'memberships' | |
97 | end |
|
101 | end | |
98 |
|
102 | |||
99 | def destroy_membership |
|
103 | def destroy_membership | |
100 | @user = User.find(params[:id]) |
|
104 | @user = User.find(params[:id]) | |
101 | Member.find(params[:membership_id]).destroy if request.post? |
|
105 | Member.find(params[:membership_id]).destroy if request.post? | |
102 | redirect_to :action => 'edit', :id => @user, :tab => 'memberships' |
|
106 | redirect_to :action => 'edit', :id => @user, :tab => 'memberships' | |
103 | end |
|
107 | end | |
104 | end |
|
108 | end |
@@ -1,297 +1,306 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Mailer < ActionMailer::Base |
|
18 | class Mailer < ActionMailer::Base | |
19 | helper :application |
|
19 | helper :application | |
20 | helper :issues |
|
20 | helper :issues | |
21 | helper :custom_fields |
|
21 | helper :custom_fields | |
22 |
|
22 | |||
23 | include ActionController::UrlWriter |
|
23 | include ActionController::UrlWriter | |
24 |
|
24 | |||
25 | def issue_add(issue) |
|
25 | def issue_add(issue) | |
26 | redmine_headers 'Project' => issue.project.identifier, |
|
26 | redmine_headers 'Project' => issue.project.identifier, | |
27 | 'Issue-Id' => issue.id, |
|
27 | 'Issue-Id' => issue.id, | |
28 | 'Issue-Author' => issue.author.login |
|
28 | 'Issue-Author' => issue.author.login | |
29 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
29 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to | |
30 | message_id issue |
|
30 | message_id issue | |
31 | recipients issue.recipients |
|
31 | recipients issue.recipients | |
32 | cc(issue.watcher_recipients - @recipients) |
|
32 | cc(issue.watcher_recipients - @recipients) | |
33 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
33 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" | |
34 | body :issue => issue, |
|
34 | body :issue => issue, | |
35 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
35 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def issue_edit(journal) |
|
38 | def issue_edit(journal) | |
39 | issue = journal.journalized |
|
39 | issue = journal.journalized | |
40 | redmine_headers 'Project' => issue.project.identifier, |
|
40 | redmine_headers 'Project' => issue.project.identifier, | |
41 | 'Issue-Id' => issue.id, |
|
41 | 'Issue-Id' => issue.id, | |
42 | 'Issue-Author' => issue.author.login |
|
42 | 'Issue-Author' => issue.author.login | |
43 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
43 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to | |
44 | message_id journal |
|
44 | message_id journal | |
45 | references issue |
|
45 | references issue | |
46 | @author = journal.user |
|
46 | @author = journal.user | |
47 | recipients issue.recipients |
|
47 | recipients issue.recipients | |
48 | # Watchers in cc |
|
48 | # Watchers in cc | |
49 | cc(issue.watcher_recipients - @recipients) |
|
49 | cc(issue.watcher_recipients - @recipients) | |
50 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
50 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " | |
51 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
51 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') | |
52 | s << issue.subject |
|
52 | s << issue.subject | |
53 | subject s |
|
53 | subject s | |
54 | body :issue => issue, |
|
54 | body :issue => issue, | |
55 | :journal => journal, |
|
55 | :journal => journal, | |
56 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
56 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def reminder(user, issues, days) |
|
59 | def reminder(user, issues, days) | |
60 | set_language_if_valid user.language |
|
60 | set_language_if_valid user.language | |
61 | recipients user.mail |
|
61 | recipients user.mail | |
62 | subject l(:mail_subject_reminder, issues.size) |
|
62 | subject l(:mail_subject_reminder, issues.size) | |
63 | body :issues => issues, |
|
63 | body :issues => issues, | |
64 | :days => days, |
|
64 | :days => days, | |
65 | :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc') |
|
65 | :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc') | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def document_added(document) |
|
68 | def document_added(document) | |
69 | redmine_headers 'Project' => document.project.identifier |
|
69 | redmine_headers 'Project' => document.project.identifier | |
70 | recipients document.project.recipients |
|
70 | recipients document.project.recipients | |
71 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
71 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" | |
72 | body :document => document, |
|
72 | body :document => document, | |
73 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) |
|
73 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def attachments_added(attachments) |
|
76 | def attachments_added(attachments) | |
77 | container = attachments.first.container |
|
77 | container = attachments.first.container | |
78 | added_to = '' |
|
78 | added_to = '' | |
79 | added_to_url = '' |
|
79 | added_to_url = '' | |
80 | case container.class.name |
|
80 | case container.class.name | |
81 | when 'Project' |
|
81 | when 'Project' | |
82 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) |
|
82 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) | |
83 | added_to = "#{l(:label_project)}: #{container}" |
|
83 | added_to = "#{l(:label_project)}: #{container}" | |
84 | when 'Version' |
|
84 | when 'Version' | |
85 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) |
|
85 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) | |
86 | added_to = "#{l(:label_version)}: #{container.name}" |
|
86 | added_to = "#{l(:label_version)}: #{container.name}" | |
87 | when 'Document' |
|
87 | when 'Document' | |
88 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
88 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) | |
89 | added_to = "#{l(:label_document)}: #{container.title}" |
|
89 | added_to = "#{l(:label_document)}: #{container.title}" | |
90 | end |
|
90 | end | |
91 | redmine_headers 'Project' => container.project.identifier |
|
91 | redmine_headers 'Project' => container.project.identifier | |
92 | recipients container.project.recipients |
|
92 | recipients container.project.recipients | |
93 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
93 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" | |
94 | body :attachments => attachments, |
|
94 | body :attachments => attachments, | |
95 | :added_to => added_to, |
|
95 | :added_to => added_to, | |
96 | :added_to_url => added_to_url |
|
96 | :added_to_url => added_to_url | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def news_added(news) |
|
99 | def news_added(news) | |
100 | redmine_headers 'Project' => news.project.identifier |
|
100 | redmine_headers 'Project' => news.project.identifier | |
101 | message_id news |
|
101 | message_id news | |
102 | recipients news.project.recipients |
|
102 | recipients news.project.recipients | |
103 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
103 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
104 | body :news => news, |
|
104 | body :news => news, | |
105 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
105 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def message_posted(message, recipients) |
|
108 | def message_posted(message, recipients) | |
109 | redmine_headers 'Project' => message.project.identifier, |
|
109 | redmine_headers 'Project' => message.project.identifier, | |
110 | 'Topic-Id' => (message.parent_id || message.id) |
|
110 | 'Topic-Id' => (message.parent_id || message.id) | |
111 | message_id message |
|
111 | message_id message | |
112 | references message.parent unless message.parent.nil? |
|
112 | references message.parent unless message.parent.nil? | |
113 | recipients(recipients) |
|
113 | recipients(recipients) | |
114 | subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" |
|
114 | subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" | |
115 | body :message => message, |
|
115 | body :message => message, | |
116 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) |
|
116 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def account_information(user, password) |
|
119 | def account_information(user, password) | |
120 | set_language_if_valid user.language |
|
120 | set_language_if_valid user.language | |
121 | recipients user.mail |
|
121 | recipients user.mail | |
122 | subject l(:mail_subject_register, Setting.app_title) |
|
122 | subject l(:mail_subject_register, Setting.app_title) | |
123 | body :user => user, |
|
123 | body :user => user, | |
124 | :password => password, |
|
124 | :password => password, | |
125 | :login_url => url_for(:controller => 'account', :action => 'login') |
|
125 | :login_url => url_for(:controller => 'account', :action => 'login') | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def account_activation_request(user) |
|
128 | def account_activation_request(user) | |
129 | # Send the email to all active administrators |
|
129 | # Send the email to all active administrators | |
130 | recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact |
|
130 | recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact | |
131 | subject l(:mail_subject_account_activation_request, Setting.app_title) |
|
131 | subject l(:mail_subject_account_activation_request, Setting.app_title) | |
132 | body :user => user, |
|
132 | body :user => user, | |
133 | :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') |
|
133 | :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
|
136 | # A registered user's account was activated by an administrator | |||
|
137 | def account_activated(user) | |||
|
138 | set_language_if_valid user.language | |||
|
139 | recipients user.mail | |||
|
140 | subject l(:mail_subject_register, Setting.app_title) | |||
|
141 | body :user => user, | |||
|
142 | :login_url => url_for(:controller => 'account', :action => 'login') | |||
|
143 | end | |||
|
144 | ||||
136 | def lost_password(token) |
|
145 | def lost_password(token) | |
137 | set_language_if_valid(token.user.language) |
|
146 | set_language_if_valid(token.user.language) | |
138 | recipients token.user.mail |
|
147 | recipients token.user.mail | |
139 | subject l(:mail_subject_lost_password, Setting.app_title) |
|
148 | subject l(:mail_subject_lost_password, Setting.app_title) | |
140 | body :token => token, |
|
149 | body :token => token, | |
141 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
150 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) | |
142 | end |
|
151 | end | |
143 |
|
152 | |||
144 | def register(token) |
|
153 | def register(token) | |
145 | set_language_if_valid(token.user.language) |
|
154 | set_language_if_valid(token.user.language) | |
146 | recipients token.user.mail |
|
155 | recipients token.user.mail | |
147 | subject l(:mail_subject_register, Setting.app_title) |
|
156 | subject l(:mail_subject_register, Setting.app_title) | |
148 | body :token => token, |
|
157 | body :token => token, | |
149 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
158 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) | |
150 | end |
|
159 | end | |
151 |
|
160 | |||
152 | def test(user) |
|
161 | def test(user) | |
153 | set_language_if_valid(user.language) |
|
162 | set_language_if_valid(user.language) | |
154 | recipients user.mail |
|
163 | recipients user.mail | |
155 | subject 'Redmine test' |
|
164 | subject 'Redmine test' | |
156 | body :url => url_for(:controller => 'welcome') |
|
165 | body :url => url_for(:controller => 'welcome') | |
157 | end |
|
166 | end | |
158 |
|
167 | |||
159 | # Overrides default deliver! method to prevent from sending an email |
|
168 | # Overrides default deliver! method to prevent from sending an email | |
160 | # with no recipient, cc or bcc |
|
169 | # with no recipient, cc or bcc | |
161 | def deliver!(mail = @mail) |
|
170 | def deliver!(mail = @mail) | |
162 | return false if (recipients.nil? || recipients.empty?) && |
|
171 | return false if (recipients.nil? || recipients.empty?) && | |
163 | (cc.nil? || cc.empty?) && |
|
172 | (cc.nil? || cc.empty?) && | |
164 | (bcc.nil? || bcc.empty?) |
|
173 | (bcc.nil? || bcc.empty?) | |
165 |
|
174 | |||
166 | # Set Message-Id and References |
|
175 | # Set Message-Id and References | |
167 | if @message_id_object |
|
176 | if @message_id_object | |
168 | mail.message_id = self.class.message_id_for(@message_id_object) |
|
177 | mail.message_id = self.class.message_id_for(@message_id_object) | |
169 | end |
|
178 | end | |
170 | if @references_objects |
|
179 | if @references_objects | |
171 | mail.references = @references_objects.collect {|o| self.class.message_id_for(o)} |
|
180 | mail.references = @references_objects.collect {|o| self.class.message_id_for(o)} | |
172 | end |
|
181 | end | |
173 | super(mail) |
|
182 | super(mail) | |
174 | end |
|
183 | end | |
175 |
|
184 | |||
176 | # Sends reminders to issue assignees |
|
185 | # Sends reminders to issue assignees | |
177 | # Available options: |
|
186 | # Available options: | |
178 | # * :days => how many days in the future to remind about (defaults to 7) |
|
187 | # * :days => how many days in the future to remind about (defaults to 7) | |
179 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
188 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) | |
180 | # * :project => id or identifier of project to process (defaults to all projects) |
|
189 | # * :project => id or identifier of project to process (defaults to all projects) | |
181 | def self.reminders(options={}) |
|
190 | def self.reminders(options={}) | |
182 | days = options[:days] || 7 |
|
191 | days = options[:days] || 7 | |
183 | project = options[:project] ? Project.find(options[:project]) : nil |
|
192 | project = options[:project] ? Project.find(options[:project]) : nil | |
184 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
193 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil | |
185 |
|
194 | |||
186 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] |
|
195 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] | |
187 | s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" |
|
196 | s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" | |
188 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" |
|
197 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" | |
189 | s << "#{Issue.table_name}.project_id = #{project.id}" if project |
|
198 | s << "#{Issue.table_name}.project_id = #{project.id}" if project | |
190 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker |
|
199 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker | |
191 |
|
200 | |||
192 | issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker], |
|
201 | issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker], | |
193 | :conditions => s.conditions |
|
202 | :conditions => s.conditions | |
194 | ).group_by(&:assigned_to) |
|
203 | ).group_by(&:assigned_to) | |
195 | issues_by_assignee.each do |assignee, issues| |
|
204 | issues_by_assignee.each do |assignee, issues| | |
196 | deliver_reminder(assignee, issues, days) unless assignee.nil? |
|
205 | deliver_reminder(assignee, issues, days) unless assignee.nil? | |
197 | end |
|
206 | end | |
198 | end |
|
207 | end | |
199 |
|
208 | |||
200 | private |
|
209 | private | |
201 | def initialize_defaults(method_name) |
|
210 | def initialize_defaults(method_name) | |
202 | super |
|
211 | super | |
203 | set_language_if_valid Setting.default_language |
|
212 | set_language_if_valid Setting.default_language | |
204 | from Setting.mail_from |
|
213 | from Setting.mail_from | |
205 |
|
214 | |||
206 | # URL options |
|
215 | # URL options | |
207 | h = Setting.host_name |
|
216 | h = Setting.host_name | |
208 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? |
|
217 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? | |
209 | default_url_options[:host] = h |
|
218 | default_url_options[:host] = h | |
210 | default_url_options[:protocol] = Setting.protocol |
|
219 | default_url_options[:protocol] = Setting.protocol | |
211 |
|
220 | |||
212 | # Common headers |
|
221 | # Common headers | |
213 | headers 'X-Mailer' => 'Redmine', |
|
222 | headers 'X-Mailer' => 'Redmine', | |
214 | 'X-Redmine-Host' => Setting.host_name, |
|
223 | 'X-Redmine-Host' => Setting.host_name, | |
215 | 'X-Redmine-Site' => Setting.app_title |
|
224 | 'X-Redmine-Site' => Setting.app_title | |
216 | end |
|
225 | end | |
217 |
|
226 | |||
218 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') |
|
227 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') | |
219 | def redmine_headers(h) |
|
228 | def redmine_headers(h) | |
220 | h.each { |k,v| headers["X-Redmine-#{k}"] = v } |
|
229 | h.each { |k,v| headers["X-Redmine-#{k}"] = v } | |
221 | end |
|
230 | end | |
222 |
|
231 | |||
223 | # Overrides the create_mail method |
|
232 | # Overrides the create_mail method | |
224 | def create_mail |
|
233 | def create_mail | |
225 | # Removes the current user from the recipients and cc |
|
234 | # Removes the current user from the recipients and cc | |
226 | # if he doesn't want to receive notifications about what he does |
|
235 | # if he doesn't want to receive notifications about what he does | |
227 | @author ||= User.current |
|
236 | @author ||= User.current | |
228 | if @author.pref[:no_self_notified] |
|
237 | if @author.pref[:no_self_notified] | |
229 | recipients.delete(@author.mail) if recipients |
|
238 | recipients.delete(@author.mail) if recipients | |
230 | cc.delete(@author.mail) if cc |
|
239 | cc.delete(@author.mail) if cc | |
231 | end |
|
240 | end | |
232 | # Blind carbon copy recipients |
|
241 | # Blind carbon copy recipients | |
233 | if Setting.bcc_recipients? |
|
242 | if Setting.bcc_recipients? | |
234 | bcc([recipients, cc].flatten.compact.uniq) |
|
243 | bcc([recipients, cc].flatten.compact.uniq) | |
235 | recipients [] |
|
244 | recipients [] | |
236 | cc [] |
|
245 | cc [] | |
237 | end |
|
246 | end | |
238 | super |
|
247 | super | |
239 | end |
|
248 | end | |
240 |
|
249 | |||
241 | # Renders a message with the corresponding layout |
|
250 | # Renders a message with the corresponding layout | |
242 | def render_message(method_name, body) |
|
251 | def render_message(method_name, body) | |
243 | layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' |
|
252 | layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' | |
244 | body[:content_for_layout] = render(:file => method_name, :body => body) |
|
253 | body[:content_for_layout] = render(:file => method_name, :body => body) | |
245 | ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true) |
|
254 | ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true) | |
246 | end |
|
255 | end | |
247 |
|
256 | |||
248 | # for the case of plain text only |
|
257 | # for the case of plain text only | |
249 | def body(*params) |
|
258 | def body(*params) | |
250 | value = super(*params) |
|
259 | value = super(*params) | |
251 | if Setting.plain_text_mail? |
|
260 | if Setting.plain_text_mail? | |
252 | templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}") |
|
261 | templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}") | |
253 | unless String === @body or templates.empty? |
|
262 | unless String === @body or templates.empty? | |
254 | template = File.basename(templates.first) |
|
263 | template = File.basename(templates.first) | |
255 | @body[:content_for_layout] = render(:file => template, :body => @body) |
|
264 | @body[:content_for_layout] = render(:file => template, :body => @body) | |
256 | @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true) |
|
265 | @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true) | |
257 | return @body |
|
266 | return @body | |
258 | end |
|
267 | end | |
259 | end |
|
268 | end | |
260 | return value |
|
269 | return value | |
261 | end |
|
270 | end | |
262 |
|
271 | |||
263 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) |
|
272 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) | |
264 | def self.controller_path |
|
273 | def self.controller_path | |
265 | '' |
|
274 | '' | |
266 | end unless respond_to?('controller_path') |
|
275 | end unless respond_to?('controller_path') | |
267 |
|
276 | |||
268 | # Returns a predictable Message-Id for the given object |
|
277 | # Returns a predictable Message-Id for the given object | |
269 | def self.message_id_for(object) |
|
278 | def self.message_id_for(object) | |
270 | # id + timestamp should reduce the odds of a collision |
|
279 | # id + timestamp should reduce the odds of a collision | |
271 | # as far as we don't send multiple emails for the same object |
|
280 | # as far as we don't send multiple emails for the same object | |
272 | hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{object.created_on.strftime("%Y%m%d%H%M%S")}" |
|
281 | hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{object.created_on.strftime("%Y%m%d%H%M%S")}" | |
273 | host = Setting.mail_from.to_s.gsub(%r{^.*@}, '') |
|
282 | host = Setting.mail_from.to_s.gsub(%r{^.*@}, '') | |
274 | host = "#{::Socket.gethostname}.redmine" if host.empty? |
|
283 | host = "#{::Socket.gethostname}.redmine" if host.empty? | |
275 | "<#{hash}@#{host}>" |
|
284 | "<#{hash}@#{host}>" | |
276 | end |
|
285 | end | |
277 |
|
286 | |||
278 | private |
|
287 | private | |
279 |
|
288 | |||
280 | def message_id(object) |
|
289 | def message_id(object) | |
281 | @message_id_object = object |
|
290 | @message_id_object = object | |
282 | end |
|
291 | end | |
283 |
|
292 | |||
284 | def references(object) |
|
293 | def references(object) | |
285 | @references_objects ||= [] |
|
294 | @references_objects ||= [] | |
286 | @references_objects << object |
|
295 | @references_objects << object | |
287 | end |
|
296 | end | |
288 | end |
|
297 | end | |
289 |
|
298 | |||
290 | # Patch TMail so that message_id is not overwritten |
|
299 | # Patch TMail so that message_id is not overwritten | |
291 | module TMail |
|
300 | module TMail | |
292 | class Mail |
|
301 | class Mail | |
293 | def add_message_id( fqdn = nil ) |
|
302 | def add_message_id( fqdn = nil ) | |
294 | self.message_id ||= ::TMail::new_message_id(fqdn) |
|
303 | self.message_id ||= ::TMail::new_message_id(fqdn) | |
295 | end |
|
304 | end | |
296 | end |
|
305 | end | |
297 | end |
|
306 | end |
@@ -1,142 +1,158 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'users_controller' |
|
19 | require 'users_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class UsersController; def rescue_action(e) raise e end; end |
|
22 | class UsersController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class UsersControllerTest < Test::Unit::TestCase |
|
24 | class UsersControllerTest < Test::Unit::TestCase | |
25 | fixtures :users, :projects, :members |
|
25 | fixtures :users, :projects, :members | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = UsersController.new |
|
28 | @controller = UsersController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @request.session[:user_id] = 1 # admin |
|
32 | @request.session[:user_id] = 1 # admin | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_index_routing |
|
35 | def test_index_routing | |
36 | #TODO: unify with list |
|
36 | #TODO: unify with list | |
37 | assert_generates( |
|
37 | assert_generates( | |
38 | '/users', |
|
38 | '/users', | |
39 | :controller => 'users', :action => 'index' |
|
39 | :controller => 'users', :action => 'index' | |
40 | ) |
|
40 | ) | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_index |
|
43 | def test_index | |
44 | get :index |
|
44 | get :index | |
45 | assert_response :success |
|
45 | assert_response :success | |
46 | assert_template 'list' |
|
46 | assert_template 'list' | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
49 | def test_list_routing |
|
49 | def test_list_routing | |
50 | #TODO: rename action to index |
|
50 | #TODO: rename action to index | |
51 | assert_routing( |
|
51 | assert_routing( | |
52 | {:method => :get, :path => '/users'}, |
|
52 | {:method => :get, :path => '/users'}, | |
53 | :controller => 'users', :action => 'list' |
|
53 | :controller => 'users', :action => 'list' | |
54 | ) |
|
54 | ) | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_list |
|
57 | def test_list | |
58 | get :list |
|
58 | get :list | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'list' |
|
60 | assert_template 'list' | |
61 | assert_not_nil assigns(:users) |
|
61 | assert_not_nil assigns(:users) | |
62 | # active users only |
|
62 | # active users only | |
63 | assert_nil assigns(:users).detect {|u| !u.active?} |
|
63 | assert_nil assigns(:users).detect {|u| !u.active?} | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_list_with_name_filter |
|
66 | def test_list_with_name_filter | |
67 | get :list, :name => 'john' |
|
67 | get :list, :name => 'john' | |
68 | assert_response :success |
|
68 | assert_response :success | |
69 | assert_template 'list' |
|
69 | assert_template 'list' | |
70 | users = assigns(:users) |
|
70 | users = assigns(:users) | |
71 | assert_not_nil users |
|
71 | assert_not_nil users | |
72 | assert_equal 1, users.size |
|
72 | assert_equal 1, users.size | |
73 | assert_equal 'John', users.first.firstname |
|
73 | assert_equal 'John', users.first.firstname | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def test_add_routing |
|
76 | def test_add_routing | |
77 | assert_routing( |
|
77 | assert_routing( | |
78 | {:method => :get, :path => '/users/new'}, |
|
78 | {:method => :get, :path => '/users/new'}, | |
79 | :controller => 'users', :action => 'add' |
|
79 | :controller => 'users', :action => 'add' | |
80 | ) |
|
80 | ) | |
81 | assert_recognizes( |
|
81 | assert_recognizes( | |
82 | #TODO: remove this and replace with POST to collection, need to modify form |
|
82 | #TODO: remove this and replace with POST to collection, need to modify form | |
83 | {:controller => 'users', :action => 'add'}, |
|
83 | {:controller => 'users', :action => 'add'}, | |
84 | {:method => :post, :path => '/users/new'} |
|
84 | {:method => :post, :path => '/users/new'} | |
85 | ) |
|
85 | ) | |
86 | assert_recognizes( |
|
86 | assert_recognizes( | |
87 | {:controller => 'users', :action => 'add'}, |
|
87 | {:controller => 'users', :action => 'add'}, | |
88 | {:method => :post, :path => '/users'} |
|
88 | {:method => :post, :path => '/users'} | |
89 | ) |
|
89 | ) | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_edit_routing |
|
92 | def test_edit_routing | |
93 | assert_routing( |
|
93 | assert_routing( | |
94 | {:method => :get, :path => '/users/444/edit'}, |
|
94 | {:method => :get, :path => '/users/444/edit'}, | |
95 | :controller => 'users', :action => 'edit', :id => '444' |
|
95 | :controller => 'users', :action => 'edit', :id => '444' | |
96 | ) |
|
96 | ) | |
97 | assert_routing( |
|
97 | assert_routing( | |
98 | {:method => :get, :path => '/users/222/edit/membership'}, |
|
98 | {:method => :get, :path => '/users/222/edit/membership'}, | |
99 | :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' |
|
99 | :controller => 'users', :action => 'edit', :id => '222', :tab => 'membership' | |
100 | ) |
|
100 | ) | |
101 | assert_recognizes( |
|
101 | assert_recognizes( | |
102 | #TODO: use PUT on user_path, modify form |
|
102 | #TODO: use PUT on user_path, modify form | |
103 | {:controller => 'users', :action => 'edit', :id => '444'}, |
|
103 | {:controller => 'users', :action => 'edit', :id => '444'}, | |
104 | {:method => :post, :path => '/users/444/edit'} |
|
104 | {:method => :post, :path => '/users/444/edit'} | |
105 | ) |
|
105 | ) | |
106 | end |
|
106 | end | |
107 |
|
107 | |||
108 | def test_add_membership_routing |
|
108 | def test_add_membership_routing | |
109 | assert_routing( |
|
109 | assert_routing( | |
110 | {:method => :post, :path => '/users/123/memberships'}, |
|
110 | {:method => :post, :path => '/users/123/memberships'}, | |
111 | :controller => 'users', :action => 'edit_membership', :id => '123' |
|
111 | :controller => 'users', :action => 'edit_membership', :id => '123' | |
112 | ) |
|
112 | ) | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_edit_membership_routing |
|
115 | def test_edit_membership_routing | |
116 | assert_routing( |
|
116 | assert_routing( | |
117 | {:method => :post, :path => '/users/123/memberships/55'}, |
|
117 | {:method => :post, :path => '/users/123/memberships/55'}, | |
118 | :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' |
|
118 | :controller => 'users', :action => 'edit_membership', :id => '123', :membership_id => '55' | |
119 | ) |
|
119 | ) | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_edit_membership |
|
122 | def test_edit_membership | |
123 | post :edit_membership, :id => 2, :membership_id => 1, |
|
123 | post :edit_membership, :id => 2, :membership_id => 1, | |
124 | :membership => { :role_id => 2} |
|
124 | :membership => { :role_id => 2} | |
125 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
125 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
126 | assert_equal 2, Member.find(1).role_id |
|
126 | assert_equal 2, Member.find(1).role_id | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
|
129 | def test_edit_with_activation_should_send_a_notification | |||
|
130 | u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') | |||
|
131 | u.login = 'foo' | |||
|
132 | u.status = User::STATUS_REGISTERED | |||
|
133 | u.save! | |||
|
134 | ActionMailer::Base.deliveries.clear | |||
|
135 | Setting.bcc_recipients = '1' | |||
|
136 | ||||
|
137 | post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} | |||
|
138 | assert u.reload.active? | |||
|
139 | mail = ActionMailer::Base.deliveries.last | |||
|
140 | assert_not_nil mail | |||
|
141 | assert_equal ['foo.bar@somenet.foo'], mail.bcc | |||
|
142 | assert mail.body.include?(ll('fr', :notice_account_activated)) | |||
|
143 | end | |||
|
144 | ||||
129 | def test_destroy_membership |
|
145 | def test_destroy_membership | |
130 | assert_routing( |
|
146 | assert_routing( | |
131 | #TODO: use DELETE method on user_membership_path, modify form |
|
147 | #TODO: use DELETE method on user_membership_path, modify form | |
132 | {:method => :post, :path => '/users/567/memberships/12/destroy'}, |
|
148 | {:method => :post, :path => '/users/567/memberships/12/destroy'}, | |
133 | :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' |
|
149 | :controller => 'users', :action => 'destroy_membership', :id => '567', :membership_id => '12' | |
134 | ) |
|
150 | ) | |
135 | end |
|
151 | end | |
136 |
|
152 | |||
137 | def test_destroy_membership |
|
153 | def test_destroy_membership | |
138 | post :destroy_membership, :id => 2, :membership_id => 1 |
|
154 | post :destroy_membership, :id => 2, :membership_id => 1 | |
139 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' |
|
155 | assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships' | |
140 | assert_nil Member.find_by_id(1) |
|
156 | assert_nil Member.find_by_id(1) | |
141 | end |
|
157 | end | |
142 | end |
|
158 | end |
General Comments 0
You need to be logged in to leave comments.
Login now