@@ -348,8 +348,6 private | |||||
348 | # from the params |
|
348 | # from the params | |
349 | # TODO: Refactor, not everything in here is needed by #edit |
|
349 | # TODO: Refactor, not everything in here is needed by #edit | |
350 | def update_issue_from_params |
|
350 | def update_issue_from_params | |
351 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
|||
352 | @priorities = IssuePriority.active |
|
|||
353 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) |
|
351 | @edit_allowed = User.current.allowed_to?(:edit_issues, @project) | |
354 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
352 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) | |
355 | @time_entry.attributes = params[:time_entry] |
|
353 | @time_entry.attributes = params[:time_entry] | |
@@ -371,6 +369,8 private | |||||
371 | end |
|
369 | end | |
372 | end |
|
370 | end | |
373 | @issue.safe_attributes = issue_attributes |
|
371 | @issue.safe_attributes = issue_attributes | |
|
372 | @priorities = IssuePriority.active | |||
|
373 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) | |||
374 | true |
|
374 | true | |
375 | end |
|
375 | end | |
376 |
|
376 |
@@ -509,17 +509,25 class Issue < ActiveRecord::Base | |||||
509 | !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? |
|
509 | !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil? | |
510 | end |
|
510 | end | |
511 |
|
511 | |||
512 | # Returns an array of status that user is able to apply |
|
512 | # Returns an array of statuses that user is able to apply | |
513 | def new_statuses_allowed_to(user=User.current, include_default=false) |
|
513 | def new_statuses_allowed_to(user=User.current, include_default=false) | |
514 | statuses = status.find_new_statuses_allowed_to( |
|
514 | initial_status = nil | |
|
515 | if new_record? | |||
|
516 | initial_status = IssueStatus.default | |||
|
517 | elsif status_id_was | |||
|
518 | initial_status = IssueStatus.find_by_id(status_id_was) | |||
|
519 | end | |||
|
520 | initial_status ||= status | |||
|
521 | ||||
|
522 | statuses = initial_status.find_new_statuses_allowed_to( | |||
515 | user.admin ? Role.all : user.roles_for_project(project), |
|
523 | user.admin ? Role.all : user.roles_for_project(project), | |
516 | tracker, |
|
524 | tracker, | |
517 | author == user, |
|
525 | author == user, | |
518 | assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id |
|
526 | assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id | |
519 | ) |
|
527 | ) | |
520 | statuses << status unless statuses.empty? |
|
528 | statuses << initial_status unless statuses.empty? | |
521 | statuses << IssueStatus.default if include_default |
|
529 | statuses << IssueStatus.default if include_default | |
522 | statuses = statuses.uniq.sort |
|
530 | statuses = statuses.compact.uniq.sort | |
523 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses |
|
531 | blocked? ? statuses.reject {|s| s.is_closed?} : statuses | |
524 | end |
|
532 | end | |
525 |
|
533 |
@@ -1372,6 +1372,22 class IssuesControllerTest < ActionController::TestCase | |||||
1372 | assert_equal 'This is the test_new issue', issue.subject |
|
1372 | assert_equal 'This is the test_new issue', issue.subject | |
1373 | end |
|
1373 | end | |
1374 |
|
1374 | |||
|
1375 | def test_update_new_form_should_propose_transitions_based_on_initial_status | |||
|
1376 | @request.session[:user_id] = 2 | |||
|
1377 | Workflow.delete_all | |||
|
1378 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) | |||
|
1379 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) | |||
|
1380 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) | |||
|
1381 | ||||
|
1382 | xhr :post, :new, :project_id => 1, | |||
|
1383 | :issue => {:tracker_id => 1, | |||
|
1384 | :status_id => 5, | |||
|
1385 | :subject => 'This is an issue'} | |||
|
1386 | ||||
|
1387 | assert_equal 5, assigns(:issue).status_id | |||
|
1388 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort | |||
|
1389 | end | |||
|
1390 | ||||
1375 | def test_post_create |
|
1391 | def test_post_create | |
1376 | @request.session[:user_id] = 2 |
|
1392 | @request.session[:user_id] = 2 | |
1377 | assert_difference 'Issue.count' do |
|
1393 | assert_difference 'Issue.count' do | |
@@ -2180,6 +2196,23 class IssuesControllerTest < ActionController::TestCase | |||||
2180 | assert_equal 'This is the test_new issue', issue.subject |
|
2196 | assert_equal 'This is the test_new issue', issue.subject | |
2181 | end |
|
2197 | end | |
2182 |
|
2198 | |||
|
2199 | def test_update_edit_form_should_propose_transitions_based_on_initial_status | |||
|
2200 | @request.session[:user_id] = 2 | |||
|
2201 | Workflow.delete_all | |||
|
2202 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) | |||
|
2203 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) | |||
|
2204 | Workflow.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) | |||
|
2205 | ||||
|
2206 | xhr :put, :new, :project_id => 1, | |||
|
2207 | :id => 2, | |||
|
2208 | :issue => {:tracker_id => 2, | |||
|
2209 | :status_id => 5, | |||
|
2210 | :subject => 'This is an issue'} | |||
|
2211 | ||||
|
2212 | assert_equal 5, assigns(:issue).status_id | |||
|
2213 | assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort | |||
|
2214 | end | |||
|
2215 | ||||
2183 | def test_update_edit_form_with_project_change |
|
2216 | def test_update_edit_form_with_project_change | |
2184 | @request.session[:user_id] = 2 |
|
2217 | @request.session[:user_id] = 2 | |
2185 | xhr :put, :new, :project_id => 1, |
|
2218 | xhr :put, :new, :project_id => 1, |
General Comments 0
You need to be logged in to leave comments.
Login now