Skip to content

Commit

Permalink
Merge pull request #1903 from alphagov/allow_nil_assigned_to
Browse files Browse the repository at this point in the history
fix(editions) prevent calling method on nil
  • Loading branch information
FelixMarcusMillne authored Aug 21, 2023
2 parents ba1d312 + 4ed960b commit ae30b3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 4 additions & 7 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test/functional/editions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ae30b3f

Please sign in to comment.