From 818444f3cf669eb2cf52b4a167df57f615c33c92 Mon Sep 17 00:00:00 2001 From: Peter Hartshorn Date: Tue, 9 Jan 2024 13:09:55 +0000 Subject: [PATCH] Use current user as assignee 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 --- app/controllers/editions_controller.rb | 2 +- app/models/edition.rb | 1 + test/models/edition_test.rb | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb index f2a9fa7e2..72321bef3 100644 --- a/app/controllers/editions_controller.rb +++ b/app/controllers/editions_controller.rb @@ -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) diff --git a/app/models/edition.rb b/app/models/edition.rb index 101d98c29..af1c5edcd 100644 --- a/app/models/edition.rb +++ b/app/models/edition.rb @@ -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 diff --git a/test/models/edition_test.rb b/test/models/edition_test.rb index ae32edef7..93551cf77 100644 --- a/test/models/edition_test.rb +++ b/test/models/edition_test.rb @@ -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,