##// END OF EJS Templates
Fixed: roadmap show subprojects issues even if subprojects is unchecked (#4761)....
Jean-Philippe Lang -
r3294:1fec53cc25ec
parent child
Show More
@@ -1,446 +1,442
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 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 menu_item :overview
19 menu_item :overview
20 menu_item :activity, :only => :activity
20 menu_item :activity, :only => :activity
21 menu_item :roadmap, :only => :roadmap
21 menu_item :roadmap, :only => :roadmap
22 menu_item :files, :only => [:list_files, :add_file]
22 menu_item :files, :only => [:list_files, :add_file]
23 menu_item :settings, :only => :settings
23 menu_item :settings, :only => :settings
24
24
25 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
25 before_filter :find_project, :except => [ :index, :list, :add, :copy, :activity ]
26 before_filter :find_optional_project, :only => :activity
26 before_filter :find_optional_project, :only => :activity
27 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
27 before_filter :authorize, :except => [ :index, :list, :add, :copy, :archive, :unarchive, :destroy, :activity ]
28 before_filter :authorize_global, :only => :add
28 before_filter :authorize_global, :only => :add
29 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
29 before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy ]
30 accept_key_auth :activity
30 accept_key_auth :activity
31
31
32 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
32 after_filter :only => [:add, :edit, :archive, :unarchive, :destroy] do |controller|
33 if controller.request.post?
33 if controller.request.post?
34 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
34 controller.send :expire_action, :controller => 'welcome', :action => 'robots.txt'
35 end
35 end
36 end
36 end
37
37
38 helper :sort
38 helper :sort
39 include SortHelper
39 include SortHelper
40 helper :custom_fields
40 helper :custom_fields
41 include CustomFieldsHelper
41 include CustomFieldsHelper
42 helper :issues
42 helper :issues
43 helper IssuesHelper
43 helper IssuesHelper
44 helper :queries
44 helper :queries
45 include QueriesHelper
45 include QueriesHelper
46 helper :repositories
46 helper :repositories
47 include RepositoriesHelper
47 include RepositoriesHelper
48 include ProjectsHelper
48 include ProjectsHelper
49
49
50 # Lists visible projects
50 # Lists visible projects
51 def index
51 def index
52 respond_to do |format|
52 respond_to do |format|
53 format.html {
53 format.html {
54 @projects = Project.visible.find(:all, :order => 'lft')
54 @projects = Project.visible.find(:all, :order => 'lft')
55 }
55 }
56 format.xml {
56 format.xml {
57 @projects = Project.visible.find(:all, :order => 'lft')
57 @projects = Project.visible.find(:all, :order => 'lft')
58 }
58 }
59 format.atom {
59 format.atom {
60 projects = Project.visible.find(:all, :order => 'created_on DESC',
60 projects = Project.visible.find(:all, :order => 'created_on DESC',
61 :limit => Setting.feeds_limit.to_i)
61 :limit => Setting.feeds_limit.to_i)
62 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
62 render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}")
63 }
63 }
64 end
64 end
65 end
65 end
66
66
67 # Add a new project
67 # Add a new project
68 def add
68 def add
69 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
69 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
70 @trackers = Tracker.all
70 @trackers = Tracker.all
71 @project = Project.new(params[:project])
71 @project = Project.new(params[:project])
72 if request.get?
72 if request.get?
73 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
73 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
74 @project.trackers = Tracker.all
74 @project.trackers = Tracker.all
75 @project.is_public = Setting.default_projects_public?
75 @project.is_public = Setting.default_projects_public?
76 @project.enabled_module_names = Setting.default_projects_modules
76 @project.enabled_module_names = Setting.default_projects_modules
77 else
77 else
78 @project.enabled_module_names = params[:enabled_modules]
78 @project.enabled_module_names = params[:enabled_modules]
79 if validate_parent_id && @project.save
79 if validate_parent_id && @project.save
80 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
80 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
81 # Add current user as a project member if he is not admin
81 # Add current user as a project member if he is not admin
82 unless User.current.admin?
82 unless User.current.admin?
83 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
83 r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
84 m = Member.new(:user => User.current, :roles => [r])
84 m = Member.new(:user => User.current, :roles => [r])
85 @project.members << m
85 @project.members << m
86 end
86 end
87 respond_to do |format|
87 respond_to do |format|
88 format.html {
88 format.html {
89 flash[:notice] = l(:notice_successful_create)
89 flash[:notice] = l(:notice_successful_create)
90 redirect_to :controller => 'projects', :action => 'settings', :id => @project
90 redirect_to :controller => 'projects', :action => 'settings', :id => @project
91 }
91 }
92 format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
92 format.xml { head :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
93 end
93 end
94 else
94 else
95 respond_to do |format|
95 respond_to do |format|
96 format.html
96 format.html
97 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
97 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
98 end
98 end
99 end
99 end
100 end
100 end
101 end
101 end
102
102
103 def copy
103 def copy
104 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
104 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
105 @trackers = Tracker.all
105 @trackers = Tracker.all
106 @root_projects = Project.find(:all,
106 @root_projects = Project.find(:all,
107 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
107 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
108 :order => 'name')
108 :order => 'name')
109 @source_project = Project.find(params[:id])
109 @source_project = Project.find(params[:id])
110 if request.get?
110 if request.get?
111 @project = Project.copy_from(@source_project)
111 @project = Project.copy_from(@source_project)
112 if @project
112 if @project
113 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
113 @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
114 else
114 else
115 redirect_to :controller => 'admin', :action => 'projects'
115 redirect_to :controller => 'admin', :action => 'projects'
116 end
116 end
117 else
117 else
118 @project = Project.new(params[:project])
118 @project = Project.new(params[:project])
119 @project.enabled_module_names = params[:enabled_modules]
119 @project.enabled_module_names = params[:enabled_modules]
120 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
120 if validate_parent_id && @project.copy(@source_project, :only => params[:only])
121 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
121 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
122 flash[:notice] = l(:notice_successful_create)
122 flash[:notice] = l(:notice_successful_create)
123 redirect_to :controller => 'admin', :action => 'projects'
123 redirect_to :controller => 'admin', :action => 'projects'
124 elsif !@project.new_record?
124 elsif !@project.new_record?
125 # Project was created
125 # Project was created
126 # But some objects were not copied due to validation failures
126 # But some objects were not copied due to validation failures
127 # (eg. issues from disabled trackers)
127 # (eg. issues from disabled trackers)
128 # TODO: inform about that
128 # TODO: inform about that
129 redirect_to :controller => 'admin', :action => 'projects'
129 redirect_to :controller => 'admin', :action => 'projects'
130 end
130 end
131 end
131 end
132 rescue ActiveRecord::RecordNotFound
132 rescue ActiveRecord::RecordNotFound
133 redirect_to :controller => 'admin', :action => 'projects'
133 redirect_to :controller => 'admin', :action => 'projects'
134 end
134 end
135
135
136 # Show @project
136 # Show @project
137 def show
137 def show
138 if params[:jump]
138 if params[:jump]
139 # try to redirect to the requested menu item
139 # try to redirect to the requested menu item
140 redirect_to_project_menu_item(@project, params[:jump]) && return
140 redirect_to_project_menu_item(@project, params[:jump]) && return
141 end
141 end
142
142
143 @users_by_role = @project.users_by_role
143 @users_by_role = @project.users_by_role
144 @subprojects = @project.children.visible
144 @subprojects = @project.children.visible
145 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
145 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
146 @trackers = @project.rolled_up_trackers
146 @trackers = @project.rolled_up_trackers
147
147
148 cond = @project.project_condition(Setting.display_subprojects_issues?)
148 cond = @project.project_condition(Setting.display_subprojects_issues?)
149
149
150 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
150 @open_issues_by_tracker = Issue.visible.count(:group => :tracker,
151 :include => [:project, :status, :tracker],
151 :include => [:project, :status, :tracker],
152 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
152 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
153 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
153 @total_issues_by_tracker = Issue.visible.count(:group => :tracker,
154 :include => [:project, :status, :tracker],
154 :include => [:project, :status, :tracker],
155 :conditions => cond)
155 :conditions => cond)
156
156
157 TimeEntry.visible_by(User.current) do
157 TimeEntry.visible_by(User.current) do
158 @total_hours = TimeEntry.sum(:hours,
158 @total_hours = TimeEntry.sum(:hours,
159 :include => :project,
159 :include => :project,
160 :conditions => cond).to_f
160 :conditions => cond).to_f
161 end
161 end
162 @key = User.current.rss_key
162 @key = User.current.rss_key
163
163
164 respond_to do |format|
164 respond_to do |format|
165 format.html
165 format.html
166 format.xml
166 format.xml
167 end
167 end
168 end
168 end
169
169
170 def settings
170 def settings
171 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
171 @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
172 @issue_category ||= IssueCategory.new
172 @issue_category ||= IssueCategory.new
173 @member ||= @project.members.new
173 @member ||= @project.members.new
174 @trackers = Tracker.all
174 @trackers = Tracker.all
175 @repository ||= @project.repository
175 @repository ||= @project.repository
176 @wiki ||= @project.wiki
176 @wiki ||= @project.wiki
177 end
177 end
178
178
179 # Edit @project
179 # Edit @project
180 def edit
180 def edit
181 if request.get?
181 if request.get?
182 else
182 else
183 @project.attributes = params[:project]
183 @project.attributes = params[:project]
184 if validate_parent_id && @project.save
184 if validate_parent_id && @project.save
185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
185 @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
186 respond_to do |format|
186 respond_to do |format|
187 format.html {
187 format.html {
188 flash[:notice] = l(:notice_successful_update)
188 flash[:notice] = l(:notice_successful_update)
189 redirect_to :action => 'settings', :id => @project
189 redirect_to :action => 'settings', :id => @project
190 }
190 }
191 format.xml { head :ok }
191 format.xml { head :ok }
192 end
192 end
193 else
193 else
194 respond_to do |format|
194 respond_to do |format|
195 format.html {
195 format.html {
196 settings
196 settings
197 render :action => 'settings'
197 render :action => 'settings'
198 }
198 }
199 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
199 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
200 end
200 end
201 end
201 end
202 end
202 end
203 end
203 end
204
204
205 def modules
205 def modules
206 @project.enabled_module_names = params[:enabled_modules]
206 @project.enabled_module_names = params[:enabled_modules]
207 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
207 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
208 end
208 end
209
209
210 def archive
210 def archive
211 if request.post?
211 if request.post?
212 unless @project.archive
212 unless @project.archive
213 flash[:error] = l(:error_can_not_archive_project)
213 flash[:error] = l(:error_can_not_archive_project)
214 end
214 end
215 end
215 end
216 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
216 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
217 end
217 end
218
218
219 def unarchive
219 def unarchive
220 @project.unarchive if request.post? && !@project.active?
220 @project.unarchive if request.post? && !@project.active?
221 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
221 redirect_to(url_for(:controller => 'admin', :action => 'projects', :status => params[:status]))
222 end
222 end
223
223
224 # Delete @project
224 # Delete @project
225 def destroy
225 def destroy
226 @project_to_destroy = @project
226 @project_to_destroy = @project
227 if request.get?
227 if request.get?
228 # display confirmation view
228 # display confirmation view
229 else
229 else
230 if params[:format] == 'xml' || params[:confirm]
230 if params[:format] == 'xml' || params[:confirm]
231 @project_to_destroy.destroy
231 @project_to_destroy.destroy
232 respond_to do |format|
232 respond_to do |format|
233 format.html { redirect_to :controller => 'admin', :action => 'projects' }
233 format.html { redirect_to :controller => 'admin', :action => 'projects' }
234 format.xml { head :ok }
234 format.xml { head :ok }
235 end
235 end
236 end
236 end
237 end
237 end
238 # hide project in layout
238 # hide project in layout
239 @project = nil
239 @project = nil
240 end
240 end
241
241
242 # Add a new issue category to @project
242 # Add a new issue category to @project
243 def add_issue_category
243 def add_issue_category
244 @category = @project.issue_categories.build(params[:category])
244 @category = @project.issue_categories.build(params[:category])
245 if request.post?
245 if request.post?
246 if @category.save
246 if @category.save
247 respond_to do |format|
247 respond_to do |format|
248 format.html do
248 format.html do
249 flash[:notice] = l(:notice_successful_create)
249 flash[:notice] = l(:notice_successful_create)
250 redirect_to :action => 'settings', :tab => 'categories', :id => @project
250 redirect_to :action => 'settings', :tab => 'categories', :id => @project
251 end
251 end
252 format.js do
252 format.js do
253 # IE doesn't support the replace_html rjs method for select box options
253 # IE doesn't support the replace_html rjs method for select box options
254 render(:update) {|page| page.replace "issue_category_id",
254 render(:update) {|page| page.replace "issue_category_id",
255 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]')
255 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]')
256 }
256 }
257 end
257 end
258 end
258 end
259 else
259 else
260 respond_to do |format|
260 respond_to do |format|
261 format.html
261 format.html
262 format.js do
262 format.js do
263 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
263 render(:update) {|page| page.alert(@category.errors.full_messages.join('\n')) }
264 end
264 end
265 end
265 end
266 end
266 end
267 end
267 end
268 end
268 end
269
269
270 # Add a new version to @project
270 # Add a new version to @project
271 def add_version
271 def add_version
272 @version = @project.versions.build
272 @version = @project.versions.build
273 if params[:version]
273 if params[:version]
274 attributes = params[:version].dup
274 attributes = params[:version].dup
275 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
275 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
276 @version.attributes = attributes
276 @version.attributes = attributes
277 end
277 end
278 if request.post?
278 if request.post?
279 if @version.save
279 if @version.save
280 respond_to do |format|
280 respond_to do |format|
281 format.html do
281 format.html do
282 flash[:notice] = l(:notice_successful_create)
282 flash[:notice] = l(:notice_successful_create)
283 redirect_to :action => 'settings', :tab => 'versions', :id => @project
283 redirect_to :action => 'settings', :tab => 'versions', :id => @project
284 end
284 end
285 format.js do
285 format.js do
286 # IE doesn't support the replace_html rjs method for select box options
286 # IE doesn't support the replace_html rjs method for select box options
287 render(:update) {|page| page.replace "issue_fixed_version_id",
287 render(:update) {|page| page.replace "issue_fixed_version_id",
288 content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
288 content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
289 }
289 }
290 end
290 end
291 end
291 end
292 else
292 else
293 respond_to do |format|
293 respond_to do |format|
294 format.html
294 format.html
295 format.js do
295 format.js do
296 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
296 render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
297 end
297 end
298 end
298 end
299 end
299 end
300 end
300 end
301 end
301 end
302
302
303 def add_file
303 def add_file
304 if request.post?
304 if request.post?
305 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
305 container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
306 attachments = attach_files(container, params[:attachments])
306 attachments = attach_files(container, params[:attachments])
307 if !attachments.empty? && Setting.notified_events.include?('file_added')
307 if !attachments.empty? && Setting.notified_events.include?('file_added')
308 Mailer.deliver_attachments_added(attachments)
308 Mailer.deliver_attachments_added(attachments)
309 end
309 end
310 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
310 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
311 return
311 return
312 end
312 end
313 @versions = @project.versions.sort
313 @versions = @project.versions.sort
314 end
314 end
315
315
316 def save_activities
316 def save_activities
317 if request.post? && params[:enumerations]
317 if request.post? && params[:enumerations]
318 Project.transaction do
318 Project.transaction do
319 params[:enumerations].each do |id, activity|
319 params[:enumerations].each do |id, activity|
320 @project.update_or_create_time_entry_activity(id, activity)
320 @project.update_or_create_time_entry_activity(id, activity)
321 end
321 end
322 end
322 end
323 end
323 end
324
324
325 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
325 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
326 end
326 end
327
327
328 def reset_activities
328 def reset_activities
329 @project.time_entry_activities.each do |time_entry_activity|
329 @project.time_entry_activities.each do |time_entry_activity|
330 time_entry_activity.destroy(time_entry_activity.parent)
330 time_entry_activity.destroy(time_entry_activity.parent)
331 end
331 end
332 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
332 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
333 end
333 end
334
334
335 def list_files
335 def list_files
336 sort_init 'filename', 'asc'
336 sort_init 'filename', 'asc'
337 sort_update 'filename' => "#{Attachment.table_name}.filename",
337 sort_update 'filename' => "#{Attachment.table_name}.filename",
338 'created_on' => "#{Attachment.table_name}.created_on",
338 'created_on' => "#{Attachment.table_name}.created_on",
339 'size' => "#{Attachment.table_name}.filesize",
339 'size' => "#{Attachment.table_name}.filesize",
340 'downloads' => "#{Attachment.table_name}.downloads"
340 'downloads' => "#{Attachment.table_name}.downloads"
341
341
342 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
342 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
343 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
343 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
344 render :layout => !request.xhr?
344 render :layout => !request.xhr?
345 end
345 end
346
346
347 def roadmap
347 def roadmap
348 @trackers = @project.trackers.find(:all, :order => 'position')
348 @trackers = @project.trackers.find(:all, :order => 'position')
349 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
349 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
350 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
350 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
351 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
351 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
352
352
353 @versions = @project.shared_versions.sort
353 @versions = @project.shared_versions.sort
354 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
354 @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed]
355
355
356 @issues_by_version = {}
356 @issues_by_version = {}
357 unless @selected_tracker_ids.empty?
357 unless @selected_tracker_ids.empty?
358 @versions.each do |version|
358 @versions.each do |version|
359 conditions = {:tracker_id => @selected_tracker_ids}
360 if !@project.versions.include?(version)
361 conditions.merge!(:project_id => project_ids)
362 end
363 issues = version.fixed_issues.visible.find(:all,
359 issues = version.fixed_issues.visible.find(:all,
364 :include => [:project, :status, :tracker, :priority],
360 :include => [:project, :status, :tracker, :priority],
365 :conditions => conditions,
361 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids},
366 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
362 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
367 @issues_by_version[version] = issues
363 @issues_by_version[version] = issues
368 end
364 end
369 end
365 end
370 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].empty?}
366 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].empty?}
371 end
367 end
372
368
373 def activity
369 def activity
374 @days = Setting.activity_days_default.to_i
370 @days = Setting.activity_days_default.to_i
375
371
376 if params[:from]
372 if params[:from]
377 begin; @date_to = params[:from].to_date + 1; rescue; end
373 begin; @date_to = params[:from].to_date + 1; rescue; end
378 end
374 end
379
375
380 @date_to ||= Date.today + 1
376 @date_to ||= Date.today + 1
381 @date_from = @date_to - @days
377 @date_from = @date_to - @days
382 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
378 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
383 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
379 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
384
380
385 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
381 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
386 :with_subprojects => @with_subprojects,
382 :with_subprojects => @with_subprojects,
387 :author => @author)
383 :author => @author)
388 @activity.scope_select {|t| !params["show_#{t}"].nil?}
384 @activity.scope_select {|t| !params["show_#{t}"].nil?}
389 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
385 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
390
386
391 events = @activity.events(@date_from, @date_to)
387 events = @activity.events(@date_from, @date_to)
392
388
393 if events.empty? || stale?(:etag => [events.first, User.current])
389 if events.empty? || stale?(:etag => [events.first, User.current])
394 respond_to do |format|
390 respond_to do |format|
395 format.html {
391 format.html {
396 @events_by_day = events.group_by(&:event_date)
392 @events_by_day = events.group_by(&:event_date)
397 render :layout => false if request.xhr?
393 render :layout => false if request.xhr?
398 }
394 }
399 format.atom {
395 format.atom {
400 title = l(:label_activity)
396 title = l(:label_activity)
401 if @author
397 if @author
402 title = @author.name
398 title = @author.name
403 elsif @activity.scope.size == 1
399 elsif @activity.scope.size == 1
404 title = l("label_#{@activity.scope.first.singularize}_plural")
400 title = l("label_#{@activity.scope.first.singularize}_plural")
405 end
401 end
406 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
402 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
407 }
403 }
408 end
404 end
409 end
405 end
410
406
411 rescue ActiveRecord::RecordNotFound
407 rescue ActiveRecord::RecordNotFound
412 render_404
408 render_404
413 end
409 end
414
410
415 private
411 private
416 def find_optional_project
412 def find_optional_project
417 return true unless params[:id]
413 return true unless params[:id]
418 @project = Project.find(params[:id])
414 @project = Project.find(params[:id])
419 authorize
415 authorize
420 rescue ActiveRecord::RecordNotFound
416 rescue ActiveRecord::RecordNotFound
421 render_404
417 render_404
422 end
418 end
423
419
424 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
420 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
425 if ids = params[:tracker_ids]
421 if ids = params[:tracker_ids]
426 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
422 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
427 else
423 else
428 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
424 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
429 end
425 end
430 end
426 end
431
427
432 # Validates parent_id param according to user's permissions
428 # Validates parent_id param according to user's permissions
433 # TODO: move it to Project model in a validation that depends on User.current
429 # TODO: move it to Project model in a validation that depends on User.current
434 def validate_parent_id
430 def validate_parent_id
435 return true if User.current.admin?
431 return true if User.current.admin?
436 parent_id = params[:project] && params[:project][:parent_id]
432 parent_id = params[:project] && params[:project][:parent_id]
437 if parent_id || @project.new_record?
433 if parent_id || @project.new_record?
438 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
434 parent = parent_id.blank? ? nil : Project.find_by_id(parent_id.to_i)
439 unless @project.allowed_parents.include?(parent)
435 unless @project.allowed_parents.include?(parent)
440 @project.errors.add :parent_id, :invalid
436 @project.errors.add :parent_id, :invalid
441 return false
437 return false
442 end
438 end
443 end
439 end
444 true
440 true
445 end
441 end
446 end
442 end
General Comments 0
You need to be logged in to leave comments. Login now