diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb index d06ef4091..f9faf9c63 100644 --- a/app/controllers/editions_controller.rb +++ b/app/controllers/editions_controller.rb @@ -332,15 +332,12 @@ def new_assignee def update_assignment(edition, assignee) return if edition.assigned_to == assignee - unless assignee.has_editor_permissions?(resource) - flash[:danger] = "Chosen assignee does not have correct editor permissions." - return - end - - if assignee + if !assignee + current_user.unassign(edition) + elsif assignee.has_editor_permissions?(resource) current_user.assign(edition, assignee) else - current_user.unassign(edition) + flash[:danger] = "Chosen assignee does not have correct editor permissions." end end diff --git a/test/functional/editions_controller_test.rb b/test/functional/editions_controller_test.rb index d0f220583..cacb3d321 100644 --- a/test/functional/editions_controller_test.rb +++ b/test/functional/editions_controller_test.rb @@ -314,6 +314,17 @@ class EditionsControllerTest < ActionController::TestCase assert_equal bob, @guide.assigned_to end + should "clear assignment if no assignment is passed" do + post :update, + params: { + id: @guide.id, + edition: {}, + } + + @guide.reload + assert_nil @guide.assigned_to + end + should "not create a new action if the assignment is unchanged" do bob = FactoryBot.create(:user, :govuk_editor) @user.assign(@guide, bob)