diff --git a/contentcuration/contentcuration/tests/views/test_views_internal.py b/contentcuration/contentcuration/tests/views/test_views_internal.py index 7689bace3a..3a8f50a6d2 100644 --- a/contentcuration/contentcuration/tests/views/test_views_internal.py +++ b/contentcuration/contentcuration/tests/views/test_views_internal.py @@ -777,6 +777,23 @@ def test_creates_channel(self): except Channel.DoesNotExist: self.fail("Channel was not created") + def test_updates_already_created_channel(self): + """ + Test that it creates a channel with the given id + """ + deleted_channel = channel() + deleted_channel.deleted = True + deleted_channel.save(actor_id=self.user.id) + self.channel_data.update({"name": "Updated name", "id": deleted_channel.id}) + self.admin_client().post( + reverse_lazy("api_create_channel"), data={"channel_data": self.channel_data}, format="json" + ) + try: + c = Channel.objects.get(id=self.channel_data["id"]) + self.assertEqual(c.name, "Updated name") + except Channel.DoesNotExist: + self.fail("Channel was not created") + def test_creates_cheftree(self): """ Test that it creates a channel with the given id diff --git a/contentcuration/contentcuration/views/internal.py b/contentcuration/contentcuration/views/internal.py index 13eba6376f..f2f268ca1a 100644 --- a/contentcuration/contentcuration/views/internal.py +++ b/contentcuration/contentcuration/views/internal.py @@ -519,7 +519,9 @@ def create_channel(channel_data, user): if files: map_files_to_node(user, channel.chef_tree, files) channel.chef_tree.save() - channel.save() + # If the channel was previously deleted, this save will undelete it + # so will require the actor_id to be set + channel.save(actor_id=user.id) # Delete chef tree if it already exists if old_chef_tree and old_chef_tree != channel.staging_tree: