diff --git a/contentcuration/contentcuration/models.py b/contentcuration/contentcuration/models.py index 3a27333b5c..2fb86ae3d9 100644 --- a/contentcuration/contentcuration/models.py +++ b/contentcuration/contentcuration/models.py @@ -2960,6 +2960,12 @@ class AuditedSpecialPermissionsLicense(models.Model): description = models.TextField(unique=True, db_index=True) distributable = models.BooleanField(default=False) + @classmethod + def mark_channel_version_as_distributable(cls, channel_version_id): + return cls.objects.filter(channel_versions__id=channel_version_id).update( + distributable=True + ) + def __str__(self): return ( self.description[:100] if len(self.description) > 100 else self.description diff --git a/contentcuration/contentcuration/tests/viewsets/test_channel.py b/contentcuration/contentcuration/tests/viewsets/test_channel.py index b7b9c42908..247531fe8e 100644 --- a/contentcuration/contentcuration/tests/viewsets/test_channel.py +++ b/contentcuration/contentcuration/tests/viewsets/test_channel.py @@ -567,6 +567,12 @@ def test_process_added_to_community_library_change( channel.editors.add(editor_user) channel.save() + channel_version = ChannelVersion.objects.get(channel=channel, version=2) + special_license = AuditedSpecialPermissionsLicense.objects.create( + description="Community library special permissions" + ) + channel_version.special_permissions_included.add(special_license) + current_live_submission = CommunityLibrarySubmission.objects.create( channel=channel, channel_version=1, @@ -643,6 +649,44 @@ def test_process_added_to_community_library_change( new_submission.status, community_library_submission.STATUS_LIVE, ) + special_license.refresh_from_db() + self.assertTrue(special_license.distributable) + + def test_publish_public_channel_marks_special_permissions_distributable(self): + user = testdata.user() + channel = testdata.channel() + channel.public = True + channel.editors.add(user) + channel.save() + + special_permissions_license = models.License.objects.get( + license_name="Special Permissions" + ) + special_license_description = "Public channel special permissions" + contentnode = ( + channel.main_tree.get_descendants() + .exclude(kind_id=content_kinds.TOPIC) + .first() + ) + contentnode.license = special_permissions_license + contentnode.license_description = special_license_description + contentnode.copyright_holder = "Public channel" + contentnode.save() + + self.client.force_authenticate(user) + response = self.sync_changes([generate_publish_channel_event(channel.id)]) + + self.assertEqual(response.status_code, 200, response.content) + channel.refresh_from_db() + audited_license = AuditedSpecialPermissionsLicense.objects.get( + description=special_license_description + ) + self.assertTrue(audited_license.distributable) + self.assertTrue( + channel.version_info.special_permissions_included.filter( + id=audited_license.id + ).exists() + ) class CRUDTestCase(StudioAPITestCase): diff --git a/contentcuration/contentcuration/utils/publish.py b/contentcuration/contentcuration/utils/publish.py index e64ff0a3b2..9a00814dd7 100644 --- a/contentcuration/contentcuration/utils/publish.py +++ b/contentcuration/contentcuration/utils/publish.py @@ -1029,6 +1029,11 @@ def fill_published_fields(channel, version_notes): else: channel.version_info.special_permissions_included.clear() + if channel.public: + ccmodels.AuditedSpecialPermissionsLicense.mark_channel_version_as_distributable( + channel.version_info.id + ) + channel.save() diff --git a/contentcuration/contentcuration/viewsets/channel.py b/contentcuration/contentcuration/viewsets/channel.py index 4f54a1df30..82ff6e0c34 100644 --- a/contentcuration/contentcuration/viewsets/channel.py +++ b/contentcuration/contentcuration/viewsets/channel.py @@ -833,6 +833,14 @@ def add_to_community_library( countries=countries, ) + published_version = ChannelVersion.objects.get( + channel_id=channel_id, + version=channel_version, + ) + models.AuditedSpecialPermissionsLicense.mark_channel_version_as_distributable( + published_version.id + ) + new_live_submission = CommunityLibrarySubmission.objects.get( channel_id=channel_id, channel_version=channel_version,