Skip to content
Open
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
37 changes: 37 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,37 @@ 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)

@mock.patch("contentcuration.viewsets.channel.publish_channel")
def test_publish_public_channel_marks_special_permissions_distributable(
self, mock_publish_channel
):
user = testdata.user()
channel = testdata.channel()
channel.version = 1
channel.public = True
channel.editors.add(user)
channel.save()

channel_version = ChannelVersion.objects.get(channel=channel, version=1)
channel.version_info = channel_version
channel.save()

special_license = AuditedSpecialPermissionsLicense.objects.create(
description="Public channel special permissions"
)
channel_version.special_permissions_included.add(special_license)

mock_publish_channel.return_value = channel

self.client.force_authenticate(user)
response = self.sync_changes([generate_publish_channel_event(channel.id)])

self.assertEqual(response.status_code, 200, response.content)
special_license.refresh_from_db()
self.assertTrue(special_license.distributable)


class CRUDTestCase(StudioAPITestCase):
Expand Down
12 changes: 12 additions & 0 deletions contentcuration/contentcuration/viewsets/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ def publish(self, pk, version_notes="", language=None):
progress_tracker=progress_tracker,
language=language,
)
if channel.public and channel.version_info:
models.AuditedSpecialPermissionsLicense.mark_channel_version_as_distributable(
channel.version_info.id
)
Change.create_changes(
[
generate_update_event(
Expand Down Expand Up @@ -833,6 +837,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