##// END OF EJS Templates
Removed translated email templates attachments_added and document_added (no longer usefull)....
Jean-Philippe Lang -
r823:dead6a28f81c
parent child
Show More
@@ -0,0 +1,5
1 <%= link_to @added_to, @url %><br />
2
3 <ul><% @attachments.each do |attachment | %>
4 <li><%= attachment.filename %></li>
5 <% end %></ul>
@@ -0,0 +1,4
1 <%= @added_to %><% @attachments.each do |attachment | %>
2 - <%= attachment.filename %><% end %>
3
4 <%= url_for @url %>
@@ -0,0 +1,4
1 <%= link_to @document.title, :only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => @document %>
2 (<%= @document.category.name %>)<br />
3 <br />
4 <%= textilizable(@document.description) %>
@@ -0,0 +1,4
1 <%= @document.title %> (<%= @document.category.name %>)
2 <%= url_for :only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => @document %>
3
4 <%= @document.description %>
@@ -1,71 +1,71
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 DocumentsController < ApplicationController
18 class DocumentsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :authorize
20 before_filter :find_project, :authorize
21
21
22 def show
22 def show
23 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
23 @attachments = @document.attachments.find(:all, :order => "created_on DESC")
24 end
24 end
25
25
26 def edit
26 def edit
27 @categories = Enumeration::get_values('DCAT')
27 @categories = Enumeration::get_values('DCAT')
28 if request.post? and @document.update_attributes(params[:document])
28 if request.post? and @document.update_attributes(params[:document])
29 flash[:notice] = l(:notice_successful_update)
29 flash[:notice] = l(:notice_successful_update)
30 redirect_to :action => 'show', :id => @document
30 redirect_to :action => 'show', :id => @document
31 end
31 end
32 end
32 end
33
33
34 def destroy
34 def destroy
35 @document.destroy
35 @document.destroy
36 redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
36 redirect_to :controller => 'projects', :action => 'list_documents', :id => @project
37 end
37 end
38
38
39 def download
39 def download
40 @attachment = @document.attachments.find(params[:attachment_id])
40 @attachment = @document.attachments.find(params[:attachment_id])
41 @attachment.increment_download
41 @attachment.increment_download
42 send_file @attachment.diskfile, :filename => @attachment.filename
42 send_file @attachment.diskfile, :filename => @attachment.filename
43 rescue
43 rescue
44 render_404
44 render_404
45 end
45 end
46
46
47 def add_attachment
47 def add_attachment
48 # Save the attachments
48 # Save the attachments
49 @attachments = []
49 @attachments = []
50 params[:attachments].each { |file|
50 params[:attachments].each { |file|
51 next unless file.size > 0
51 next unless file.size > 0
52 a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
52 a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
53 @attachments << a unless a.new_record?
53 @attachments << a unless a.new_record?
54 } if params[:attachments] and params[:attachments].is_a? Array
54 } if params[:attachments] and params[:attachments].is_a? Array
55 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added')
55 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('document_added')
56 redirect_to :action => 'show', :id => @document
56 redirect_to :action => 'show', :id => @document
57 end
57 end
58
58
59 def destroy_attachment
59 def destroy_attachment
60 @document.attachments.find(params[:attachment_id]).destroy
60 @document.attachments.find(params[:attachment_id]).destroy
61 redirect_to :action => 'show', :id => @document
61 redirect_to :action => 'show', :id => @document
62 end
62 end
63
63
64 private
64 private
65 def find_project
65 def find_project
66 @document = Document.find(params[:id])
66 @document = Document.find(params[:id])
67 @project = @document.project
67 @project = @document.project
68 rescue ActiveRecord::RecordNotFound
68 rescue ActiveRecord::RecordNotFound
69 render_404
69 render_404
70 end
70 end
71 end
71 end
@@ -1,676 +1,676
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 'csv'
18 require 'csv'
19
19
20 class ProjectsController < ApplicationController
20 class ProjectsController < ApplicationController
21 layout 'base'
21 layout 'base'
22 before_filter :find_project, :except => [ :index, :list, :add ]
22 before_filter :find_project, :except => [ :index, :list, :add ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
23 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
24 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
25 accept_key_auth :activity, :calendar
25 accept_key_auth :activity, :calendar
26
26
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
27 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
28 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
29 cache_sweeper :version_sweeper, :only => [ :add_version ]
30
30
31 helper :sort
31 helper :sort
32 include SortHelper
32 include SortHelper
33 helper :custom_fields
33 helper :custom_fields
34 include CustomFieldsHelper
34 include CustomFieldsHelper
35 helper :ifpdf
35 helper :ifpdf
36 include IfpdfHelper
36 include IfpdfHelper
37 helper :issues
37 helper :issues
38 helper IssuesHelper
38 helper IssuesHelper
39 helper :queries
39 helper :queries
40 include QueriesHelper
40 include QueriesHelper
41 helper :repositories
41 helper :repositories
42 include RepositoriesHelper
42 include RepositoriesHelper
43 include ProjectsHelper
43 include ProjectsHelper
44
44
45 def index
45 def index
46 list
46 list
47 render :action => 'list' unless request.xhr?
47 render :action => 'list' unless request.xhr?
48 end
48 end
49
49
50 # Lists visible projects
50 # Lists visible projects
51 def list
51 def list
52 projects = Project.find :all,
52 projects = Project.find :all,
53 :conditions => Project.visible_by(logged_in_user),
53 :conditions => Project.visible_by(logged_in_user),
54 :include => :parent
54 :include => :parent
55 @project_tree = projects.group_by {|p| p.parent || p}
55 @project_tree = projects.group_by {|p| p.parent || p}
56 @project_tree.each_key {|p| @project_tree[p] -= [p]}
56 @project_tree.each_key {|p| @project_tree[p] -= [p]}
57 end
57 end
58
58
59 # Add a new project
59 # Add a new project
60 def add
60 def add
61 @custom_fields = IssueCustomField.find(:all)
61 @custom_fields = IssueCustomField.find(:all)
62 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
62 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
63 @project = Project.new(params[:project])
63 @project = Project.new(params[:project])
64 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
64 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
65 if request.get?
65 if request.get?
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
66 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
67 else
67 else
68 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
68 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
69 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
69 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
70 @project.custom_values = @custom_values
70 @project.custom_values = @custom_values
71 if @project.save
71 if @project.save
72 @project.enabled_module_names = params[:enabled_modules]
72 @project.enabled_module_names = params[:enabled_modules]
73 flash[:notice] = l(:notice_successful_create)
73 flash[:notice] = l(:notice_successful_create)
74 redirect_to :controller => 'admin', :action => 'projects'
74 redirect_to :controller => 'admin', :action => 'projects'
75 end
75 end
76 end
76 end
77 end
77 end
78
78
79 # Show @project
79 # Show @project
80 def show
80 def show
81 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
81 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
82 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
82 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
83 @subprojects = @project.active_children
83 @subprojects = @project.active_children
84 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
84 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
85 @trackers = Tracker.find(:all, :order => 'position')
85 @trackers = Tracker.find(:all, :order => 'position')
86 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
86 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
87 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
87 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
88 @total_hours = @project.time_entries.sum(:hours)
88 @total_hours = @project.time_entries.sum(:hours)
89 @key = User.current.rss_key
89 @key = User.current.rss_key
90 end
90 end
91
91
92 def settings
92 def settings
93 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
93 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
94 @custom_fields = IssueCustomField.find(:all)
94 @custom_fields = IssueCustomField.find(:all)
95 @issue_category ||= IssueCategory.new
95 @issue_category ||= IssueCategory.new
96 @member ||= @project.members.new
96 @member ||= @project.members.new
97 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
97 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
98 @repository ||= @project.repository
98 @repository ||= @project.repository
99 @wiki ||= @project.wiki
99 @wiki ||= @project.wiki
100 end
100 end
101
101
102 # Edit @project
102 # Edit @project
103 def edit
103 def edit
104 if request.post?
104 if request.post?
105 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
105 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
106 if params[:custom_fields]
106 if params[:custom_fields]
107 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
107 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
108 @project.custom_values = @custom_values
108 @project.custom_values = @custom_values
109 end
109 end
110 @project.attributes = params[:project]
110 @project.attributes = params[:project]
111 if @project.save
111 if @project.save
112 flash[:notice] = l(:notice_successful_update)
112 flash[:notice] = l(:notice_successful_update)
113 redirect_to :action => 'settings', :id => @project
113 redirect_to :action => 'settings', :id => @project
114 else
114 else
115 settings
115 settings
116 render :action => 'settings'
116 render :action => 'settings'
117 end
117 end
118 end
118 end
119 end
119 end
120
120
121 def modules
121 def modules
122 @project.enabled_module_names = params[:enabled_modules]
122 @project.enabled_module_names = params[:enabled_modules]
123 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
123 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
124 end
124 end
125
125
126 def archive
126 def archive
127 @project.archive if request.post? && @project.active?
127 @project.archive if request.post? && @project.active?
128 redirect_to :controller => 'admin', :action => 'projects'
128 redirect_to :controller => 'admin', :action => 'projects'
129 end
129 end
130
130
131 def unarchive
131 def unarchive
132 @project.unarchive if request.post? && !@project.active?
132 @project.unarchive if request.post? && !@project.active?
133 redirect_to :controller => 'admin', :action => 'projects'
133 redirect_to :controller => 'admin', :action => 'projects'
134 end
134 end
135
135
136 # Delete @project
136 # Delete @project
137 def destroy
137 def destroy
138 @project_to_destroy = @project
138 @project_to_destroy = @project
139 if request.post? and params[:confirm]
139 if request.post? and params[:confirm]
140 @project_to_destroy.destroy
140 @project_to_destroy.destroy
141 redirect_to :controller => 'admin', :action => 'projects'
141 redirect_to :controller => 'admin', :action => 'projects'
142 end
142 end
143 # hide project in layout
143 # hide project in layout
144 @project = nil
144 @project = nil
145 end
145 end
146
146
147 # Add a new issue category to @project
147 # Add a new issue category to @project
148 def add_issue_category
148 def add_issue_category
149 @category = @project.issue_categories.build(params[:category])
149 @category = @project.issue_categories.build(params[:category])
150 if request.post? and @category.save
150 if request.post? and @category.save
151 respond_to do |format|
151 respond_to do |format|
152 format.html do
152 format.html do
153 flash[:notice] = l(:notice_successful_create)
153 flash[:notice] = l(:notice_successful_create)
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
154 redirect_to :action => 'settings', :tab => 'categories', :id => @project
155 end
155 end
156 format.js do
156 format.js do
157 # IE doesn't support the replace_html rjs method for select box options
157 # IE doesn't support the replace_html rjs method for select box options
158 render(:update) {|page| page.replace "issue_category_id",
158 render(:update) {|page| page.replace "issue_category_id",
159 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
159 content_tag('select', '<option></option>' + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
160 }
160 }
161 end
161 end
162 end
162 end
163 end
163 end
164 end
164 end
165
165
166 # Add a new version to @project
166 # Add a new version to @project
167 def add_version
167 def add_version
168 @version = @project.versions.build(params[:version])
168 @version = @project.versions.build(params[:version])
169 if request.post? and @version.save
169 if request.post? and @version.save
170 flash[:notice] = l(:notice_successful_create)
170 flash[:notice] = l(:notice_successful_create)
171 redirect_to :action => 'settings', :tab => 'versions', :id => @project
171 redirect_to :action => 'settings', :tab => 'versions', :id => @project
172 end
172 end
173 end
173 end
174
174
175 # Add a new document to @project
175 # Add a new document to @project
176 def add_document
176 def add_document
177 @categories = Enumeration::get_values('DCAT')
177 @categories = Enumeration::get_values('DCAT')
178 @document = @project.documents.build(params[:document])
178 @document = @project.documents.build(params[:document])
179 if request.post? and @document.save
179 if request.post? and @document.save
180 # Save the attachments
180 # Save the attachments
181 params[:attachments].each { |a|
181 params[:attachments].each { |a|
182 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
182 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
183 } if params[:attachments] and params[:attachments].is_a? Array
183 } if params[:attachments] and params[:attachments].is_a? Array
184 flash[:notice] = l(:notice_successful_create)
184 flash[:notice] = l(:notice_successful_create)
185 Mailer.deliver_document_add(@document) if Setting.notified_events.include?('document_added')
185 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
186 redirect_to :action => 'list_documents', :id => @project
186 redirect_to :action => 'list_documents', :id => @project
187 end
187 end
188 end
188 end
189
189
190 # Show documents list of @project
190 # Show documents list of @project
191 def list_documents
191 def list_documents
192 @documents = @project.documents.find :all, :include => :category
192 @documents = @project.documents.find :all, :include => :category
193 end
193 end
194
194
195 # Add a new issue to @project
195 # Add a new issue to @project
196 def add_issue
196 def add_issue
197 @tracker = Tracker.find(params[:tracker_id])
197 @tracker = Tracker.find(params[:tracker_id])
198 @priorities = Enumeration::get_values('IPRI')
198 @priorities = Enumeration::get_values('IPRI')
199
199
200 default_status = IssueStatus.default
200 default_status = IssueStatus.default
201 unless default_status
201 unless default_status
202 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
202 flash.now[:error] = 'No default issue status defined. Please check your configuration.'
203 render :nothing => true, :layout => true
203 render :nothing => true, :layout => true
204 return
204 return
205 end
205 end
206 @issue = Issue.new(:project => @project, :tracker => @tracker)
206 @issue = Issue.new(:project => @project, :tracker => @tracker)
207 @issue.status = default_status
207 @issue.status = default_status
208 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
208 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
209 if request.get?
209 if request.get?
210 @issue.start_date = Date.today
210 @issue.start_date = Date.today
211 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
211 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) }
212 else
212 else
213 @issue.attributes = params[:issue]
213 @issue.attributes = params[:issue]
214
214
215 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
215 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
216 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
216 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
217
217
218 @issue.author_id = self.logged_in_user.id if self.logged_in_user
218 @issue.author_id = self.logged_in_user.id if self.logged_in_user
219 # Multiple file upload
219 # Multiple file upload
220 @attachments = []
220 @attachments = []
221 params[:attachments].each { |a|
221 params[:attachments].each { |a|
222 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
222 @attachments << Attachment.new(:container => @issue, :file => a, :author => logged_in_user) unless a.size == 0
223 } if params[:attachments] and params[:attachments].is_a? Array
223 } if params[:attachments] and params[:attachments].is_a? Array
224 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
224 @custom_values = @project.custom_fields_for_issues(@tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
225 @issue.custom_values = @custom_values
225 @issue.custom_values = @custom_values
226 if @issue.save
226 if @issue.save
227 @attachments.each(&:save)
227 @attachments.each(&:save)
228 flash[:notice] = l(:notice_successful_create)
228 flash[:notice] = l(:notice_successful_create)
229 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
229 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
230 redirect_to :action => 'list_issues', :id => @project
230 redirect_to :action => 'list_issues', :id => @project
231 end
231 end
232 end
232 end
233 end
233 end
234
234
235 # Show filtered/sorted issues list of @project
235 # Show filtered/sorted issues list of @project
236 def list_issues
236 def list_issues
237 sort_init "#{Issue.table_name}.id", "desc"
237 sort_init "#{Issue.table_name}.id", "desc"
238 sort_update
238 sort_update
239
239
240 retrieve_query
240 retrieve_query
241
241
242 @results_per_page_options = [ 15, 25, 50, 100 ]
242 @results_per_page_options = [ 15, 25, 50, 100 ]
243 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
243 if params[:per_page] and @results_per_page_options.include? params[:per_page].to_i
244 @results_per_page = params[:per_page].to_i
244 @results_per_page = params[:per_page].to_i
245 session[:results_per_page] = @results_per_page
245 session[:results_per_page] = @results_per_page
246 else
246 else
247 @results_per_page = session[:results_per_page] || 25
247 @results_per_page = session[:results_per_page] || 25
248 end
248 end
249
249
250 if @query.valid?
250 if @query.valid?
251 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
251 @issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
252 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
252 @issue_pages = Paginator.new self, @issue_count, @results_per_page, params['page']
253 @issues = Issue.find :all, :order => sort_clause,
253 @issues = Issue.find :all, :order => sort_clause,
254 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
254 :include => [ :assigned_to, :status, :tracker, :project, :priority, :category ],
255 :conditions => @query.statement,
255 :conditions => @query.statement,
256 :limit => @issue_pages.items_per_page,
256 :limit => @issue_pages.items_per_page,
257 :offset => @issue_pages.current.offset
257 :offset => @issue_pages.current.offset
258 end
258 end
259
259
260 render :layout => false if request.xhr?
260 render :layout => false if request.xhr?
261 end
261 end
262
262
263 # Export filtered/sorted issues list to CSV
263 # Export filtered/sorted issues list to CSV
264 def export_issues_csv
264 def export_issues_csv
265 sort_init "#{Issue.table_name}.id", "desc"
265 sort_init "#{Issue.table_name}.id", "desc"
266 sort_update
266 sort_update
267
267
268 retrieve_query
268 retrieve_query
269 render :action => 'list_issues' and return unless @query.valid?
269 render :action => 'list_issues' and return unless @query.valid?
270
270
271 @issues = Issue.find :all, :order => sort_clause,
271 @issues = Issue.find :all, :order => sort_clause,
272 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
272 :include => [ :assigned_to, :author, :status, :tracker, :priority, :project, {:custom_values => :custom_field} ],
273 :conditions => @query.statement,
273 :conditions => @query.statement,
274 :limit => Setting.issues_export_limit.to_i
274 :limit => Setting.issues_export_limit.to_i
275
275
276 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
276 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
277 export = StringIO.new
277 export = StringIO.new
278 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
278 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
279 # csv header fields
279 # csv header fields
280 headers = [ "#", l(:field_status),
280 headers = [ "#", l(:field_status),
281 l(:field_project),
281 l(:field_project),
282 l(:field_tracker),
282 l(:field_tracker),
283 l(:field_priority),
283 l(:field_priority),
284 l(:field_subject),
284 l(:field_subject),
285 l(:field_assigned_to),
285 l(:field_assigned_to),
286 l(:field_author),
286 l(:field_author),
287 l(:field_start_date),
287 l(:field_start_date),
288 l(:field_due_date),
288 l(:field_due_date),
289 l(:field_done_ratio),
289 l(:field_done_ratio),
290 l(:field_created_on),
290 l(:field_created_on),
291 l(:field_updated_on)
291 l(:field_updated_on)
292 ]
292 ]
293 for custom_field in @project.all_custom_fields
293 for custom_field in @project.all_custom_fields
294 headers << custom_field.name
294 headers << custom_field.name
295 end
295 end
296 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
296 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
297 # csv lines
297 # csv lines
298 @issues.each do |issue|
298 @issues.each do |issue|
299 fields = [issue.id, issue.status.name,
299 fields = [issue.id, issue.status.name,
300 issue.project.name,
300 issue.project.name,
301 issue.tracker.name,
301 issue.tracker.name,
302 issue.priority.name,
302 issue.priority.name,
303 issue.subject,
303 issue.subject,
304 (issue.assigned_to ? issue.assigned_to.name : ""),
304 (issue.assigned_to ? issue.assigned_to.name : ""),
305 issue.author.name,
305 issue.author.name,
306 issue.start_date ? l_date(issue.start_date) : nil,
306 issue.start_date ? l_date(issue.start_date) : nil,
307 issue.due_date ? l_date(issue.due_date) : nil,
307 issue.due_date ? l_date(issue.due_date) : nil,
308 issue.done_ratio,
308 issue.done_ratio,
309 l_datetime(issue.created_on),
309 l_datetime(issue.created_on),
310 l_datetime(issue.updated_on)
310 l_datetime(issue.updated_on)
311 ]
311 ]
312 for custom_field in @project.all_custom_fields
312 for custom_field in @project.all_custom_fields
313 fields << (show_value issue.custom_value_for(custom_field))
313 fields << (show_value issue.custom_value_for(custom_field))
314 end
314 end
315 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
315 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
316 end
316 end
317 end
317 end
318 export.rewind
318 export.rewind
319 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
319 send_data(export.read, :type => 'text/csv; header=present', :filename => 'export.csv')
320 end
320 end
321
321
322 # Export filtered/sorted issues to PDF
322 # Export filtered/sorted issues to PDF
323 def export_issues_pdf
323 def export_issues_pdf
324 sort_init "#{Issue.table_name}.id", "desc"
324 sort_init "#{Issue.table_name}.id", "desc"
325 sort_update
325 sort_update
326
326
327 retrieve_query
327 retrieve_query
328 render :action => 'list_issues' and return unless @query.valid?
328 render :action => 'list_issues' and return unless @query.valid?
329
329
330 @issues = Issue.find :all, :order => sort_clause,
330 @issues = Issue.find :all, :order => sort_clause,
331 :include => [ :author, :status, :tracker, :priority, :project ],
331 :include => [ :author, :status, :tracker, :priority, :project ],
332 :conditions => @query.statement,
332 :conditions => @query.statement,
333 :limit => Setting.issues_export_limit.to_i
333 :limit => Setting.issues_export_limit.to_i
334
334
335 @options_for_rfpdf ||= {}
335 @options_for_rfpdf ||= {}
336 @options_for_rfpdf[:file_name] = "export.pdf"
336 @options_for_rfpdf[:file_name] = "export.pdf"
337 render :layout => false
337 render :layout => false
338 end
338 end
339
339
340 # Bulk edit issues
340 # Bulk edit issues
341 def bulk_edit_issues
341 def bulk_edit_issues
342 if request.post?
342 if request.post?
343 status = IssueStatus.find_by_id(params[:status_id])
343 status = IssueStatus.find_by_id(params[:status_id])
344 priority = Enumeration.find_by_id(params[:priority_id])
344 priority = Enumeration.find_by_id(params[:priority_id])
345 assigned_to = User.find_by_id(params[:assigned_to_id])
345 assigned_to = User.find_by_id(params[:assigned_to_id])
346 category = @project.issue_categories.find_by_id(params[:category_id])
346 category = @project.issue_categories.find_by_id(params[:category_id])
347 fixed_version = @project.versions.find_by_id(params[:fixed_version_id])
347 fixed_version = @project.versions.find_by_id(params[:fixed_version_id])
348 issues = @project.issues.find_all_by_id(params[:issue_ids])
348 issues = @project.issues.find_all_by_id(params[:issue_ids])
349 unsaved_issue_ids = []
349 unsaved_issue_ids = []
350 issues.each do |issue|
350 issues.each do |issue|
351 journal = issue.init_journal(User.current, params[:notes])
351 journal = issue.init_journal(User.current, params[:notes])
352 issue.priority = priority if priority
352 issue.priority = priority if priority
353 issue.assigned_to = assigned_to if assigned_to
353 issue.assigned_to = assigned_to if assigned_to
354 issue.category = category if category
354 issue.category = category if category
355 issue.fixed_version = fixed_version if fixed_version
355 issue.fixed_version = fixed_version if fixed_version
356 issue.start_date = params[:start_date] unless params[:start_date].blank?
356 issue.start_date = params[:start_date] unless params[:start_date].blank?
357 issue.due_date = params[:due_date] unless params[:due_date].blank?
357 issue.due_date = params[:due_date] unless params[:due_date].blank?
358 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
358 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
359 # Don't save any change to the issue if the user is not authorized to apply the requested status
359 # Don't save any change to the issue if the user is not authorized to apply the requested status
360 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
360 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
361 # Send notification for each issue (if changed)
361 # Send notification for each issue (if changed)
362 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
362 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
363 else
363 else
364 # Keep unsaved issue ids to display them in flash error
364 # Keep unsaved issue ids to display them in flash error
365 unsaved_issue_ids << issue.id
365 unsaved_issue_ids << issue.id
366 end
366 end
367 end
367 end
368 if unsaved_issue_ids.empty?
368 if unsaved_issue_ids.empty?
369 flash[:notice] = l(:notice_successful_update) unless issues.empty?
369 flash[:notice] = l(:notice_successful_update) unless issues.empty?
370 else
370 else
371 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
371 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
372 end
372 end
373 redirect_to :action => 'list_issues', :id => @project
373 redirect_to :action => 'list_issues', :id => @project
374 return
374 return
375 end
375 end
376 if current_role && User.current.allowed_to?(:change_issue_status, @project)
376 if current_role && User.current.allowed_to?(:change_issue_status, @project)
377 # Find potential statuses the user could be allowed to switch issues to
377 # Find potential statuses the user could be allowed to switch issues to
378 @available_statuses = Workflow.find(:all, :include => :new_status,
378 @available_statuses = Workflow.find(:all, :include => :new_status,
379 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
379 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
380 end
380 end
381 render :update do |page|
381 render :update do |page|
382 page.hide 'query_form'
382 page.hide 'query_form'
383 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
383 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
384 end
384 end
385 end
385 end
386
386
387 def move_issues
387 def move_issues
388 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
388 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
389 redirect_to :action => 'list_issues', :id => @project and return unless @issues
389 redirect_to :action => 'list_issues', :id => @project and return unless @issues
390 @projects = []
390 @projects = []
391 # find projects to which the user is allowed to move the issue
391 # find projects to which the user is allowed to move the issue
392 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
392 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
393 # issue can be moved to any tracker
393 # issue can be moved to any tracker
394 @trackers = Tracker.find(:all)
394 @trackers = Tracker.find(:all)
395 if request.post? and params[:new_project_id] and params[:new_tracker_id]
395 if request.post? and params[:new_project_id] and params[:new_tracker_id]
396 new_project = Project.find_by_id(params[:new_project_id])
396 new_project = Project.find_by_id(params[:new_project_id])
397 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
397 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
398 @issues.each do |i|
398 @issues.each do |i|
399 if new_project && i.project_id != new_project.id
399 if new_project && i.project_id != new_project.id
400 # issue is moved to another project
400 # issue is moved to another project
401 i.category = nil
401 i.category = nil
402 i.fixed_version = nil
402 i.fixed_version = nil
403 # delete issue relations
403 # delete issue relations
404 i.relations_from.clear
404 i.relations_from.clear
405 i.relations_to.clear
405 i.relations_to.clear
406 i.project = new_project
406 i.project = new_project
407 end
407 end
408 if new_tracker
408 if new_tracker
409 i.tracker = new_tracker
409 i.tracker = new_tracker
410 end
410 end
411 i.save
411 i.save
412 end
412 end
413 flash[:notice] = l(:notice_successful_update)
413 flash[:notice] = l(:notice_successful_update)
414 redirect_to :action => 'list_issues', :id => @project
414 redirect_to :action => 'list_issues', :id => @project
415 end
415 end
416 end
416 end
417
417
418 # Add a news to @project
418 # Add a news to @project
419 def add_news
419 def add_news
420 @news = News.new(:project => @project)
420 @news = News.new(:project => @project)
421 if request.post?
421 if request.post?
422 @news.attributes = params[:news]
422 @news.attributes = params[:news]
423 @news.author_id = self.logged_in_user.id if self.logged_in_user
423 @news.author_id = self.logged_in_user.id if self.logged_in_user
424 if @news.save
424 if @news.save
425 flash[:notice] = l(:notice_successful_create)
425 flash[:notice] = l(:notice_successful_create)
426 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
426 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
427 redirect_to :action => 'list_news', :id => @project
427 redirect_to :action => 'list_news', :id => @project
428 end
428 end
429 end
429 end
430 end
430 end
431
431
432 # Show news list of @project
432 # Show news list of @project
433 def list_news
433 def list_news
434 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
434 @news_pages, @newss = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
435
435
436 respond_to do |format|
436 respond_to do |format|
437 format.html { render :layout => false if request.xhr? }
437 format.html { render :layout => false if request.xhr? }
438 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
438 format.atom { render_feed(@newss, :title => "#{@project.name}: #{l(:label_news_plural)}") }
439 end
439 end
440 end
440 end
441
441
442 def add_file
442 def add_file
443 if request.post?
443 if request.post?
444 @version = @project.versions.find_by_id(params[:version_id])
444 @version = @project.versions.find_by_id(params[:version_id])
445 # Save the attachments
445 # Save the attachments
446 @attachments = []
446 @attachments = []
447 params[:attachments].each { |file|
447 params[:attachments].each { |file|
448 next unless file.size > 0
448 next unless file.size > 0
449 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
449 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
450 @attachments << a unless a.new_record?
450 @attachments << a unless a.new_record?
451 } if params[:attachments] and params[:attachments].is_a? Array
451 } if params[:attachments] and params[:attachments].is_a? Array
452 Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
452 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
453 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
453 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
454 end
454 end
455 @versions = @project.versions.sort
455 @versions = @project.versions.sort
456 end
456 end
457
457
458 def list_files
458 def list_files
459 @versions = @project.versions.sort
459 @versions = @project.versions.sort
460 end
460 end
461
461
462 # Show changelog for @project
462 # Show changelog for @project
463 def changelog
463 def changelog
464 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
464 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
465 retrieve_selected_tracker_ids(@trackers)
465 retrieve_selected_tracker_ids(@trackers)
466 @versions = @project.versions.sort
466 @versions = @project.versions.sort
467 end
467 end
468
468
469 def roadmap
469 def roadmap
470 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
470 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
471 retrieve_selected_tracker_ids(@trackers)
471 retrieve_selected_tracker_ids(@trackers)
472 @versions = @project.versions.sort
472 @versions = @project.versions.sort
473 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
473 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
474 end
474 end
475
475
476 def activity
476 def activity
477 if params[:year] and params[:year].to_i > 1900
477 if params[:year] and params[:year].to_i > 1900
478 @year = params[:year].to_i
478 @year = params[:year].to_i
479 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
479 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
480 @month = params[:month].to_i
480 @month = params[:month].to_i
481 end
481 end
482 end
482 end
483 @year ||= Date.today.year
483 @year ||= Date.today.year
484 @month ||= Date.today.month
484 @month ||= Date.today.month
485
485
486 case params[:format]
486 case params[:format]
487 when 'atom'
487 when 'atom'
488 # 30 last days
488 # 30 last days
489 @date_from = Date.today - 30
489 @date_from = Date.today - 30
490 @date_to = Date.today + 1
490 @date_to = Date.today + 1
491 else
491 else
492 # current month
492 # current month
493 @date_from = Date.civil(@year, @month, 1)
493 @date_from = Date.civil(@year, @month, 1)
494 @date_to = @date_from >> 1
494 @date_to = @date_from >> 1
495 end
495 end
496
496
497 @event_types = %w(issues news files documents wiki_pages changesets)
497 @event_types = %w(issues news files documents wiki_pages changesets)
498 @event_types.delete('wiki_pages') unless @project.wiki
498 @event_types.delete('wiki_pages') unless @project.wiki
499 @event_types.delete('changesets') unless @project.repository
499 @event_types.delete('changesets') unless @project.repository
500 # only show what the user is allowed to view
500 # only show what the user is allowed to view
501 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
501 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
502
502
503 @scope = @event_types.select {|t| params["show_#{t}"]}
503 @scope = @event_types.select {|t| params["show_#{t}"]}
504 # default events if none is specified in parameters
504 # default events if none is specified in parameters
505 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
505 @scope = (@event_types - %w(wiki_pages))if @scope.empty?
506
506
507 @events = []
507 @events = []
508
508
509 if @scope.include?('issues')
509 if @scope.include?('issues')
510 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
510 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
511 end
511 end
512
512
513 if @scope.include?('news')
513 if @scope.include?('news')
514 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
514 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
515 end
515 end
516
516
517 if @scope.include?('files')
517 if @scope.include?('files')
518 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
518 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
519 end
519 end
520
520
521 if @scope.include?('documents')
521 if @scope.include?('documents')
522 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
522 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
523 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
523 @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
524 end
524 end
525
525
526 if @scope.include?('wiki_pages')
526 if @scope.include?('wiki_pages')
527 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
527 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
528 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
528 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
529 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
529 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
530 "#{WikiContent.versioned_table_name}.id"
530 "#{WikiContent.versioned_table_name}.id"
531 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
531 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
532 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
532 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
533 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
533 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
534 @project.id, @date_from, @date_to]
534 @project.id, @date_from, @date_to]
535
535
536 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
536 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
537 end
537 end
538
538
539 if @scope.include?('changesets')
539 if @scope.include?('changesets')
540 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
540 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
541 end
541 end
542
542
543 @events_by_day = @events.group_by(&:event_date)
543 @events_by_day = @events.group_by(&:event_date)
544
544
545 respond_to do |format|
545 respond_to do |format|
546 format.html { render :layout => false if request.xhr? }
546 format.html { render :layout => false if request.xhr? }
547 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
547 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
548 end
548 end
549 end
549 end
550
550
551 def calendar
551 def calendar
552 @trackers = Tracker.find(:all, :order => 'position')
552 @trackers = Tracker.find(:all, :order => 'position')
553 retrieve_selected_tracker_ids(@trackers)
553 retrieve_selected_tracker_ids(@trackers)
554
554
555 if params[:year] and params[:year].to_i > 1900
555 if params[:year] and params[:year].to_i > 1900
556 @year = params[:year].to_i
556 @year = params[:year].to_i
557 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
557 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
558 @month = params[:month].to_i
558 @month = params[:month].to_i
559 end
559 end
560 end
560 end
561 @year ||= Date.today.year
561 @year ||= Date.today.year
562 @month ||= Date.today.month
562 @month ||= Date.today.month
563 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
563 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
564
564
565 events = []
565 events = []
566 @project.issues_with_subprojects(params[:with_subprojects]) do
566 @project.issues_with_subprojects(params[:with_subprojects]) do
567 events += Issue.find(:all,
567 events += Issue.find(:all,
568 :include => [:tracker, :status, :assigned_to, :priority, :project],
568 :include => [:tracker, :status, :assigned_to, :priority, :project],
569 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
569 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
570 ) unless @selected_tracker_ids.empty?
570 ) unless @selected_tracker_ids.empty?
571 end
571 end
572 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
572 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
573 @calendar.events = events
573 @calendar.events = events
574
574
575 render :layout => false if request.xhr?
575 render :layout => false if request.xhr?
576 end
576 end
577
577
578 def gantt
578 def gantt
579 @trackers = Tracker.find(:all, :order => 'position')
579 @trackers = Tracker.find(:all, :order => 'position')
580 retrieve_selected_tracker_ids(@trackers)
580 retrieve_selected_tracker_ids(@trackers)
581
581
582 if params[:year] and params[:year].to_i >0
582 if params[:year] and params[:year].to_i >0
583 @year_from = params[:year].to_i
583 @year_from = params[:year].to_i
584 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
584 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
585 @month_from = params[:month].to_i
585 @month_from = params[:month].to_i
586 else
586 else
587 @month_from = 1
587 @month_from = 1
588 end
588 end
589 else
589 else
590 @month_from ||= Date.today.month
590 @month_from ||= Date.today.month
591 @year_from ||= Date.today.year
591 @year_from ||= Date.today.year
592 end
592 end
593
593
594 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
594 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
595 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
595 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
596 months = (params[:months] || User.current.pref[:gantt_months]).to_i
596 months = (params[:months] || User.current.pref[:gantt_months]).to_i
597 @months = (months > 0 && months < 25) ? months : 6
597 @months = (months > 0 && months < 25) ? months : 6
598
598
599 # Save gantt paramters as user preference (zoom and months count)
599 # Save gantt paramters as user preference (zoom and months count)
600 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
600 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
601 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
601 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
602 User.current.preference.save
602 User.current.preference.save
603 end
603 end
604
604
605 @date_from = Date.civil(@year_from, @month_from, 1)
605 @date_from = Date.civil(@year_from, @month_from, 1)
606 @date_to = (@date_from >> @months) - 1
606 @date_to = (@date_from >> @months) - 1
607
607
608 @events = []
608 @events = []
609 @project.issues_with_subprojects(params[:with_subprojects]) do
609 @project.issues_with_subprojects(params[:with_subprojects]) do
610 @events += Issue.find(:all,
610 @events += Issue.find(:all,
611 :order => "start_date, due_date",
611 :order => "start_date, due_date",
612 :include => [:tracker, :status, :assigned_to, :priority, :project],
612 :include => [:tracker, :status, :assigned_to, :priority, :project],
613 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
613 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to]
614 ) unless @selected_tracker_ids.empty?
614 ) unless @selected_tracker_ids.empty?
615 end
615 end
616 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
616 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
617 @events.sort! {|x,y| x.start_date <=> y.start_date }
617 @events.sort! {|x,y| x.start_date <=> y.start_date }
618
618
619 if params[:format]=='pdf'
619 if params[:format]=='pdf'
620 @options_for_rfpdf ||= {}
620 @options_for_rfpdf ||= {}
621 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
621 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
622 render :template => "projects/gantt.rfpdf", :layout => false
622 render :template => "projects/gantt.rfpdf", :layout => false
623 elsif params[:format]=='png' && respond_to?('gantt_image')
623 elsif params[:format]=='png' && respond_to?('gantt_image')
624 image = gantt_image(@events, @date_from, @months, @zoom)
624 image = gantt_image(@events, @date_from, @months, @zoom)
625 image.format = 'PNG'
625 image.format = 'PNG'
626 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
626 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
627 else
627 else
628 render :template => "projects/gantt.rhtml"
628 render :template => "projects/gantt.rhtml"
629 end
629 end
630 end
630 end
631
631
632 private
632 private
633 # Find project of id params[:id]
633 # Find project of id params[:id]
634 # if not found, redirect to project list
634 # if not found, redirect to project list
635 # Used as a before_filter
635 # Used as a before_filter
636 def find_project
636 def find_project
637 @project = Project.find(params[:id])
637 @project = Project.find(params[:id])
638 rescue ActiveRecord::RecordNotFound
638 rescue ActiveRecord::RecordNotFound
639 render_404
639 render_404
640 end
640 end
641
641
642 def retrieve_selected_tracker_ids(selectable_trackers)
642 def retrieve_selected_tracker_ids(selectable_trackers)
643 if ids = params[:tracker_ids]
643 if ids = params[:tracker_ids]
644 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
644 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
645 else
645 else
646 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
646 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
647 end
647 end
648 end
648 end
649
649
650 # Retrieve query from session or build a new query
650 # Retrieve query from session or build a new query
651 def retrieve_query
651 def retrieve_query
652 if params[:query_id]
652 if params[:query_id]
653 @query = @project.queries.find(params[:query_id])
653 @query = @project.queries.find(params[:query_id])
654 @query.executed_by = logged_in_user
654 @query.executed_by = logged_in_user
655 session[:query] = @query
655 session[:query] = @query
656 else
656 else
657 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
657 if params[:set_filter] or !session[:query] or session[:query].project_id != @project.id
658 # Give it a name, required to be valid
658 # Give it a name, required to be valid
659 @query = Query.new(:name => "_", :executed_by => logged_in_user)
659 @query = Query.new(:name => "_", :executed_by => logged_in_user)
660 @query.project = @project
660 @query.project = @project
661 if params[:fields] and params[:fields].is_a? Array
661 if params[:fields] and params[:fields].is_a? Array
662 params[:fields].each do |field|
662 params[:fields].each do |field|
663 @query.add_filter(field, params[:operators][field], params[:values][field])
663 @query.add_filter(field, params[:operators][field], params[:values][field])
664 end
664 end
665 else
665 else
666 @query.available_filters.keys.each do |field|
666 @query.available_filters.keys.each do |field|
667 @query.add_short_filter(field, params[field]) if params[field]
667 @query.add_short_filter(field, params[field]) if params[field]
668 end
668 end
669 end
669 end
670 session[:query] = @query
670 session[:query] = @query
671 else
671 else
672 @query = session[:query]
672 @query = session[:query]
673 end
673 end
674 end
674 end
675 end
675 end
676 end
676 end
@@ -1,133 +1,130
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 ApplicationHelper
19 helper ApplicationHelper
20 helper IssuesHelper
20 helper IssuesHelper
21 helper CustomFieldsHelper
21 helper CustomFieldsHelper
22
22
23 def account_information(user, password)
23 def account_information(user, password)
24 set_language_if_valid user.language
24 set_language_if_valid user.language
25 recipients user.mail
25 recipients user.mail
26 from Setting.mail_from
26 from Setting.mail_from
27 subject l(:mail_subject_register)
27 subject l(:mail_subject_register)
28 body :user => user, :password => password
28 body :user => user, :password => password
29 end
29 end
30
30
31 def issue_add(issue)
31 def issue_add(issue)
32 set_language_if_valid(Setting.default_language)
32 set_language_if_valid(Setting.default_language)
33 # Sends to all project members
33 # Sends to all project members
34 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
34 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
35 # Sends to author and assignee (even if they turned off mail notification)
35 # Sends to author and assignee (even if they turned off mail notification)
36 @recipients << issue.author.mail if issue.author
36 @recipients << issue.author.mail if issue.author
37 @recipients << issue.assigned_to.mail if issue.assigned_to
37 @recipients << issue.assigned_to.mail if issue.assigned_to
38 @recipients.compact!
38 @recipients.compact!
39 @recipients.uniq!
39 @recipients.uniq!
40 @from = Setting.mail_from
40 @from = Setting.mail_from
41 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
41 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
42 @body['issue'] = issue
42 @body['issue'] = issue
43 end
43 end
44
44
45 def issue_edit(journal)
45 def issue_edit(journal)
46 set_language_if_valid(Setting.default_language)
46 set_language_if_valid(Setting.default_language)
47 # Sends to all project members
47 # Sends to all project members
48 issue = journal.journalized
48 issue = journal.journalized
49 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
49 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
50 # Sends to author and assignee (even if they turned off mail notification)
50 # Sends to author and assignee (even if they turned off mail notification)
51 @recipients << issue.author.mail if issue.author
51 @recipients << issue.author.mail if issue.author
52 @recipients << issue.assigned_to.mail if issue.assigned_to
52 @recipients << issue.assigned_to.mail if issue.assigned_to
53 @recipients.compact!
53 @recipients.compact!
54 @recipients.uniq!
54 @recipients.uniq!
55 # Watchers in cc
55 # Watchers in cc
56 @cc = issue.watcher_recipients - @recipients
56 @cc = issue.watcher_recipients - @recipients
57 @from = Setting.mail_from
57 @from = Setting.mail_from
58 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
58 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
59 @body['issue'] = issue
59 @body['issue'] = issue
60 @body['journal']= journal
60 @body['journal']= journal
61 end
61 end
62
62
63 def document_add(document)
63 def document_added(document)
64 set_language_if_valid(Setting.default_language)
64 set_language_if_valid(Setting.default_language)
65 @recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
65 @recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
66 @from = Setting.mail_from
66 @from = Setting.mail_from
67 @subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
67 @subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
68 @body['document'] = document
68 @body['document'] = document
69 end
69 end
70
70
71 def attachments_add(attachments)
71 def attachments_added(attachments)
72 set_language_if_valid(Setting.default_language)
72 set_language_if_valid(Setting.default_language)
73 container = attachments.first.container
73 container = attachments.first.container
74 url = ''
74 url = ''
75 added_to = ''
75 added_to = ''
76 case container.class.name
76 case container.class.name
77 when 'Version'
77 when 'Version'
78 url = url_for(:only_path => false, :host => Setting.host_name, :controller => 'projects', :action => 'list_files', :id => container.project_id)
78 url = {:only_path => false, :host => Setting.host_name, :controller => 'projects', :action => 'list_files', :id => container.project_id}
79 added_to = "#{l(:label_version)}: #{container.name}"
79 added_to = "#{l(:label_version)}: #{container.name}"
80 when 'Document'
80 when 'Document'
81 url = url_for(:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id)
81 url = {:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id}
82 added_to = "#{l(:label_document)}: #{container.title}"
82 added_to = "#{l(:label_document)}: #{container.title}"
83 when 'Issue'
84 url = url = url_for(:only_path => false, :host => Setting.host_name, :controller => 'issues', :action => 'show', :id => container.id)
85 added_to = "#{container.tracker.name} ##{container.id}: #{container.subject}"
86 end
83 end
87 @recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
84 @recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
88 @from = Setting.mail_from
85 @from = Setting.mail_from
89 @subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
86 @subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
90 @body['attachments'] = attachments
87 @body['attachments'] = attachments
91 @body['url'] = url
88 @body['url'] = url
92 @body['added_to'] = added_to
89 @body['added_to'] = added_to
93 end
90 end
94
91
95 def news_added(news)
92 def news_added(news)
96 set_language_if_valid(Setting.default_language)
93 set_language_if_valid(Setting.default_language)
97 @recipients = news.project.users.collect { |u| u.mail if u.mail_notification }.compact
94 @recipients = news.project.users.collect { |u| u.mail if u.mail_notification }.compact
98 @from = Setting.mail_from
95 @from = Setting.mail_from
99 @subject = "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
96 @subject = "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
100 @body['news'] = news
97 @body['news'] = news
101 end
98 end
102
99
103 def lost_password(token)
100 def lost_password(token)
104 set_language_if_valid(token.user.language)
101 set_language_if_valid(token.user.language)
105 @recipients = token.user.mail
102 @recipients = token.user.mail
106 @from = Setting.mail_from
103 @from = Setting.mail_from
107 @subject = l(:mail_subject_lost_password)
104 @subject = l(:mail_subject_lost_password)
108 @body['token'] = token
105 @body['token'] = token
109 end
106 end
110
107
111 def register(token)
108 def register(token)
112 set_language_if_valid(token.user.language)
109 set_language_if_valid(token.user.language)
113 @recipients = token.user.mail
110 @recipients = token.user.mail
114 @from = Setting.mail_from
111 @from = Setting.mail_from
115 @subject = l(:mail_subject_register)
112 @subject = l(:mail_subject_register)
116 @body['token'] = token
113 @body['token'] = token
117 end
114 end
118
115
119 def message_posted(message, recipients)
116 def message_posted(message, recipients)
120 set_language_if_valid(Setting.default_language)
117 set_language_if_valid(Setting.default_language)
121 @recipients = recipients
118 @recipients = recipients
122 @from = Setting.mail_from
119 @from = Setting.mail_from
123 @subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
120 @subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
124 @body['message'] = message
121 @body['message'] = message
125 end
122 end
126
123
127 def test(user)
124 def test(user)
128 set_language_if_valid(user.language)
125 set_language_if_valid(user.language)
129 @recipients = user.mail
126 @recipients = user.mail
130 @from = Setting.mail_from
127 @from = Setting.mail_from
131 @subject = 'Redmine'
128 @subject = 'Redmine'
132 end
129 end
133 end
130 end
@@ -1,63 +1,63
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
19
20 class MailerTest < Test::Unit::TestCase
20 class MailerTest < Test::Unit::TestCase
21 fixtures :projects, :issues, :users, :members, :documents, :attachments, :tokens, :journals, :journal_details, :trackers, :issue_statuses, :enumerations
21 fixtures :projects, :issues, :users, :members, :documents, :attachments, :tokens, :journals, :journal_details, :trackers, :issue_statuses, :enumerations
22
22
23 # test mailer methods for each language
23 # test mailer methods for each language
24 def test_issue_add
24 def test_issue_add
25 issue = Issue.find(1)
25 issue = Issue.find(1)
26 GLoc.valid_languages.each do |lang|
26 GLoc.valid_languages.each do |lang|
27 Setting.default_language = lang.to_s
27 Setting.default_language = lang.to_s
28 assert Mailer.deliver_issue_add(issue)
28 assert Mailer.deliver_issue_add(issue)
29 end
29 end
30 end
30 end
31
31
32 def test_issue_edit
32 def test_issue_edit
33 journal = Journal.find(1)
33 journal = Journal.find(1)
34 GLoc.valid_languages.each do |lang|
34 GLoc.valid_languages.each do |lang|
35 Setting.default_language = lang.to_s
35 Setting.default_language = lang.to_s
36 assert Mailer.deliver_issue_edit(journal)
36 assert Mailer.deliver_issue_edit(journal)
37 end
37 end
38 end
38 end
39
39
40 def test_document_add
40 def test_document_add
41 document = Document.find(1)
41 document = Document.find(1)
42 GLoc.valid_languages.each do |lang|
42 GLoc.valid_languages.each do |lang|
43 Setting.default_language = lang.to_s
43 Setting.default_language = lang.to_s
44 assert Mailer.deliver_document_add(document)
44 assert Mailer.deliver_document_added(document)
45 end
45 end
46 end
46 end
47
47
48 def test_lost_password
48 def test_lost_password
49 token = Token.find(2)
49 token = Token.find(2)
50 GLoc.valid_languages.each do |lang|
50 GLoc.valid_languages.each do |lang|
51 token.user.update_attribute :language, lang.to_s
51 token.user.update_attribute :language, lang.to_s
52 assert Mailer.deliver_lost_password(token)
52 assert Mailer.deliver_lost_password(token)
53 end
53 end
54 end
54 end
55
55
56 def test_register
56 def test_register
57 token = Token.find(1)
57 token = Token.find(1)
58 GLoc.valid_languages.each do |lang|
58 GLoc.valid_languages.each do |lang|
59 token.user.update_attribute :language, lang.to_s
59 token.user.update_attribute :language, lang.to_s
60 assert Mailer.deliver_register(token)
60 assert Mailer.deliver_register(token)
61 end
61 end
62 end
62 end
63 end No newline at end of file
63 end
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now