##// END OF EJS Templates
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
Jean-Philippe Lang -
r879:fa95501fe5e8
parent child
Show More
@@ -0,0 +1,39
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class JournalTest < Test::Unit::TestCase
21 fixtures :issues, :issue_statuses, :journals, :journal_details
22
23 def setup
24 @journal = Journal.find 1
25 end
26
27 def test_journalized_is_an_issue
28 issue = @journal.issue
29 assert_kind_of Issue, issue
30 assert_equal 1, issue.id
31 end
32
33 def test_new_status
34 status = @journal.new_status
35 assert_not_nil status
36 assert_kind_of IssueStatus, status
37 assert_equal 2, status.id
38 end
39 end
@@ -1,552 +1,553
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 ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 layout 'base'
19 layout 'base'
20 before_filter :find_project, :except => [ :index, :list, :add ]
20 before_filter :find_project, :except => [ :index, :list, :add ]
21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
21 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
22 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
23 accept_key_auth :activity, :calendar
23 accept_key_auth :activity, :calendar
24
24
25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
25 cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
26 cache_sweeper :issue_sweeper, :only => [ :add_issue ]
27 cache_sweeper :version_sweeper, :only => [ :add_version ]
27 cache_sweeper :version_sweeper, :only => [ :add_version ]
28
28
29 helper :sort
29 helper :sort
30 include SortHelper
30 include SortHelper
31 helper :custom_fields
31 helper :custom_fields
32 include CustomFieldsHelper
32 include CustomFieldsHelper
33 helper :ifpdf
33 helper :ifpdf
34 include IfpdfHelper
34 include IfpdfHelper
35 helper :issues
35 helper :issues
36 helper IssuesHelper
36 helper IssuesHelper
37 helper :queries
37 helper :queries
38 include QueriesHelper
38 include QueriesHelper
39 helper :repositories
39 helper :repositories
40 include RepositoriesHelper
40 include RepositoriesHelper
41 include ProjectsHelper
41 include ProjectsHelper
42
42
43 def index
43 def index
44 list
44 list
45 render :action => 'list' unless request.xhr?
45 render :action => 'list' unless request.xhr?
46 end
46 end
47
47
48 # Lists visible projects
48 # Lists visible projects
49 def list
49 def list
50 projects = Project.find :all,
50 projects = Project.find :all,
51 :conditions => Project.visible_by(logged_in_user),
51 :conditions => Project.visible_by(logged_in_user),
52 :include => :parent
52 :include => :parent
53 @project_tree = projects.group_by {|p| p.parent || p}
53 @project_tree = projects.group_by {|p| p.parent || p}
54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
54 @project_tree.each_key {|p| @project_tree[p] -= [p]}
55 end
55 end
56
56
57 # Add a new project
57 # Add a new project
58 def add
58 def add
59 @custom_fields = IssueCustomField.find(:all)
59 @custom_fields = IssueCustomField.find(:all)
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
61 @project = Project.new(params[:project])
61 @project = Project.new(params[:project])
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 if request.get?
63 if request.get?
64 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
64 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 else
65 else
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 @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)) }
67 @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)) }
68 @project.custom_values = @custom_values
68 @project.custom_values = @custom_values
69 if @project.save
69 if @project.save
70 @project.enabled_module_names = params[:enabled_modules]
70 @project.enabled_module_names = params[:enabled_modules]
71 flash[:notice] = l(:notice_successful_create)
71 flash[:notice] = l(:notice_successful_create)
72 redirect_to :controller => 'admin', :action => 'projects'
72 redirect_to :controller => 'admin', :action => 'projects'
73 end
73 end
74 end
74 end
75 end
75 end
76
76
77 # Show @project
77 # Show @project
78 def show
78 def show
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 @subprojects = @project.active_children
81 @subprojects = @project.active_children
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
83 @trackers = Tracker.find(:all, :order => 'position')
83 @trackers = Tracker.find(:all, :order => 'position')
84 @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])
84 @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])
85 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
85 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
86 @total_hours = @project.time_entries.sum(:hours)
86 @total_hours = @project.time_entries.sum(:hours)
87 @key = User.current.rss_key
87 @key = User.current.rss_key
88 end
88 end
89
89
90 def settings
90 def settings
91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
91 @root_projects = Project::find(:all, :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id])
92 @custom_fields = IssueCustomField.find(:all)
92 @custom_fields = IssueCustomField.find(:all)
93 @issue_category ||= IssueCategory.new
93 @issue_category ||= IssueCategory.new
94 @member ||= @project.members.new
94 @member ||= @project.members.new
95 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
95 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
96 @repository ||= @project.repository
96 @repository ||= @project.repository
97 @wiki ||= @project.wiki
97 @wiki ||= @project.wiki
98 end
98 end
99
99
100 # Edit @project
100 # Edit @project
101 def edit
101 def edit
102 if request.post?
102 if request.post?
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
104 if params[:custom_fields]
104 if params[:custom_fields]
105 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
106 @project.custom_values = @custom_values
106 @project.custom_values = @custom_values
107 end
107 end
108 @project.attributes = params[:project]
108 @project.attributes = params[:project]
109 if @project.save
109 if @project.save
110 flash[:notice] = l(:notice_successful_update)
110 flash[:notice] = l(:notice_successful_update)
111 redirect_to :action => 'settings', :id => @project
111 redirect_to :action => 'settings', :id => @project
112 else
112 else
113 settings
113 settings
114 render :action => 'settings'
114 render :action => 'settings'
115 end
115 end
116 end
116 end
117 end
117 end
118
118
119 def modules
119 def modules
120 @project.enabled_module_names = params[:enabled_modules]
120 @project.enabled_module_names = params[:enabled_modules]
121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
121 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
122 end
122 end
123
123
124 def archive
124 def archive
125 @project.archive if request.post? && @project.active?
125 @project.archive if request.post? && @project.active?
126 redirect_to :controller => 'admin', :action => 'projects'
126 redirect_to :controller => 'admin', :action => 'projects'
127 end
127 end
128
128
129 def unarchive
129 def unarchive
130 @project.unarchive if request.post? && !@project.active?
130 @project.unarchive if request.post? && !@project.active?
131 redirect_to :controller => 'admin', :action => 'projects'
131 redirect_to :controller => 'admin', :action => 'projects'
132 end
132 end
133
133
134 # Delete @project
134 # Delete @project
135 def destroy
135 def destroy
136 @project_to_destroy = @project
136 @project_to_destroy = @project
137 if request.post? and params[:confirm]
137 if request.post? and params[:confirm]
138 @project_to_destroy.destroy
138 @project_to_destroy.destroy
139 redirect_to :controller => 'admin', :action => 'projects'
139 redirect_to :controller => 'admin', :action => 'projects'
140 end
140 end
141 # hide project in layout
141 # hide project in layout
142 @project = nil
142 @project = nil
143 end
143 end
144
144
145 # Add a new issue category to @project
145 # Add a new issue category to @project
146 def add_issue_category
146 def add_issue_category
147 @category = @project.issue_categories.build(params[:category])
147 @category = @project.issue_categories.build(params[:category])
148 if request.post? and @category.save
148 if request.post? and @category.save
149 respond_to do |format|
149 respond_to do |format|
150 format.html do
150 format.html do
151 flash[:notice] = l(:notice_successful_create)
151 flash[:notice] = l(:notice_successful_create)
152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
152 redirect_to :action => 'settings', :tab => 'categories', :id => @project
153 end
153 end
154 format.js do
154 format.js do
155 # IE doesn't support the replace_html rjs method for select box options
155 # IE doesn't support the replace_html rjs method for select box options
156 render(:update) {|page| page.replace "issue_category_id",
156 render(:update) {|page| page.replace "issue_category_id",
157 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]')
157 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]')
158 }
158 }
159 end
159 end
160 end
160 end
161 end
161 end
162 end
162 end
163
163
164 # Add a new version to @project
164 # Add a new version to @project
165 def add_version
165 def add_version
166 @version = @project.versions.build(params[:version])
166 @version = @project.versions.build(params[:version])
167 if request.post? and @version.save
167 if request.post? and @version.save
168 flash[:notice] = l(:notice_successful_create)
168 flash[:notice] = l(:notice_successful_create)
169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
169 redirect_to :action => 'settings', :tab => 'versions', :id => @project
170 end
170 end
171 end
171 end
172
172
173 # Add a new document to @project
173 # Add a new document to @project
174 def add_document
174 def add_document
175 @document = @project.documents.build(params[:document])
175 @document = @project.documents.build(params[:document])
176 if request.post? and @document.save
176 if request.post? and @document.save
177 # Save the attachments
177 # Save the attachments
178 params[:attachments].each { |a|
178 params[:attachments].each { |a|
179 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
179 Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
180 } if params[:attachments] and params[:attachments].is_a? Array
180 } if params[:attachments] and params[:attachments].is_a? Array
181 flash[:notice] = l(:notice_successful_create)
181 flash[:notice] = l(:notice_successful_create)
182 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
182 Mailer.deliver_document_added(@document) if Setting.notified_events.include?('document_added')
183 redirect_to :action => 'list_documents', :id => @project
183 redirect_to :action => 'list_documents', :id => @project
184 end
184 end
185 end
185 end
186
186
187 # Show documents list of @project
187 # Show documents list of @project
188 def list_documents
188 def list_documents
189 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
189 @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
190 documents = @project.documents.find :all, :include => [:attachments, :category]
190 documents = @project.documents.find :all, :include => [:attachments, :category]
191 case @sort_by
191 case @sort_by
192 when 'date'
192 when 'date'
193 @grouped = documents.group_by {|d| d.created_on.to_date }
193 @grouped = documents.group_by {|d| d.created_on.to_date }
194 when 'title'
194 when 'title'
195 @grouped = documents.group_by {|d| d.title.first.upcase}
195 @grouped = documents.group_by {|d| d.title.first.upcase}
196 when 'author'
196 when 'author'
197 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
197 @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author}
198 else
198 else
199 @grouped = documents.group_by(&:category)
199 @grouped = documents.group_by(&:category)
200 end
200 end
201 render :layout => false if request.xhr?
201 render :layout => false if request.xhr?
202 end
202 end
203
203
204 # Add a new issue to @project
204 # Add a new issue to @project
205 # The new issue will be created from an existing one if copy_from parameter is given
205 # The new issue will be created from an existing one if copy_from parameter is given
206 def add_issue
206 def add_issue
207 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
207 @issue = params[:copy_from] ? Issue.new.copy_from(params[:copy_from]) : Issue.new(params[:issue])
208 @issue.project = @project
208 @issue.project = @project
209 @issue.author = User.current
209 @issue.author = User.current
210 @issue.tracker ||= Tracker.find(params[:tracker_id])
210 @issue.tracker ||= Tracker.find(params[:tracker_id])
211
211
212 default_status = IssueStatus.default
212 default_status = IssueStatus.default
213 unless default_status
213 unless default_status
214 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
214 flash.now[:error] = 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
215 render :nothing => true, :layout => true
215 render :nothing => true, :layout => true
216 return
216 return
217 end
217 end
218 @issue.status = default_status
218 @issue.status = default_status
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
219 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker))if logged_in_user
220
220
221 if request.get?
221 if request.get?
222 @issue.start_date ||= Date.today
222 @issue.start_date ||= Date.today
223 @custom_values = @issue.custom_values.empty? ?
223 @custom_values = @issue.custom_values.empty? ?
224 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
224 @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue) } :
225 @issue.custom_values
225 @issue.custom_values
226 else
226 else
227 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
227 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
228 # Check that the user is allowed to apply the requested status
228 # Check that the user is allowed to apply the requested status
229 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
229 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
230 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
230 @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
231 @issue.custom_values = @custom_values
231 @issue.custom_values = @custom_values
232 if @issue.save
232 if @issue.save
233 if params[:attachments] && params[:attachments].is_a?(Array)
233 if params[:attachments] && params[:attachments].is_a?(Array)
234 # Save attachments
234 # Save attachments
235 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
235 params[:attachments].each {|a| Attachment.create(:container => @issue, :file => a, :author => User.current) unless a.size == 0}
236 end
236 end
237 flash[:notice] = l(:notice_successful_create)
237 flash[:notice] = l(:notice_successful_create)
238 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
238 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
239 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
239 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
240 return
240 return
241 end
241 end
242 end
242 end
243 @priorities = Enumeration::get_values('IPRI')
243 @priorities = Enumeration::get_values('IPRI')
244 end
244 end
245
245
246 # Bulk edit issues
246 # Bulk edit issues
247 def bulk_edit_issues
247 def bulk_edit_issues
248 if request.post?
248 if request.post?
249 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
249 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
250 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
250 priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
251 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
251 assigned_to = params[:assigned_to_id].blank? ? nil : User.find_by_id(params[:assigned_to_id])
252 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
252 category = params[:category_id].blank? ? nil : @project.issue_categories.find_by_id(params[:category_id])
253 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
253 fixed_version = params[:fixed_version_id].blank? ? nil : @project.versions.find_by_id(params[:fixed_version_id])
254 issues = @project.issues.find_all_by_id(params[:issue_ids])
254 issues = @project.issues.find_all_by_id(params[:issue_ids])
255 unsaved_issue_ids = []
255 unsaved_issue_ids = []
256 issues.each do |issue|
256 issues.each do |issue|
257 journal = issue.init_journal(User.current, params[:notes])
257 journal = issue.init_journal(User.current, params[:notes])
258 issue.priority = priority if priority
258 issue.priority = priority if priority
259 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
259 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
260 issue.category = category if category
260 issue.category = category if category
261 issue.fixed_version = fixed_version if fixed_version
261 issue.fixed_version = fixed_version if fixed_version
262 issue.start_date = params[:start_date] unless params[:start_date].blank?
262 issue.start_date = params[:start_date] unless params[:start_date].blank?
263 issue.due_date = params[:due_date] unless params[:due_date].blank?
263 issue.due_date = params[:due_date] unless params[:due_date].blank?
264 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
264 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
265 # Don't save any change to the issue if the user is not authorized to apply the requested status
265 # Don't save any change to the issue if the user is not authorized to apply the requested status
266 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
266 if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save
267 # Send notification for each issue (if changed)
267 # Send notification for each issue (if changed)
268 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
268 Mailer.deliver_issue_edit(journal) if journal.details.any? && Setting.notified_events.include?('issue_updated')
269 else
269 else
270 # Keep unsaved issue ids to display them in flash error
270 # Keep unsaved issue ids to display them in flash error
271 unsaved_issue_ids << issue.id
271 unsaved_issue_ids << issue.id
272 end
272 end
273 end
273 end
274 if unsaved_issue_ids.empty?
274 if unsaved_issue_ids.empty?
275 flash[:notice] = l(:notice_successful_update) unless issues.empty?
275 flash[:notice] = l(:notice_successful_update) unless issues.empty?
276 else
276 else
277 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
277 flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, issues.size, '#' + unsaved_issue_ids.join(', #'))
278 end
278 end
279 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
279 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
280 return
280 return
281 end
281 end
282 if current_role && User.current.allowed_to?(:change_issue_status, @project)
282 if current_role && User.current.allowed_to?(:change_issue_status, @project)
283 # Find potential statuses the user could be allowed to switch issues to
283 # Find potential statuses the user could be allowed to switch issues to
284 @available_statuses = Workflow.find(:all, :include => :new_status,
284 @available_statuses = Workflow.find(:all, :include => :new_status,
285 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
285 :conditions => {:role_id => current_role.id}).collect(&:new_status).compact.uniq
286 end
286 end
287 render :update do |page|
287 render :update do |page|
288 page.hide 'query_form'
288 page.hide 'query_form'
289 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
289 page.replace_html 'bulk-edit', :partial => 'issues/bulk_edit_form'
290 end
290 end
291 end
291 end
292
292
293 def move_issues
293 def move_issues
294 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
294 @issues = @project.issues.find(params[:issue_ids]) if params[:issue_ids]
295 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
295 redirect_to :controller => 'issues', :action => 'index', :project_id => @project and return unless @issues
296 @projects = []
296 @projects = []
297 # find projects to which the user is allowed to move the issue
297 # find projects to which the user is allowed to move the issue
298 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
298 User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
299 # issue can be moved to any tracker
299 # issue can be moved to any tracker
300 @trackers = Tracker.find(:all)
300 @trackers = Tracker.find(:all)
301 if request.post? and params[:new_project_id] and params[:new_tracker_id]
301 if request.post? and params[:new_project_id] and params[:new_tracker_id]
302 new_project = Project.find_by_id(params[:new_project_id])
302 new_project = Project.find_by_id(params[:new_project_id])
303 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
303 new_tracker = Tracker.find_by_id(params[:new_tracker_id])
304 @issues.each do |i|
304 @issues.each do |i|
305 if new_project && i.project_id != new_project.id
305 if new_project && i.project_id != new_project.id
306 # issue is moved to another project
306 # issue is moved to another project
307 i.category = nil
307 i.category = nil
308 i.fixed_version = nil
308 i.fixed_version = nil
309 # delete issue relations
309 # delete issue relations
310 i.relations_from.clear
310 i.relations_from.clear
311 i.relations_to.clear
311 i.relations_to.clear
312 i.project = new_project
312 i.project = new_project
313 end
313 end
314 if new_tracker
314 if new_tracker
315 i.tracker = new_tracker
315 i.tracker = new_tracker
316 end
316 end
317 i.save
317 i.save
318 end
318 end
319 flash[:notice] = l(:notice_successful_update)
319 flash[:notice] = l(:notice_successful_update)
320 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
320 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
321 end
321 end
322 end
322 end
323
323
324 # Add a news to @project
324 # Add a news to @project
325 def add_news
325 def add_news
326 @news = News.new(:project => @project)
326 @news = News.new(:project => @project)
327 if request.post?
327 if request.post?
328 @news.attributes = params[:news]
328 @news.attributes = params[:news]
329 @news.author_id = self.logged_in_user.id if self.logged_in_user
329 @news.author_id = self.logged_in_user.id if self.logged_in_user
330 if @news.save
330 if @news.save
331 flash[:notice] = l(:notice_successful_create)
331 flash[:notice] = l(:notice_successful_create)
332 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
332 Mailer.deliver_news_added(@news) if Setting.notified_events.include?('news_added')
333 redirect_to :controller => 'news', :action => 'index', :project_id => @project
333 redirect_to :controller => 'news', :action => 'index', :project_id => @project
334 end
334 end
335 end
335 end
336 end
336 end
337
337
338 def add_file
338 def add_file
339 if request.post?
339 if request.post?
340 @version = @project.versions.find_by_id(params[:version_id])
340 @version = @project.versions.find_by_id(params[:version_id])
341 # Save the attachments
341 # Save the attachments
342 @attachments = []
342 @attachments = []
343 params[:attachments].each { |file|
343 params[:attachments].each { |file|
344 next unless file.size > 0
344 next unless file.size > 0
345 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
345 a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
346 @attachments << a unless a.new_record?
346 @attachments << a unless a.new_record?
347 } if params[:attachments] and params[:attachments].is_a? Array
347 } if params[:attachments] and params[:attachments].is_a? Array
348 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
348 Mailer.deliver_attachments_added(@attachments) if !@attachments.empty? && Setting.notified_events.include?('file_added')
349 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
349 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
350 end
350 end
351 @versions = @project.versions.sort
351 @versions = @project.versions.sort
352 end
352 end
353
353
354 def list_files
354 def list_files
355 @versions = @project.versions.sort
355 @versions = @project.versions.sort
356 end
356 end
357
357
358 # Show changelog for @project
358 # Show changelog for @project
359 def changelog
359 def changelog
360 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
360 @trackers = Tracker.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
361 retrieve_selected_tracker_ids(@trackers)
361 retrieve_selected_tracker_ids(@trackers)
362 @versions = @project.versions.sort
362 @versions = @project.versions.sort
363 end
363 end
364
364
365 def roadmap
365 def roadmap
366 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
366 @trackers = Tracker.find(:all, :conditions => ["is_in_roadmap=?", true], :order => 'position')
367 retrieve_selected_tracker_ids(@trackers)
367 retrieve_selected_tracker_ids(@trackers)
368 @versions = @project.versions.sort
368 @versions = @project.versions.sort
369 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
369 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
370 end
370 end
371
371
372 def activity
372 def activity
373 if params[:year] and params[:year].to_i > 1900
373 if params[:year] and params[:year].to_i > 1900
374 @year = params[:year].to_i
374 @year = params[:year].to_i
375 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
375 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
376 @month = params[:month].to_i
376 @month = params[:month].to_i
377 end
377 end
378 end
378 end
379 @year ||= Date.today.year
379 @year ||= Date.today.year
380 @month ||= Date.today.month
380 @month ||= Date.today.month
381
381
382 case params[:format]
382 case params[:format]
383 when 'atom'
383 when 'atom'
384 # 30 last days
384 # 30 last days
385 @date_from = Date.today - 30
385 @date_from = Date.today - 30
386 @date_to = Date.today + 1
386 @date_to = Date.today + 1
387 else
387 else
388 # current month
388 # current month
389 @date_from = Date.civil(@year, @month, 1)
389 @date_from = Date.civil(@year, @month, 1)
390 @date_to = @date_from >> 1
390 @date_to = @date_from >> 1
391 end
391 end
392
392
393 @event_types = %w(issues news files documents changesets wiki_pages messages)
393 @event_types = %w(issues news files documents changesets wiki_pages messages)
394 @event_types.delete('wiki_pages') unless @project.wiki
394 @event_types.delete('wiki_pages') unless @project.wiki
395 @event_types.delete('changesets') unless @project.repository
395 @event_types.delete('changesets') unless @project.repository
396 @event_types.delete('messages') unless @project.boards.any?
396 @event_types.delete('messages') unless @project.boards.any?
397 # only show what the user is allowed to view
397 # only show what the user is allowed to view
398 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
398 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
399
399
400 @scope = @event_types.select {|t| params["show_#{t}"]}
400 @scope = @event_types.select {|t| params["show_#{t}"]}
401 # default events if none is specified in parameters
401 # default events if none is specified in parameters
402 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
402 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
403
403
404 @events = []
404 @events = []
405
405
406 if @scope.include?('issues')
406 if @scope.include?('issues')
407 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
407 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
408 @events += @project.issues_status_changes(@date_from, @date_to)
408 end
409 end
409
410
410 if @scope.include?('news')
411 if @scope.include?('news')
411 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
412 @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
412 end
413 end
413
414
414 if @scope.include?('files')
415 if @scope.include?('files')
415 @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 )
416 @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 )
416 end
417 end
417
418
418 if @scope.include?('documents')
419 if @scope.include?('documents')
419 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
420 @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
420 @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 )
421 @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 )
421 end
422 end
422
423
423 if @scope.include?('wiki_pages')
424 if @scope.include?('wiki_pages')
424 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
425 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
425 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
426 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
426 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
427 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
427 "#{WikiContent.versioned_table_name}.id"
428 "#{WikiContent.versioned_table_name}.id"
428 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
429 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
429 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
430 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
430 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
431 conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
431 @project.id, @date_from, @date_to]
432 @project.id, @date_from, @date_to]
432
433
433 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
434 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
434 end
435 end
435
436
436 if @scope.include?('changesets')
437 if @scope.include?('changesets')
437 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
438 @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
438 end
439 end
439
440
440 if @scope.include?('messages')
441 if @scope.include?('messages')
441 @events += Message.find(:all,
442 @events += Message.find(:all,
442 :include => [:board, :author],
443 :include => [:board, :author],
443 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
444 :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", @project.id, @date_from, @date_to])
444 end
445 end
445
446
446 @events_by_day = @events.group_by(&:event_date)
447 @events_by_day = @events.group_by(&:event_date)
447
448
448 respond_to do |format|
449 respond_to do |format|
449 format.html { render :layout => false if request.xhr? }
450 format.html { render :layout => false if request.xhr? }
450 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
451 format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
451 end
452 end
452 end
453 end
453
454
454 def calendar
455 def calendar
455 @trackers = Tracker.find(:all, :order => 'position')
456 @trackers = Tracker.find(:all, :order => 'position')
456 retrieve_selected_tracker_ids(@trackers)
457 retrieve_selected_tracker_ids(@trackers)
457
458
458 if params[:year] and params[:year].to_i > 1900
459 if params[:year] and params[:year].to_i > 1900
459 @year = params[:year].to_i
460 @year = params[:year].to_i
460 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
461 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
461 @month = params[:month].to_i
462 @month = params[:month].to_i
462 end
463 end
463 end
464 end
464 @year ||= Date.today.year
465 @year ||= Date.today.year
465 @month ||= Date.today.month
466 @month ||= Date.today.month
466 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
467 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
467
468
468 events = []
469 events = []
469 @project.issues_with_subprojects(params[:with_subprojects]) do
470 @project.issues_with_subprojects(params[:with_subprojects]) do
470 events += Issue.find(:all,
471 events += Issue.find(:all,
471 :include => [:tracker, :status, :assigned_to, :priority, :project],
472 :include => [:tracker, :status, :assigned_to, :priority, :project],
472 :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]
473 :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]
473 ) unless @selected_tracker_ids.empty?
474 ) unless @selected_tracker_ids.empty?
474 end
475 end
475 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
476 events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
476 @calendar.events = events
477 @calendar.events = events
477
478
478 render :layout => false if request.xhr?
479 render :layout => false if request.xhr?
479 end
480 end
480
481
481 def gantt
482 def gantt
482 @trackers = Tracker.find(:all, :order => 'position')
483 @trackers = Tracker.find(:all, :order => 'position')
483 retrieve_selected_tracker_ids(@trackers)
484 retrieve_selected_tracker_ids(@trackers)
484
485
485 if params[:year] and params[:year].to_i >0
486 if params[:year] and params[:year].to_i >0
486 @year_from = params[:year].to_i
487 @year_from = params[:year].to_i
487 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
488 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
488 @month_from = params[:month].to_i
489 @month_from = params[:month].to_i
489 else
490 else
490 @month_from = 1
491 @month_from = 1
491 end
492 end
492 else
493 else
493 @month_from ||= Date.today.month
494 @month_from ||= Date.today.month
494 @year_from ||= Date.today.year
495 @year_from ||= Date.today.year
495 end
496 end
496
497
497 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
498 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
498 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
499 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
499 months = (params[:months] || User.current.pref[:gantt_months]).to_i
500 months = (params[:months] || User.current.pref[:gantt_months]).to_i
500 @months = (months > 0 && months < 25) ? months : 6
501 @months = (months > 0 && months < 25) ? months : 6
501
502
502 # Save gantt paramters as user preference (zoom and months count)
503 # Save gantt paramters as user preference (zoom and months count)
503 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
504 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
504 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
505 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
505 User.current.preference.save
506 User.current.preference.save
506 end
507 end
507
508
508 @date_from = Date.civil(@year_from, @month_from, 1)
509 @date_from = Date.civil(@year_from, @month_from, 1)
509 @date_to = (@date_from >> @months) - 1
510 @date_to = (@date_from >> @months) - 1
510
511
511 @events = []
512 @events = []
512 @project.issues_with_subprojects(params[:with_subprojects]) do
513 @project.issues_with_subprojects(params[:with_subprojects]) do
513 @events += Issue.find(:all,
514 @events += Issue.find(:all,
514 :order => "start_date, due_date",
515 :order => "start_date, due_date",
515 :include => [:tracker, :status, :assigned_to, :priority, :project],
516 :include => [:tracker, :status, :assigned_to, :priority, :project],
516 :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]
517 :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]
517 ) unless @selected_tracker_ids.empty?
518 ) unless @selected_tracker_ids.empty?
518 end
519 end
519 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
520 @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
520 @events.sort! {|x,y| x.start_date <=> y.start_date }
521 @events.sort! {|x,y| x.start_date <=> y.start_date }
521
522
522 if params[:format]=='pdf'
523 if params[:format]=='pdf'
523 @options_for_rfpdf ||= {}
524 @options_for_rfpdf ||= {}
524 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
525 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
525 render :template => "projects/gantt.rfpdf", :layout => false
526 render :template => "projects/gantt.rfpdf", :layout => false
526 elsif params[:format]=='png' && respond_to?('gantt_image')
527 elsif params[:format]=='png' && respond_to?('gantt_image')
527 image = gantt_image(@events, @date_from, @months, @zoom)
528 image = gantt_image(@events, @date_from, @months, @zoom)
528 image.format = 'PNG'
529 image.format = 'PNG'
529 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
530 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
530 else
531 else
531 render :template => "projects/gantt.rhtml"
532 render :template => "projects/gantt.rhtml"
532 end
533 end
533 end
534 end
534
535
535 private
536 private
536 # Find project of id params[:id]
537 # Find project of id params[:id]
537 # if not found, redirect to project list
538 # if not found, redirect to project list
538 # Used as a before_filter
539 # Used as a before_filter
539 def find_project
540 def find_project
540 @project = Project.find(params[:id])
541 @project = Project.find(params[:id])
541 rescue ActiveRecord::RecordNotFound
542 rescue ActiveRecord::RecordNotFound
542 render_404
543 render_404
543 end
544 end
544
545
545 def retrieve_selected_tracker_ids(selectable_trackers)
546 def retrieve_selected_tracker_ids(selectable_trackers)
546 if ids = params[:tracker_ids]
547 if ids = params[:tracker_ids]
547 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
548 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
548 else
549 else
549 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
550 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
550 end
551 end
551 end
552 end
552 end
553 end
@@ -1,40 +1,47
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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 Journal < ActiveRecord::Base
18 class Journal < ActiveRecord::Base
19 belongs_to :journalized, :polymorphic => true
19 belongs_to :journalized, :polymorphic => true
20 # added as a quick fix to allow eager loading of the polymorphic association
20 # added as a quick fix to allow eager loading of the polymorphic association
21 # since always associated to an issue, for now
21 # since always associated to an issue, for now
22 belongs_to :issue, :foreign_key => :journalized_id
22 belongs_to :issue, :foreign_key => :journalized_id
23
23
24 belongs_to :user
24 belongs_to :user
25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
26
26
27 acts_as_searchable :columns => 'notes',
27 acts_as_searchable :columns => 'notes',
28 :include => :issue,
28 :include => :issue,
29 :project_key => "#{Issue.table_name}.project_id",
29 :project_key => "#{Issue.table_name}.project_id",
30 :date_column => "#{Issue.table_name}.created_on"
30 :date_column => "#{Issue.table_name}.created_on"
31
31
32 acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}"},
32 acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}" + ((s = o.new_status) ? " (#{s})" : '') },
33 :description => :notes,
33 :description => :notes,
34 :author => :user,
34 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}}
35 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}}
35
36
36 def save
37 def save
37 # Do not save an empty journal
38 # Do not save an empty journal
38 (details.empty? && notes.blank?) ? false : super
39 (details.empty? && notes.blank?) ? false : super
39 end
40 end
41
42 # Returns the new status if the journal contains a status change, otherwise nil
43 def new_status
44 c = details.detect {|detail| detail.prop_key == 'status_id'}
45 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
46 end
40 end
47 end
@@ -1,178 +1,188
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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 Project < ActiveRecord::Base
18 class Project < ActiveRecord::Base
19 # Project statuses
19 # Project statuses
20 STATUS_ACTIVE = 1
20 STATUS_ACTIVE = 1
21 STATUS_ARCHIVED = 9
21 STATUS_ARCHIVED = 9
22
22
23 has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
23 has_many :members, :dependent => :delete_all, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}"
24 has_many :users, :through => :members
24 has_many :users, :through => :members
25 has_many :custom_values, :dependent => :delete_all, :as => :customized
25 has_many :custom_values, :dependent => :delete_all, :as => :customized
26 has_many :enabled_modules, :dependent => :delete_all
26 has_many :enabled_modules, :dependent => :delete_all
27 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
27 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
28 has_many :issue_changes, :through => :issues, :source => :journals
28 has_many :issue_changes, :through => :issues, :source => :journals
29 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
29 has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC"
30 has_many :time_entries, :dependent => :delete_all
30 has_many :time_entries, :dependent => :delete_all
31 has_many :queries, :dependent => :delete_all
31 has_many :queries, :dependent => :delete_all
32 has_many :documents, :dependent => :destroy
32 has_many :documents, :dependent => :destroy
33 has_many :news, :dependent => :delete_all, :include => :author
33 has_many :news, :dependent => :delete_all, :include => :author
34 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
34 has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name"
35 has_many :boards, :order => "position ASC"
35 has_many :boards, :order => "position ASC"
36 has_one :repository, :dependent => :destroy
36 has_one :repository, :dependent => :destroy
37 has_many :changesets, :through => :repository
37 has_many :changesets, :through => :repository
38 has_one :wiki, :dependent => :destroy
38 has_one :wiki, :dependent => :destroy
39 has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
39 has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
40 acts_as_tree :order => "name", :counter_cache => true
40 acts_as_tree :order => "name", :counter_cache => true
41
41
42 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
42 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
43 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
43 acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
44 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}
44 :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}
45
45
46 attr_protected :status, :enabled_module_names
46 attr_protected :status, :enabled_module_names
47
47
48 validates_presence_of :name, :description, :identifier
48 validates_presence_of :name, :description, :identifier
49 validates_uniqueness_of :name, :identifier
49 validates_uniqueness_of :name, :identifier
50 validates_associated :custom_values, :on => :update
50 validates_associated :custom_values, :on => :update
51 validates_associated :repository, :wiki
51 validates_associated :repository, :wiki
52 validates_length_of :name, :maximum => 30
52 validates_length_of :name, :maximum => 30
53 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
53 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
54 validates_length_of :description, :maximum => 255
54 validates_length_of :description, :maximum => 255
55 validates_length_of :homepage, :maximum => 60
55 validates_length_of :homepage, :maximum => 60
56 validates_length_of :identifier, :in => 3..12
56 validates_length_of :identifier, :in => 3..12
57 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
57 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
58
58
59 def identifier=(identifier)
59 def identifier=(identifier)
60 super unless identifier_frozen?
60 super unless identifier_frozen?
61 end
61 end
62
62
63 def identifier_frozen?
63 def identifier_frozen?
64 errors[:identifier].nil? && !(new_record? || identifier.blank?)
64 errors[:identifier].nil? && !(new_record? || identifier.blank?)
65 end
65 end
66
66
67 def issues_with_subprojects(include_subprojects=false)
67 def issues_with_subprojects(include_subprojects=false)
68 conditions = nil
68 conditions = nil
69 if include_subprojects && !active_children.empty?
69 if include_subprojects && !active_children.empty?
70 ids = [id] + active_children.collect {|c| c.id}
70 ids = [id] + active_children.collect {|c| c.id}
71 conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
71 conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"]
72 end
72 end
73 conditions ||= ["#{Issue.table_name}.project_id = ?", id]
73 conditions ||= ["#{Issue.table_name}.project_id = ?", id]
74 Issue.with_scope :find => { :conditions => conditions } do
74 Issue.with_scope :find => { :conditions => conditions } do
75 yield
75 yield
76 end
76 end
77 end
77 end
78
78
79 # Return all issues status changes for the project between the 2 given dates
80 def issues_status_changes(from, to)
81 Journal.find(:all, :include => [:issue, :details, :user],
82 :conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" +
83 " AND #{Issue.table_name}.project_id = ?" +
84 " AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
85 " AND #{Journal.table_name}.created_on BETWEEN ? AND ?",
86 id, from, to+1])
87 end
88
79 # returns latest created projects
89 # returns latest created projects
80 # non public projects will be returned only if user is a member of those
90 # non public projects will be returned only if user is a member of those
81 def self.latest(user=nil, count=5)
91 def self.latest(user=nil, count=5)
82 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
92 find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
83 end
93 end
84
94
85 def self.visible_by(user=nil)
95 def self.visible_by(user=nil)
86 if user && user.admin?
96 if user && user.admin?
87 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
97 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
88 elsif user && user.memberships.any?
98 elsif user && user.memberships.any?
89 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
99 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
90 else
100 else
91 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
101 return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}"
92 end
102 end
93 end
103 end
94
104
95 def active?
105 def active?
96 self.status == STATUS_ACTIVE
106 self.status == STATUS_ACTIVE
97 end
107 end
98
108
99 def archive
109 def archive
100 # Archive subprojects if any
110 # Archive subprojects if any
101 children.each do |subproject|
111 children.each do |subproject|
102 subproject.archive
112 subproject.archive
103 end
113 end
104 update_attribute :status, STATUS_ARCHIVED
114 update_attribute :status, STATUS_ARCHIVED
105 end
115 end
106
116
107 def unarchive
117 def unarchive
108 return false if parent && !parent.active?
118 return false if parent && !parent.active?
109 update_attribute :status, STATUS_ACTIVE
119 update_attribute :status, STATUS_ACTIVE
110 end
120 end
111
121
112 def active_children
122 def active_children
113 children.select {|child| child.active?}
123 children.select {|child| child.active?}
114 end
124 end
115
125
116 # Users issues can be assigned to
126 # Users issues can be assigned to
117 def assignable_users
127 def assignable_users
118 members.select {|m| m.role.assignable?}.collect {|m| m.user}
128 members.select {|m| m.role.assignable?}.collect {|m| m.user}
119 end
129 end
120
130
121 # Returns the mail adresses of users that should be always notified on project events
131 # Returns the mail adresses of users that should be always notified on project events
122 def recipients
132 def recipients
123 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
133 members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail}
124 end
134 end
125
135
126 # Returns an array of all custom fields enabled for project issues
136 # Returns an array of all custom fields enabled for project issues
127 # (explictly associated custom fields and custom fields enabled for all projects)
137 # (explictly associated custom fields and custom fields enabled for all projects)
128 def custom_fields_for_issues(tracker)
138 def custom_fields_for_issues(tracker)
129 all_custom_fields.select {|c| tracker.custom_fields.include? c }
139 all_custom_fields.select {|c| tracker.custom_fields.include? c }
130 end
140 end
131
141
132 def all_custom_fields
142 def all_custom_fields
133 @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
143 @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq
134 end
144 end
135
145
136 def <=>(project)
146 def <=>(project)
137 name <=> project.name
147 name <=> project.name
138 end
148 end
139
149
140 def allows_to?(action)
150 def allows_to?(action)
141 if action.is_a? Hash
151 if action.is_a? Hash
142 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
152 allowed_actions.include? "#{action[:controller]}/#{action[:action]}"
143 else
153 else
144 allowed_permissions.include? action
154 allowed_permissions.include? action
145 end
155 end
146 end
156 end
147
157
148 def module_enabled?(module_name)
158 def module_enabled?(module_name)
149 module_name = module_name.to_s
159 module_name = module_name.to_s
150 enabled_modules.detect {|m| m.name == module_name}
160 enabled_modules.detect {|m| m.name == module_name}
151 end
161 end
152
162
153 def enabled_module_names=(module_names)
163 def enabled_module_names=(module_names)
154 enabled_modules.clear
164 enabled_modules.clear
155 module_names = [] unless module_names && module_names.is_a?(Array)
165 module_names = [] unless module_names && module_names.is_a?(Array)
156 module_names.each do |name|
166 module_names.each do |name|
157 enabled_modules << EnabledModule.new(:name => name.to_s)
167 enabled_modules << EnabledModule.new(:name => name.to_s)
158 end
168 end
159 end
169 end
160
170
161 protected
171 protected
162 def validate
172 def validate
163 errors.add(parent_id, " must be a root project") if parent and parent.parent
173 errors.add(parent_id, " must be a root project") if parent and parent.parent
164 errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
174 errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
165 end
175 end
166
176
167 private
177 private
168 def allowed_permissions
178 def allowed_permissions
169 @allowed_permissions ||= begin
179 @allowed_permissions ||= begin
170 module_names = enabled_modules.collect {|m| m.name}
180 module_names = enabled_modules.collect {|m| m.name}
171 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
181 Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name}
172 end
182 end
173 end
183 end
174
184
175 def allowed_actions
185 def allowed_actions
176 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
186 @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten
177 end
187 end
178 end
188 end
@@ -1,41 +1,41
1 <h2><%=l(:label_activity)%>: <%= "#{month_name(@month).downcase} #{@year}" %></h2>
1 <h2><%=l(:label_activity)%>: <%= "#{month_name(@month).downcase} #{@year}" %></h2>
2
2
3 <% @events_by_day.keys.sort {|x,y| y <=> x }.each do |day| %>
3 <% @events_by_day.keys.sort {|x,y| y <=> x }.each do |day| %>
4 <h3><%= day_name(day.cwday) %> <%= day.day %></h3>
4 <h3><%= day_name(day.cwday) %> <%= day.day %></h3>
5 <ul>
5 <ul>
6 <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
6 <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
7 <li><p><%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
7 <li><p><%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
8 <% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
8 <% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
9 <span class="author"><%= e.event_author if e.respond_to?(:author) %></span></p></li>
9 <span class="author"><%= e.event_author if e.respond_to?(:event_author) %></span></p></li>
10 <% end %>
10 <% end %>
11 </ul>
11 </ul>
12 <% end %>
12 <% end %>
13
13
14 <% if @events_by_day.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>
14 <% if @events_by_day.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>
15
15
16 <div style="float:left;">
16 <div style="float:left;">
17 <% prev_params = params.clone.update :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) %>
17 <% prev_params = params.clone.update :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) %>
18 <%= link_to_remote ('&#171; ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
18 <%= link_to_remote ('&#171; ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
19 {:update => "content", :url => prev_params}, {:href => url_for(prev_params)} %>
19 {:update => "content", :url => prev_params}, {:href => url_for(prev_params)} %>
20 </div>
20 </div>
21 <div style="float:right;">
21 <div style="float:right;">
22 <% next_params = params.clone.update :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) %>
22 <% next_params = params.clone.update :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) %>
23 <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' &#187;'),
23 <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' &#187;'),
24 {:update => "content", :url => next_params}, {:href => url_for(next_params)} %>
24 {:update => "content", :url => next_params}, {:href => url_for(next_params)} %>
25 &nbsp;
25 &nbsp;
26 </div>
26 </div>
27 <br />
27 <br />
28
28
29 <% content_for :header_tags do %>
29 <% content_for :header_tags do %>
30 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :year => nil, :month => nil, :key => User.current.rss_key})) %>
30 <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :year => nil, :month => nil, :key => User.current.rss_key})) %>
31 <% end %>
31 <% end %>
32
32
33 <% content_for :sidebar do %>
33 <% content_for :sidebar do %>
34 <% form_tag do %>
34 <% form_tag do %>
35 <h3><%= l(:label_activity) %></h3>
35 <h3><%= l(:label_activity) %></h3>
36 <p><% @event_types.each do |t| %>
36 <p><% @event_types.each do |t| %>
37 <label><%= check_box_tag "show_#{t}", 1, @scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label><br />
37 <label><%= check_box_tag "show_#{t}", 1, @scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label><br />
38 <% end %></p>
38 <% end %></p>
39 <p><%= submit_tag l(:button_apply), :class => 'button-small' %></p>
39 <p><%= submit_tag l(:button_apply), :class => 'button-small' %></p>
40 <% end %>
40 <% end %>
41 <% end %>
41 <% end %>
@@ -1,58 +1,58
1 ---
1 ---
2 issues_001:
2 issues_001:
3 created_on: 2006-07-19 21:02:17 +02:00
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
4 project_id: 1
4 project_id: 1
5 updated_on: 2006-07-19 21:04:30 +02:00
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
6 priority_id: 4
6 priority_id: 4
7 subject: Can't print recipes
7 subject: Can't print recipes
8 id: 1
8 id: 1
9 fixed_version_id:
9 fixed_version_id:
10 category_id: 1
10 category_id: 1
11 description: Unable to print recipes
11 description: Unable to print recipes
12 tracker_id: 1
12 tracker_id: 1
13 assigned_to_id:
13 assigned_to_id:
14 author_id: 2
14 author_id: 2
15 status_id: 1
15 status_id: 1
16 issues_002:
16 issues_002:
17 created_on: 2006-07-19 21:04:21 +02:00
17 created_on: 2006-07-19 21:04:21 +02:00
18 project_id: 1
18 project_id: 1
19 updated_on: 2006-07-19 21:09:50 +02:00
19 updated_on: 2006-07-19 21:09:50 +02:00
20 priority_id: 5
20 priority_id: 5
21 subject: Add ingredients categories
21 subject: Add ingredients categories
22 id: 2
22 id: 2
23 fixed_version_id:
23 fixed_version_id:
24 category_id:
24 category_id:
25 description: Ingredients should be classified by categories
25 description: Ingredients should be classified by categories
26 tracker_id: 2
26 tracker_id: 2
27 assigned_to_id: 3
27 assigned_to_id: 3
28 author_id: 2
28 author_id: 2
29 status_id: 2
29 status_id: 2
30 issues_003:
30 issues_003:
31 created_on: 2006-07-19 21:07:27 +02:00
31 created_on: 2006-07-19 21:07:27 +02:00
32 project_id: 1
32 project_id: 1
33 updated_on: 2006-07-19 21:07:27 +02:00
33 updated_on: 2006-07-19 21:07:27 +02:00
34 priority_id: 4
34 priority_id: 4
35 subject: Error 281 when updating a recipe
35 subject: Error 281 when updating a recipe
36 id: 3
36 id: 3
37 fixed_version_id:
37 fixed_version_id:
38 category_id:
38 category_id:
39 description: Error 281 is encountered when saving a recipe
39 description: Error 281 is encountered when saving a recipe
40 tracker_id: 1
40 tracker_id: 1
41 assigned_to_id:
41 assigned_to_id:
42 author_id: 2
42 author_id: 2
43 status_id: 1
43 status_id: 1
44 issues_004:
44 issues_004:
45 created_on: 2006-07-19 21:07:27 +02:00
45 created_on: 2006-07-19 21:07:27 +02:00
46 project_id: 2
46 project_id: 2
47 updated_on: 2006-07-19 21:07:27 +02:00
47 updated_on: 2006-07-19 21:07:27 +02:00
48 priority_id: 4
48 priority_id: 4
49 subject: Issue on project 2
49 subject: Issue on project 2
50 id: 4
50 id: 4
51 fixed_version_id:
51 fixed_version_id:
52 category_id:
52 category_id:
53 description: Issue on project 2
53 description: Issue on project 2
54 tracker_id: 1
54 tracker_id: 1
55 assigned_to_id:
55 assigned_to_id:
56 author_id: 2
56 author_id: 2
57 status_id: 1
57 status_id: 1
58
58
@@ -1,8 +1,8
1 ---
1 ---
2 journals_001:
2 journals_001:
3 created_on: 2007-01-26 19:58:40 +01:00
3 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4 notes: "Journal notes"
4 notes: "Journal notes"
5 id: 1
5 id: 1
6 journalized_type: Issue
6 journalized_type: Issue
7 user_id: 1
7 user_id: 1
8 journalized_id: 1
8 journalized_id: 1
@@ -1,131 +1,149
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 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
25 fixtures :projects, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :issue_statuses, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 end
31 end
32
32
33 def test_index
33 def test_index
34 get :index
34 get :index
35 assert_response :success
35 assert_response :success
36 assert_template 'list'
36 assert_template 'list'
37 end
37 end
38
38
39 def test_list
39 def test_list
40 get :list
40 get :list
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:project_tree)
43 assert_not_nil assigns(:project_tree)
44 end
44 end
45
45
46 def test_show
46 def test_show
47 get :show, :id => 1
47 get :show, :id => 1
48 assert_response :success
48 assert_response :success
49 assert_template 'show'
49 assert_template 'show'
50 assert_not_nil assigns(:project)
50 assert_not_nil assigns(:project)
51 end
51 end
52
52
53 def test_list_documents
53 def test_list_documents
54 get :list_documents, :id => 1
54 get :list_documents, :id => 1
55 assert_response :success
55 assert_response :success
56 assert_template 'list_documents'
56 assert_template 'list_documents'
57 assert_not_nil assigns(:grouped)
57 assert_not_nil assigns(:grouped)
58 end
58 end
59
59
60 def test_bulk_edit_issues
60 def test_bulk_edit_issues
61 @request.session[:user_id] = 2
61 @request.session[:user_id] = 2
62 # update issues priority
62 # update issues priority
63 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
63 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
64 assert_response 302
64 assert_response 302
65 # check that the issues were updated
65 # check that the issues were updated
66 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
66 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
67 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
67 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
68 end
68 end
69
69
70 def test_list_files
70 def test_list_files
71 get :list_files, :id => 1
71 get :list_files, :id => 1
72 assert_response :success
72 assert_response :success
73 assert_template 'list_files'
73 assert_template 'list_files'
74 assert_not_nil assigns(:versions)
74 assert_not_nil assigns(:versions)
75 end
75 end
76
76
77 def test_changelog
77 def test_changelog
78 get :changelog, :id => 1
78 get :changelog, :id => 1
79 assert_response :success
79 assert_response :success
80 assert_template 'changelog'
80 assert_template 'changelog'
81 assert_not_nil assigns(:versions)
81 assert_not_nil assigns(:versions)
82 end
82 end
83
83
84 def test_roadmap
84 def test_roadmap
85 get :roadmap, :id => 1
85 get :roadmap, :id => 1
86 assert_response :success
86 assert_response :success
87 assert_template 'roadmap'
87 assert_template 'roadmap'
88 assert_not_nil assigns(:versions)
88 assert_not_nil assigns(:versions)
89 end
89 end
90
90
91 def test_activity
91 def test_activity
92 get :activity, :id => 1
92 get :activity, :id => 1
93 assert_response :success
93 assert_response :success
94 assert_template 'activity'
94 assert_template 'activity'
95 assert_not_nil assigns(:events_by_day)
95 assert_not_nil assigns(:events_by_day)
96
97 assert_tag :tag => "h3",
98 :content => /#{2.days.ago.to_date.day}/,
99 :sibling => { :tag => "ul",
100 :child => { :tag => "li",
101 :child => { :tag => "p",
102 :content => /(#{IssueStatus.find(2).name})/,
103 }
104 }
105 }
106 assert_tag :tag => "h3",
107 :content => /#{3.day.ago.to_date.day}/,
108 :sibling => { :tag => "ul", :child => { :tag => "li",
109 :child => { :tag => "p",
110 :content => /#{Issue.find(1).subject}/,
111 }
112 }
113 }
96 end
114 end
97
115
98 def test_archive
116 def test_archive
99 @request.session[:user_id] = 1 # admin
117 @request.session[:user_id] = 1 # admin
100 post :archive, :id => 1
118 post :archive, :id => 1
101 assert_redirected_to 'admin/projects'
119 assert_redirected_to 'admin/projects'
102 assert !Project.find(1).active?
120 assert !Project.find(1).active?
103 end
121 end
104
122
105 def test_unarchive
123 def test_unarchive
106 @request.session[:user_id] = 1 # admin
124 @request.session[:user_id] = 1 # admin
107 Project.find(1).archive
125 Project.find(1).archive
108 post :unarchive, :id => 1
126 post :unarchive, :id => 1
109 assert_redirected_to 'admin/projects'
127 assert_redirected_to 'admin/projects'
110 assert Project.find(1).active?
128 assert Project.find(1).active?
111 end
129 end
112
130
113 def test_add_issue
131 def test_add_issue
114 @request.session[:user_id] = 2
132 @request.session[:user_id] = 2
115 get :add_issue, :id => 1, :tracker_id => 1
133 get :add_issue, :id => 1, :tracker_id => 1
116 assert_response :success
134 assert_response :success
117 assert_template 'add_issue'
135 assert_template 'add_issue'
118 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
136 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
119 assert_redirected_to 'projects/1/issues'
137 assert_redirected_to 'projects/1/issues'
120 assert Issue.find_by_subject('This is the test_add_issue issue')
138 assert Issue.find_by_subject('This is the test_add_issue issue')
121 end
139 end
122
140
123 def test_copy_issue
141 def test_copy_issue
124 @request.session[:user_id] = 2
142 @request.session[:user_id] = 2
125 get :add_issue, :id => 1, :copy_from => 1
143 get :add_issue, :id => 1, :copy_from => 1
126 assert_template 'add_issue'
144 assert_template 'add_issue'
127 assert_not_nil assigns(:issue)
145 assert_not_nil assigns(:issue)
128 orig = Issue.find(1)
146 orig = Issue.find(1)
129 assert_equal orig.subject, assigns(:issue).subject
147 assert_equal orig.subject, assigns(:issue).subject
130 end
148 end
131 end
149 end
@@ -1,107 +1,116
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 ProjectTest < Test::Unit::TestCase
20 class ProjectTest < Test::Unit::TestCase
21 fixtures :projects
21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details
22
22
23 def setup
23 def setup
24 @ecookbook = Project.find(1)
24 @ecookbook = Project.find(1)
25 @ecookbook_sub1 = Project.find(3)
25 @ecookbook_sub1 = Project.find(3)
26 end
26 end
27
27
28 def test_truth
28 def test_truth
29 assert_kind_of Project, @ecookbook
29 assert_kind_of Project, @ecookbook
30 assert_equal "eCookbook", @ecookbook.name
30 assert_equal "eCookbook", @ecookbook.name
31 end
31 end
32
32
33 def test_update
33 def test_update
34 assert_equal "eCookbook", @ecookbook.name
34 assert_equal "eCookbook", @ecookbook.name
35 @ecookbook.name = "eCook"
35 @ecookbook.name = "eCook"
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
37 @ecookbook.reload
37 @ecookbook.reload
38 assert_equal "eCook", @ecookbook.name
38 assert_equal "eCook", @ecookbook.name
39 end
39 end
40
40
41 def test_validate
41 def test_validate
42 @ecookbook.name = ""
42 @ecookbook.name = ""
43 assert !@ecookbook.save
43 assert !@ecookbook.save
44 assert_equal 1, @ecookbook.errors.count
44 assert_equal 1, @ecookbook.errors.count
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
46 end
46 end
47
47
48 def test_public_projects
48 def test_public_projects
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
50 assert_equal 3, public_projects.length
50 assert_equal 3, public_projects.length
51 assert_equal true, public_projects[0].is_public?
51 assert_equal true, public_projects[0].is_public?
52 end
52 end
53
53
54 def test_archive
54 def test_archive
55 user = @ecookbook.members.first.user
55 user = @ecookbook.members.first.user
56 @ecookbook.archive
56 @ecookbook.archive
57 @ecookbook.reload
57 @ecookbook.reload
58
58
59 assert !@ecookbook.active?
59 assert !@ecookbook.active?
60 assert !user.projects.include?(@ecookbook)
60 assert !user.projects.include?(@ecookbook)
61 # Subproject are also archived
61 # Subproject are also archived
62 assert !@ecookbook.children.empty?
62 assert !@ecookbook.children.empty?
63 assert @ecookbook.active_children.empty?
63 assert @ecookbook.active_children.empty?
64 end
64 end
65
65
66 def test_unarchive
66 def test_unarchive
67 user = @ecookbook.members.first.user
67 user = @ecookbook.members.first.user
68 @ecookbook.archive
68 @ecookbook.archive
69 # A subproject of an archived project can not be unarchived
69 # A subproject of an archived project can not be unarchived
70 assert !@ecookbook_sub1.unarchive
70 assert !@ecookbook_sub1.unarchive
71
71
72 # Unarchive project
72 # Unarchive project
73 assert @ecookbook.unarchive
73 assert @ecookbook.unarchive
74 @ecookbook.reload
74 @ecookbook.reload
75 assert @ecookbook.active?
75 assert @ecookbook.active?
76 assert user.projects.include?(@ecookbook)
76 assert user.projects.include?(@ecookbook)
77 # Subproject can now be unarchived
77 # Subproject can now be unarchived
78 @ecookbook_sub1.reload
78 @ecookbook_sub1.reload
79 assert @ecookbook_sub1.unarchive
79 assert @ecookbook_sub1.unarchive
80 end
80 end
81
81
82 def test_destroy
82 def test_destroy
83 @ecookbook.destroy
83 @ecookbook.destroy
84 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
84 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
85 end
85 end
86
86
87 def test_subproject_ok
87 def test_subproject_ok
88 sub = Project.find(2)
88 sub = Project.find(2)
89 sub.parent = @ecookbook
89 sub.parent = @ecookbook
90 assert sub.save
90 assert sub.save
91 assert_equal @ecookbook.id, sub.parent.id
91 assert_equal @ecookbook.id, sub.parent.id
92 @ecookbook.reload
92 @ecookbook.reload
93 assert_equal 3, @ecookbook.children.size
93 assert_equal 3, @ecookbook.children.size
94 end
94 end
95
95
96 def test_subproject_invalid
96 def test_subproject_invalid
97 sub = Project.find(2)
97 sub = Project.find(2)
98 sub.parent = @ecookbook_sub1
98 sub.parent = @ecookbook_sub1
99 assert !sub.save
99 assert !sub.save
100 end
100 end
101
101
102 def test_subproject_invalid_2
102 def test_subproject_invalid_2
103 sub = @ecookbook
103 sub = @ecookbook
104 sub.parent = Project.find(2)
104 sub.parent = Project.find(2)
105 assert !sub.save
105 assert !sub.save
106 end
106 end
107
108 def test_issues_status_changes
109 journals = @ecookbook.issues_status_changes 3.days.ago.to_date, Date.today
110 assert_equal 1, journals.size
111 assert_kind_of Journal, journals.first
112
113 journals = @ecookbook.issues_status_changes 30.days.ago.to_date, 10.days.ago.to_date
114 assert_equal 0, journals.size
115 end
107 end
116 end
General Comments 0
You need to be logged in to leave comments. Login now