Skip to content

Commit

Permalink
Use current user as assignee
Browse files Browse the repository at this point in the history
Previously, a publisher would need to manually assign themselves as the
assignee when creating an edition. We now assign the user that
created the edition as the assignee. This can be still be modified from
the UI if the assignee is different from the creator, but for the
majority of cases this should be the expected behaviour.

Trello:
https://trello.com/c/3zzF4dKj/37-auto-assign-ownership-in-mainstream-publisher
  • Loading branch information
1pretz1 committed Jan 10, 2024
1 parent 0252a48 commit 818444f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def duplicate
if !resource.can_create_new_edition?
flash[:warning] = "Another person has created a newer edition"
redirect_to edition_path(resource)
elsif command.duplicate(target_edition_class_name, new_assignee)
elsif command.duplicate(target_edition_class_name, current_user)
new_edition = command.new_edition
UpdateWorker.perform_async(new_edition.id.to_s)

Expand Down
1 change: 1 addition & 0 deletions app/models/edition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def self.find_or_create_from_panopticon_data(panopticon_id, importing_user)
panopticon_id: metadata.id,
slug: metadata.slug,
title: metadata.name,
assigned_to_id: importing_user.id,
)
end

Expand Down
18 changes: 18 additions & 0 deletions test/models/edition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,24 @@ def draft_second_edition_from(published_edition)
assert_equal artefact.id.to_s, publication.panopticon_id.to_s
end

test "should create a publication with the current user as the assignee" do
artefact = FactoryBot.create(
:artefact,
slug: "foo-bar",
kind: "answer",
name: "Foo bar",
owning_app: "publisher",
)
artefact.save!

Artefact.find(artefact.id)
user = FactoryBot.create(:user, :govuk_editor)

publication = Edition.find_or_create_from_panopticon_data(artefact.id, user)

assert_equal user.id.to_s, publication.assigned_to_id.to_s
end

test "should not change edition metadata if archived" do
artefact = FactoryBot.create(
:artefact,
Expand Down

0 comments on commit 818444f

Please sign in to comment.