##// END OF EJS Templates
Fixed: private subprojects names are revealed on the project overview (#1152)....
Jean-Philippe Lang -
r1384:2d11265ec5e1
parent child
Show More
@@ -1,433 +1,433
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 layout 'base'
20 20 menu_item :overview
21 21 menu_item :activity, :only => :activity
22 22 menu_item :roadmap, :only => :roadmap
23 23 menu_item :files, :only => [:list_files, :add_file]
24 24 menu_item :settings, :only => :settings
25 25 menu_item :issues, :only => [:changelog]
26 26
27 27 before_filter :find_project, :except => [ :index, :list, :add, :activity ]
28 28 before_filter :find_optional_project, :only => :activity
29 29 before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ]
30 30 before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
31 31 accept_key_auth :activity, :calendar
32 32
33 33 helper :sort
34 34 include SortHelper
35 35 helper :custom_fields
36 36 include CustomFieldsHelper
37 37 helper :ifpdf
38 38 include IfpdfHelper
39 39 helper :issues
40 40 helper IssuesHelper
41 41 helper :queries
42 42 include QueriesHelper
43 43 helper :repositories
44 44 include RepositoriesHelper
45 45 include ProjectsHelper
46 46
47 47 def index
48 48 list
49 49 render :action => 'list' unless request.xhr?
50 50 end
51 51
52 52 # Lists visible projects
53 53 def list
54 54 projects = Project.find :all,
55 55 :conditions => Project.visible_by(User.current),
56 56 :include => :parent
57 57 @project_tree = projects.group_by {|p| p.parent || p}
58 58 @project_tree.each_key {|p| @project_tree[p] -= [p]}
59 59 end
60 60
61 61 # Add a new project
62 62 def add
63 63 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
64 64 @trackers = Tracker.all
65 65 @root_projects = Project.find(:all,
66 66 :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
67 67 :order => 'name')
68 68 @project = Project.new(params[:project])
69 69 if request.get?
70 70 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
71 71 @project.trackers = Tracker.all
72 72 @project.is_public = Setting.default_projects_public?
73 73 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
74 74 else
75 75 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
76 76 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
77 77 @project.custom_values = @custom_values
78 78 @project.enabled_module_names = params[:enabled_modules]
79 79 if @project.save
80 80 flash[:notice] = l(:notice_successful_create)
81 81 redirect_to :controller => 'admin', :action => 'projects'
82 82 end
83 83 end
84 84 end
85 85
86 86 # Show @project
87 87 def show
88 88 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
89 89 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
90 @subprojects = @project.active_children
90 @subprojects = @project.children.find(:all, :conditions => Project.visible_by(User.current))
91 91 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
92 92 @trackers = @project.rolled_up_trackers
93 93
94 94 cond = @project.project_condition(Setting.display_subprojects_issues?)
95 95 Issue.visible_by(User.current) do
96 96 @open_issues_by_tracker = Issue.count(:group => :tracker,
97 97 :include => [:project, :status, :tracker],
98 98 :conditions => ["(#{cond}) AND #{IssueStatus.table_name}.is_closed=?", false])
99 99 @total_issues_by_tracker = Issue.count(:group => :tracker,
100 100 :include => [:project, :status, :tracker],
101 101 :conditions => cond)
102 102 end
103 103 TimeEntry.visible_by(User.current) do
104 104 @total_hours = TimeEntry.sum(:hours,
105 105 :include => :project,
106 106 :conditions => cond).to_f
107 107 end
108 108 @key = User.current.rss_key
109 109 end
110 110
111 111 def settings
112 112 @root_projects = Project.find(:all,
113 113 :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
114 114 :order => 'name')
115 115 @custom_fields = IssueCustomField.find(:all)
116 116 @issue_category ||= IssueCategory.new
117 117 @member ||= @project.members.new
118 118 @trackers = Tracker.all
119 119 @custom_values ||= ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
120 120 @repository ||= @project.repository
121 121 @wiki ||= @project.wiki
122 122 end
123 123
124 124 # Edit @project
125 125 def edit
126 126 if request.post?
127 127 if params[:custom_fields]
128 128 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
129 129 @project.custom_values = @custom_values
130 130 end
131 131 @project.attributes = params[:project]
132 132 if @project.save
133 133 flash[:notice] = l(:notice_successful_update)
134 134 redirect_to :action => 'settings', :id => @project
135 135 else
136 136 settings
137 137 render :action => 'settings'
138 138 end
139 139 end
140 140 end
141 141
142 142 def modules
143 143 @project.enabled_module_names = params[:enabled_modules]
144 144 redirect_to :action => 'settings', :id => @project, :tab => 'modules'
145 145 end
146 146
147 147 def archive
148 148 @project.archive if request.post? && @project.active?
149 149 redirect_to :controller => 'admin', :action => 'projects'
150 150 end
151 151
152 152 def unarchive
153 153 @project.unarchive if request.post? && !@project.active?
154 154 redirect_to :controller => 'admin', :action => 'projects'
155 155 end
156 156
157 157 # Delete @project
158 158 def destroy
159 159 @project_to_destroy = @project
160 160 if request.post? and params[:confirm]
161 161 @project_to_destroy.destroy
162 162 redirect_to :controller => 'admin', :action => 'projects'
163 163 end
164 164 # hide project in layout
165 165 @project = nil
166 166 end
167 167
168 168 # Add a new issue category to @project
169 169 def add_issue_category
170 170 @category = @project.issue_categories.build(params[:category])
171 171 if request.post? and @category.save
172 172 respond_to do |format|
173 173 format.html do
174 174 flash[:notice] = l(:notice_successful_create)
175 175 redirect_to :action => 'settings', :tab => 'categories', :id => @project
176 176 end
177 177 format.js do
178 178 # IE doesn't support the replace_html rjs method for select box options
179 179 render(:update) {|page| page.replace "issue_category_id",
180 180 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]')
181 181 }
182 182 end
183 183 end
184 184 end
185 185 end
186 186
187 187 # Add a new version to @project
188 188 def add_version
189 189 @version = @project.versions.build(params[:version])
190 190 if request.post? and @version.save
191 191 flash[:notice] = l(:notice_successful_create)
192 192 redirect_to :action => 'settings', :tab => 'versions', :id => @project
193 193 end
194 194 end
195 195
196 196 def add_file
197 197 if request.post?
198 198 @version = @project.versions.find_by_id(params[:version_id])
199 199 attachments = attach_files(@version, params[:attachments])
200 200 Mailer.deliver_attachments_added(attachments) if !attachments.empty? && Setting.notified_events.include?('file_added')
201 201 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
202 202 end
203 203 @versions = @project.versions.sort
204 204 end
205 205
206 206 def list_files
207 207 sort_init "#{Attachment.table_name}.filename", "asc"
208 208 sort_update
209 209 @versions = @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
210 210 render :layout => !request.xhr?
211 211 end
212 212
213 213 # Show changelog for @project
214 214 def changelog
215 215 @trackers = @project.trackers.find(:all, :conditions => ["is_in_chlog=?", true], :order => 'position')
216 216 retrieve_selected_tracker_ids(@trackers)
217 217 @versions = @project.versions.sort
218 218 end
219 219
220 220 def roadmap
221 221 @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true])
222 222 retrieve_selected_tracker_ids(@trackers)
223 223 @versions = @project.versions.sort
224 224 @versions = @versions.select {|v| !v.completed? } unless params[:completed]
225 225 end
226 226
227 227 def activity
228 228 @days = Setting.activity_days_default.to_i
229 229
230 230 if params[:from]
231 231 begin; @date_to = params[:from].to_date; rescue; end
232 232 end
233 233
234 234 @date_to ||= Date.today + 1
235 235 @date_from = @date_to - @days
236 236
237 237 @event_types = %w(issues news files documents changesets wiki_pages messages)
238 238 if @project
239 239 @event_types.delete('wiki_pages') unless @project.wiki
240 240 @event_types.delete('changesets') unless @project.repository
241 241 @event_types.delete('messages') unless @project.boards.any?
242 242 # only show what the user is allowed to view
243 243 @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
244 244 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
245 245 end
246 246 @scope = @event_types.select {|t| params["show_#{t}"]}
247 247 # default events if none is specified in parameters
248 248 @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
249 249
250 250 @events = []
251 251
252 252 if @scope.include?('issues')
253 253 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
254 254 cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
255 255 @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
256 256
257 257 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
258 258 cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
259 259 @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
260 260 end
261 261
262 262 if @scope.include?('news')
263 263 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
264 264 cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
265 265 @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
266 266 end
267 267
268 268 if @scope.include?('files')
269 269 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
270 270 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
271 271 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
272 272 :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
273 273 "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
274 274 :conditions => cond.conditions)
275 275 end
276 276
277 277 if @scope.include?('documents')
278 278 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
279 279 cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
280 280 @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
281 281
282 282 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
283 283 cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
284 284 @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
285 285 :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
286 286 "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
287 287 :conditions => cond.conditions)
288 288 end
289 289
290 290 if @scope.include?('wiki_pages')
291 291 select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
292 292 "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
293 293 "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
294 294 "#{WikiContent.versioned_table_name}.id"
295 295 joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
296 296 "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
297 297 "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
298 298
299 299 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
300 300 cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
301 301 @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
302 302 end
303 303
304 304 if @scope.include?('changesets')
305 305 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
306 306 cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
307 307 @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
308 308 end
309 309
310 310 if @scope.include?('messages')
311 311 cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
312 312 cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
313 313 @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
314 314 end
315 315
316 316 @events_by_day = @events.group_by(&:event_date)
317 317
318 318 respond_to do |format|
319 319 format.html { render :layout => false if request.xhr? }
320 320 format.atom { render_feed(@events, :title => "#{@project || Setting.app_title}: #{l(:label_activity)}") }
321 321 end
322 322 end
323 323
324 324 def calendar
325 325 @trackers = @project.rolled_up_trackers
326 326 retrieve_selected_tracker_ids(@trackers)
327 327
328 328 if params[:year] and params[:year].to_i > 1900
329 329 @year = params[:year].to_i
330 330 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
331 331 @month = params[:month].to_i
332 332 end
333 333 end
334 334 @year ||= Date.today.year
335 335 @month ||= Date.today.month
336 336 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
337 337 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
338 338 events = []
339 339 @project.issues_with_subprojects(@with_subprojects) do
340 340 events += Issue.find(:all,
341 341 :include => [:tracker, :status, :assigned_to, :priority, :project],
342 342 :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]
343 343 ) unless @selected_tracker_ids.empty?
344 344 events += Version.find(:all, :include => :project,
345 345 :conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
346 346 end
347 347 @calendar.events = events
348 348
349 349 render :layout => false if request.xhr?
350 350 end
351 351
352 352 def gantt
353 353 @trackers = @project.rolled_up_trackers
354 354 retrieve_selected_tracker_ids(@trackers)
355 355
356 356 if params[:year] and params[:year].to_i >0
357 357 @year_from = params[:year].to_i
358 358 if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
359 359 @month_from = params[:month].to_i
360 360 else
361 361 @month_from = 1
362 362 end
363 363 else
364 364 @month_from ||= Date.today.month
365 365 @year_from ||= Date.today.year
366 366 end
367 367
368 368 zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
369 369 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
370 370 months = (params[:months] || User.current.pref[:gantt_months]).to_i
371 371 @months = (months > 0 && months < 25) ? months : 6
372 372
373 373 # Save gantt paramters as user preference (zoom and months count)
374 374 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
375 375 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
376 376 User.current.preference.save
377 377 end
378 378
379 379 @date_from = Date.civil(@year_from, @month_from, 1)
380 380 @date_to = (@date_from >> @months) - 1
381 381 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
382 382
383 383 @events = []
384 384 @project.issues_with_subprojects(@with_subprojects) do
385 385 @events += Issue.find(:all,
386 386 :order => "start_date, due_date",
387 387 :include => [:tracker, :status, :assigned_to, :priority, :project],
388 388 :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]
389 389 ) unless @selected_tracker_ids.empty?
390 390 @events += Version.find(:all, :include => :project,
391 391 :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
392 392 end
393 393 @events.sort! {|x,y| x.start_date <=> y.start_date }
394 394
395 395 if params[:format]=='pdf'
396 396 @options_for_rfpdf ||= {}
397 397 @options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
398 398 render :template => "projects/gantt.rfpdf", :layout => false
399 399 elsif params[:format]=='png' && respond_to?('gantt_image')
400 400 image = gantt_image(@events, @date_from, @months, @zoom)
401 401 image.format = 'PNG'
402 402 send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
403 403 else
404 404 render :template => "projects/gantt.rhtml"
405 405 end
406 406 end
407 407
408 408 private
409 409 # Find project of id params[:id]
410 410 # if not found, redirect to project list
411 411 # Used as a before_filter
412 412 def find_project
413 413 @project = Project.find(params[:id])
414 414 rescue ActiveRecord::RecordNotFound
415 415 render_404
416 416 end
417 417
418 418 def find_optional_project
419 419 return true unless params[:id]
420 420 @project = Project.find(params[:id])
421 421 authorize
422 422 rescue ActiveRecord::RecordNotFound
423 423 render_404
424 424 end
425 425
426 426 def retrieve_selected_tracker_ids(selectable_trackers)
427 427 if ids = params[:tracker_ids]
428 428 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
429 429 else
430 430 @selected_tracker_ids = selectable_trackers.collect {|t| t.id.to_s }
431 431 end
432 432 end
433 433 end
@@ -1,27 +1,33
1 1 ---
2 2 members_001:
3 3 created_on: 2006-07-19 19:35:33 +02:00
4 4 project_id: 1
5 5 role_id: 1
6 6 id: 1
7 7 user_id: 2
8 8 members_002:
9 9 created_on: 2006-07-19 19:35:36 +02:00
10 10 project_id: 1
11 11 role_id: 2
12 12 id: 2
13 13 user_id: 3
14 14 members_003:
15 15 created_on: 2006-07-19 19:35:36 +02:00
16 16 project_id: 2
17 17 role_id: 2
18 18 id: 3
19 19 user_id: 2
20 20 members_004:
21 21 id: 4
22 22 created_on: 2006-07-19 19:35:36 +02:00
23 23 project_id: 1
24 24 role_id: 2
25 25 # Locked user
26 26 user_id: 5
27 members_005:
28 id: 5
29 created_on: 2006-07-19 19:35:33 +02:00
30 project_id: 5
31 role_id: 1
32 user_id: 2
27 33 No newline at end of file
@@ -1,45 +1,57
1 1 ---
2 2 projects_001:
3 3 created_on: 2006-07-19 19:13:59 +02:00
4 4 name: eCookbook
5 5 updated_on: 2006-07-19 22:53:01 +02:00
6 projects_count: 2
6 projects_count: 3
7 7 id: 1
8 8 description: Recipes management application
9 9 homepage: http://ecookbook.somenet.foo/
10 10 is_public: true
11 11 identifier: ecookbook
12 12 parent_id:
13 13 projects_002:
14 14 created_on: 2006-07-19 19:14:19 +02:00
15 15 name: OnlineStore
16 16 updated_on: 2006-07-19 19:14:19 +02:00
17 17 projects_count: 0
18 18 id: 2
19 19 description: E-commerce web site
20 20 homepage: ""
21 21 is_public: false
22 22 identifier: onlinestore
23 23 parent_id:
24 24 projects_003:
25 25 created_on: 2006-07-19 19:15:21 +02:00
26 26 name: eCookbook Subproject 1
27 27 updated_on: 2006-07-19 19:18:12 +02:00
28 28 projects_count: 0
29 29 id: 3
30 30 description: eCookBook Subproject 1
31 31 homepage: ""
32 32 is_public: true
33 33 identifier: subproject1
34 34 parent_id: 1
35 35 projects_004:
36 36 created_on: 2006-07-19 19:15:51 +02:00
37 37 name: eCookbook Subproject 2
38 38 updated_on: 2006-07-19 19:17:07 +02:00
39 39 projects_count: 0
40 40 id: 4
41 41 description: eCookbook Subproject 2
42 42 homepage: ""
43 43 is_public: true
44 44 identifier: subproject2
45 45 parent_id: 1
46 projects_005:
47 created_on: 2006-07-19 19:15:51 +02:00
48 name: Private child of eCookbook
49 updated_on: 2006-07-19 19:17:07 +02:00
50 projects_count: 0
51 id: 5
52 description: This is a private subproject of a public project
53 homepage: ""
54 is_public: false
55 identifier: private_child
56 parent_id: 1
57 No newline at end of file
@@ -1,268 +1,283
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'projects_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class ProjectsController; def rescue_action(e) raise e end; end
23 23
24 24 class ProjectsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
26 26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
27 27
28 28 def setup
29 29 @controller = ProjectsController.new
30 30 @request = ActionController::TestRequest.new
31 31 @response = ActionController::TestResponse.new
32 32 end
33 33
34 34 def test_index
35 35 get :index
36 36 assert_response :success
37 37 assert_template 'list'
38 38 end
39 39
40 40 def test_list
41 41 get :list
42 42 assert_response :success
43 43 assert_template 'list'
44 44 assert_not_nil assigns(:project_tree)
45 45 # Root project as hash key
46 46 assert assigns(:project_tree).has_key?(Project.find(1))
47 47 # Subproject in corresponding value
48 48 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
49 49 end
50 50
51 51 def test_show_by_id
52 52 get :show, :id => 1
53 53 assert_response :success
54 54 assert_template 'show'
55 55 assert_not_nil assigns(:project)
56 56 end
57 57
58 58 def test_show_by_identifier
59 59 get :show, :id => 'ecookbook'
60 60 assert_response :success
61 61 assert_template 'show'
62 62 assert_not_nil assigns(:project)
63 63 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
64 64 end
65 65
66 def test_private_subprojects_hidden
67 get :show, :id => 'ecookbook'
68 assert_response :success
69 assert_template 'show'
70 assert_no_tag :tag => 'a', :content => /Private child/
71 end
72
73 def test_private_subprojects_visible
74 @request.session[:user_id] = 2 # manager who is a member of the private subproject
75 get :show, :id => 'ecookbook'
76 assert_response :success
77 assert_template 'show'
78 assert_tag :tag => 'a', :content => /Private child/
79 end
80
66 81 def test_settings
67 82 @request.session[:user_id] = 2 # manager
68 83 get :settings, :id => 1
69 84 assert_response :success
70 85 assert_template 'settings'
71 86 end
72 87
73 88 def test_edit
74 89 @request.session[:user_id] = 2 # manager
75 90 post :edit, :id => 1, :project => {:name => 'Test changed name',
76 91 :custom_field_ids => ['']}
77 92 assert_redirected_to 'projects/settings/ecookbook'
78 93 project = Project.find(1)
79 94 assert_equal 'Test changed name', project.name
80 95 end
81 96
82 97 def test_get_destroy
83 98 @request.session[:user_id] = 1 # admin
84 99 get :destroy, :id => 1
85 100 assert_response :success
86 101 assert_template 'destroy'
87 102 assert_not_nil Project.find_by_id(1)
88 103 end
89 104
90 105 def test_post_destroy
91 106 @request.session[:user_id] = 1 # admin
92 107 post :destroy, :id => 1, :confirm => 1
93 108 assert_redirected_to 'admin/projects'
94 109 assert_nil Project.find_by_id(1)
95 110 end
96 111
97 112 def test_list_files
98 113 get :list_files, :id => 1
99 114 assert_response :success
100 115 assert_template 'list_files'
101 116 assert_not_nil assigns(:versions)
102 117 end
103 118
104 119 def test_changelog
105 120 get :changelog, :id => 1
106 121 assert_response :success
107 122 assert_template 'changelog'
108 123 assert_not_nil assigns(:versions)
109 124 end
110 125
111 126 def test_roadmap
112 127 get :roadmap, :id => 1
113 128 assert_response :success
114 129 assert_template 'roadmap'
115 130 assert_not_nil assigns(:versions)
116 131 # Version with no date set appears
117 132 assert assigns(:versions).include?(Version.find(3))
118 133 # Completed version doesn't appear
119 134 assert !assigns(:versions).include?(Version.find(1))
120 135 end
121 136
122 137 def test_roadmap_with_completed_versions
123 138 get :roadmap, :id => 1, :completed => 1
124 139 assert_response :success
125 140 assert_template 'roadmap'
126 141 assert_not_nil assigns(:versions)
127 142 # Version with no date set appears
128 143 assert assigns(:versions).include?(Version.find(3))
129 144 # Completed version appears
130 145 assert assigns(:versions).include?(Version.find(1))
131 146 end
132 147
133 148 def test_project_activity
134 149 get :activity, :id => 1, :with_subprojects => 0
135 150 assert_response :success
136 151 assert_template 'activity'
137 152 assert_not_nil assigns(:events_by_day)
138 153 assert_not_nil assigns(:events)
139 154
140 155 # subproject issue not included by default
141 156 assert !assigns(:events).include?(Issue.find(5))
142 157
143 158 assert_tag :tag => "h3",
144 159 :content => /#{2.days.ago.to_date.day}/,
145 160 :sibling => { :tag => "dl",
146 161 :child => { :tag => "dt",
147 162 :attributes => { :class => 'issue-edit' },
148 163 :child => { :tag => "a",
149 164 :content => /(#{IssueStatus.find(2).name})/,
150 165 }
151 166 }
152 167 }
153 168
154 169 get :activity, :id => 1, :from => 3.days.ago.to_date
155 170 assert_response :success
156 171 assert_template 'activity'
157 172 assert_not_nil assigns(:events_by_day)
158 173
159 174 assert_tag :tag => "h3",
160 175 :content => /#{3.day.ago.to_date.day}/,
161 176 :sibling => { :tag => "dl",
162 177 :child => { :tag => "dt",
163 178 :attributes => { :class => 'issue' },
164 179 :child => { :tag => "a",
165 180 :content => /#{Issue.find(1).subject}/,
166 181 }
167 182 }
168 183 }
169 184 end
170 185
171 186 def test_activity_with_subprojects
172 187 get :activity, :id => 1, :with_subprojects => 1
173 188 assert_response :success
174 189 assert_template 'activity'
175 190 assert_not_nil assigns(:events)
176 191
177 192 assert assigns(:events).include?(Issue.find(1))
178 193 assert !assigns(:events).include?(Issue.find(4))
179 194 # subproject issue
180 195 assert assigns(:events).include?(Issue.find(5))
181 196 end
182 197
183 198 def test_global_activity_anonymous
184 199 get :activity
185 200 assert_response :success
186 201 assert_template 'activity'
187 202 assert_not_nil assigns(:events)
188 203
189 204 assert assigns(:events).include?(Issue.find(1))
190 205 # Issue of a private project
191 206 assert !assigns(:events).include?(Issue.find(4))
192 207 end
193 208
194 209 def test_global_activity_logged_user
195 210 @request.session[:user_id] = 2 # manager
196 211 get :activity
197 212 assert_response :success
198 213 assert_template 'activity'
199 214 assert_not_nil assigns(:events)
200 215
201 216 assert assigns(:events).include?(Issue.find(1))
202 217 # Issue of a private project the user belongs to
203 218 assert assigns(:events).include?(Issue.find(4))
204 219 end
205 220
206 221
207 222 def test_global_activity_with_all_types
208 223 get :activity, :show_issues => 1, :show_news => 1, :show_files => 1, :show_documents => 1, :show_changesets => 1, :show_wiki_pages => 1, :show_messages => 1
209 224 assert_response :success
210 225 assert_template 'activity'
211 226 assert_not_nil assigns(:events)
212 227
213 228 assert assigns(:events).include?(Issue.find(1))
214 229 assert !assigns(:events).include?(Issue.find(4))
215 230 assert assigns(:events).include?(Message.find(5))
216 231 end
217 232
218 233 def test_calendar
219 234 get :calendar, :id => 1
220 235 assert_response :success
221 236 assert_template 'calendar'
222 237 assert_not_nil assigns(:calendar)
223 238 end
224 239
225 240 def test_calendar_with_subprojects
226 241 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
227 242 assert_response :success
228 243 assert_template 'calendar'
229 244 assert_not_nil assigns(:calendar)
230 245 end
231 246
232 247 def test_gantt
233 248 get :gantt, :id => 1
234 249 assert_response :success
235 250 assert_template 'gantt.rhtml'
236 251 assert_not_nil assigns(:events)
237 252 end
238 253
239 254 def test_gantt_with_subprojects
240 255 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
241 256 assert_response :success
242 257 assert_template 'gantt.rhtml'
243 258 assert_not_nil assigns(:events)
244 259 end
245 260
246 261 def test_gantt_export_to_pdf
247 262 get :gantt, :id => 1, :format => 'pdf'
248 263 assert_response :success
249 264 assert_template 'gantt.rfpdf'
250 265 assert_equal 'application/pdf', @response.content_type
251 266 assert_not_nil assigns(:events)
252 267 end
253 268
254 269 def test_archive
255 270 @request.session[:user_id] = 1 # admin
256 271 post :archive, :id => 1
257 272 assert_redirected_to 'admin/projects'
258 273 assert !Project.find(1).active?
259 274 end
260 275
261 276 def test_unarchive
262 277 @request.session[:user_id] = 1 # admin
263 278 Project.find(1).archive
264 279 post :unarchive, :id => 1
265 280 assert_redirected_to 'admin/projects'
266 281 assert Project.find(1).active?
267 282 end
268 283 end
@@ -1,132 +1,132
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class ProjectTest < Test::Unit::TestCase
21 21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards
22 22
23 23 def setup
24 24 @ecookbook = Project.find(1)
25 25 @ecookbook_sub1 = Project.find(3)
26 26 end
27 27
28 28 def test_truth
29 29 assert_kind_of Project, @ecookbook
30 30 assert_equal "eCookbook", @ecookbook.name
31 31 end
32 32
33 33 def test_update
34 34 assert_equal "eCookbook", @ecookbook.name
35 35 @ecookbook.name = "eCook"
36 36 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
37 37 @ecookbook.reload
38 38 assert_equal "eCook", @ecookbook.name
39 39 end
40 40
41 41 def test_validate
42 42 @ecookbook.name = ""
43 43 assert !@ecookbook.save
44 44 assert_equal 1, @ecookbook.errors.count
45 45 assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
46 46 end
47 47
48 48 def test_public_projects
49 49 public_projects = Project.find(:all, :conditions => ["is_public=?", true])
50 50 assert_equal 3, public_projects.length
51 51 assert_equal true, public_projects[0].is_public?
52 52 end
53 53
54 54 def test_archive
55 55 user = @ecookbook.members.first.user
56 56 @ecookbook.archive
57 57 @ecookbook.reload
58 58
59 59 assert !@ecookbook.active?
60 60 assert !user.projects.include?(@ecookbook)
61 61 # Subproject are also archived
62 62 assert !@ecookbook.children.empty?
63 63 assert @ecookbook.active_children.empty?
64 64 end
65 65
66 66 def test_unarchive
67 67 user = @ecookbook.members.first.user
68 68 @ecookbook.archive
69 69 # A subproject of an archived project can not be unarchived
70 70 assert !@ecookbook_sub1.unarchive
71 71
72 72 # Unarchive project
73 73 assert @ecookbook.unarchive
74 74 @ecookbook.reload
75 75 assert @ecookbook.active?
76 76 assert user.projects.include?(@ecookbook)
77 77 # Subproject can now be unarchived
78 78 @ecookbook_sub1.reload
79 79 assert @ecookbook_sub1.unarchive
80 80 end
81 81
82 82 def test_destroy
83 83 # 2 active members
84 84 assert_equal 2, @ecookbook.members.size
85 85 # and 1 is locked
86 86 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
87 87 # some boards
88 88 assert @ecookbook.boards.any?
89 89
90 90 @ecookbook.destroy
91 91 # make sure that the project non longer exists
92 92 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
93 93 # make sure related data was removed
94 94 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
95 95 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
96 96 end
97 97
98 98 def test_subproject_ok
99 99 sub = Project.find(2)
100 100 sub.parent = @ecookbook
101 101 assert sub.save
102 102 assert_equal @ecookbook.id, sub.parent.id
103 103 @ecookbook.reload
104 assert_equal 3, @ecookbook.children.size
104 assert_equal 4, @ecookbook.children.size
105 105 end
106 106
107 107 def test_subproject_invalid
108 108 sub = Project.find(2)
109 109 sub.parent = @ecookbook_sub1
110 110 assert !sub.save
111 111 end
112 112
113 113 def test_subproject_invalid_2
114 114 sub = @ecookbook
115 115 sub.parent = Project.find(2)
116 116 assert !sub.save
117 117 end
118 118
119 119 def test_rolled_up_trackers
120 120 parent = Project.find(1)
121 121 child = parent.children.find(3)
122 122
123 123 assert_equal [1, 2], parent.tracker_ids
124 124 assert_equal [2, 3], child.tracker_ids
125 125
126 126 assert_kind_of Tracker, parent.rolled_up_trackers.first
127 127 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
128 128
129 129 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
130 130 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
131 131 end
132 132 end
General Comments 0
You need to be logged in to leave comments. Login now