Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions contentcuration/contentcuration/tests/viewsets/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
8 changes: 8 additions & 0 deletions contentcuration/contentcuration/viewsets/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down