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