@@ -249,7 +249,7 class Project < ActiveRecord::Base | |||
|
249 | 249 | return @allowed_parents if @allowed_parents |
|
250 | 250 | @allowed_parents = Project.find(:all, :conditions => Project.allowed_to_condition(User.current, :add_subprojects)) |
|
251 | 251 | @allowed_parents = @allowed_parents - self_and_descendants |
|
252 | if User.current.allowed_to?(:add_project, nil, :global => true) | |
|
252 | if User.current.allowed_to?(:add_project, nil, :global => true) || (!new_record? && parent.nil?) | |
|
253 | 253 | @allowed_parents << nil |
|
254 | 254 | end |
|
255 | 255 | unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent) |
@@ -285,6 +285,48 class ProjectTest < ActiveSupport::TestCase | |||
|
285 | 285 | assert Project.new.allowed_parents.compact.empty? |
|
286 | 286 | end |
|
287 | 287 | |
|
288 | def test_allowed_parents_with_add_subprojects_permission | |
|
289 | Role.find(1).remove_permission!(:add_project) | |
|
290 | Role.find(1).add_permission!(:add_subprojects) | |
|
291 | User.current = User.find(2) | |
|
292 | # new project | |
|
293 | assert !Project.new.allowed_parents.include?(nil) | |
|
294 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
|
295 | # existing root project | |
|
296 | assert Project.find(1).allowed_parents.include?(nil) | |
|
297 | # existing child | |
|
298 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
|
299 | assert !Project.find(3).allowed_parents.include?(nil) | |
|
300 | end | |
|
301 | ||
|
302 | def test_allowed_parents_with_add_project_permission | |
|
303 | Role.find(1).add_permission!(:add_project) | |
|
304 | Role.find(1).remove_permission!(:add_subprojects) | |
|
305 | User.current = User.find(2) | |
|
306 | # new project | |
|
307 | assert Project.new.allowed_parents.include?(nil) | |
|
308 | assert !Project.new.allowed_parents.include?(Project.find(1)) | |
|
309 | # existing root project | |
|
310 | assert Project.find(1).allowed_parents.include?(nil) | |
|
311 | # existing child | |
|
312 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
|
313 | assert Project.find(3).allowed_parents.include?(nil) | |
|
314 | end | |
|
315 | ||
|
316 | def test_allowed_parents_with_add_project_and_subprojects_permission | |
|
317 | Role.find(1).add_permission!(:add_project) | |
|
318 | Role.find(1).add_permission!(:add_subprojects) | |
|
319 | User.current = User.find(2) | |
|
320 | # new project | |
|
321 | assert Project.new.allowed_parents.include?(nil) | |
|
322 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
|
323 | # existing root project | |
|
324 | assert Project.find(1).allowed_parents.include?(nil) | |
|
325 | # existing child | |
|
326 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
|
327 | assert Project.find(3).allowed_parents.include?(nil) | |
|
328 | end | |
|
329 | ||
|
288 | 330 | def test_users_by_role |
|
289 | 331 | users_by_role = Project.find(1).users_by_role |
|
290 | 332 | assert_kind_of Hash, users_by_role |
General Comments 0
You need to be logged in to leave comments.
Login now