Skip to content

Commit 609e651

Browse files
committed
fix code
1 parent b213fd0 commit 609e651

File tree

8 files changed

+53
-97
lines changed

8 files changed

+53
-97
lines changed

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/composables/useLicenseAudit.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ export function useLicenseAudit(channelRef, channelVersionRef) {
3636
}
3737

3838
return (
39-
'community_library_invalid_licenses' in versionData &&
40-
'community_library_special_permissions' in versionData
39+
'non_distributable_licenses_included' in versionData &&
40+
'special_permissions_included' in versionData
4141
);
4242
});
4343

4444
const invalidLicenses = computed(() => {
4545
const versionData = currentVersionData.value;
46-
return versionData?.community_library_invalid_licenses || [];
46+
return versionData?.non_distributable_licenses_included || [];
4747
});
4848

4949
const specialPermissions = computed(() => {
5050
const versionData = currentVersionData.value;
51-
return versionData?.community_library_special_permissions || [];
51+
return versionData?.special_permissions_included || [];
5252
});
5353

5454
const includedLicenses = computed(() => {
@@ -123,5 +123,6 @@ export function useLicenseAudit(channelRef, channelVersionRef) {
123123
checkAndTriggerAudit,
124124
triggerAudit,
125125
fetchPublishedData,
126+
currentVersionData,
126127
};
127128
}

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/composables/useSpecialPermissions.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const ITEMS_PER_PAGE = 3;
2323
* Reactive state for the fetched, flattened permissions and pagination
2424
* helpers used by `SpecialPermissionsList.vue`.
2525
*/
26-
export function useSpecialPermissions(permissionIds) {
26+
export function useSpecialPermissions(channelVersionId, permissionIds) {
2727
const permissions = ref([]);
2828
const isLoading = ref(false);
2929
const error = ref(null);
@@ -39,20 +39,24 @@ export function useSpecialPermissions(permissionIds) {
3939
return permissions.value.slice(start, end);
4040
});
4141

42-
async function fetchPermissions(ids) {
43-
if (!ids || ids.length === 0) {
44-
permissions.value = [];
45-
return;
46-
}
47-
42+
async function fetchPermissions(versionId, ids) {
4843
isLoading.value = true;
4944
error.value = null;
45+
permissions.value = [];
5046

5147
try {
52-
const response = await AuditedSpecialPermissionsLicense.fetchCollection({
53-
by_ids: ids.join(','),
54-
distributable: false,
55-
});
48+
let response = [];
49+
if (versionId) {
50+
response = await AuditedSpecialPermissionsLicense.fetchCollection({
51+
channel_version: versionId,
52+
distributable: false,
53+
});
54+
} else if (ids && ids.length > 0) {
55+
response = await AuditedSpecialPermissionsLicense.fetchCollection({
56+
by_ids: ids.join(','),
57+
distributable: false,
58+
});
59+
}
5660

5761
permissions.value = response.map(permission => ({
5862
id: permission.id,
@@ -79,18 +83,10 @@ export function useSpecialPermissions(permissionIds) {
7983
}
8084
}
8185

82-
const resolvedPermissionIds = computed(() => {
83-
const ids = unref(permissionIds);
84-
if (!ids || ids.length === 0) {
85-
return [];
86-
}
87-
return ids;
88-
});
89-
9086
watch(
91-
resolvedPermissionIds,
92-
ids => {
93-
fetchPermissions(ids);
87+
[() => unref(channelVersionId), () => unref(permissionIds)],
88+
([versionId, ids]) => {
89+
fetchPermissions(versionId, ids);
9490
},
9591
{ immediate: true },
9692
);

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/index.vue

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@
163163
<SpecialPermissionsList
164164
v-if="licenseAuditIsFinished && specialPermissions.length > 0"
165165
v-model="checkedSpecialPermissions"
166-
:permissionIds="specialPermissions"
166+
:channel-version-id="versionDetail && versionDetail.id"
167+
:permission-ids="specialPermissions"
167168
@update:allChecked="allSpecialPermissionsChecked = $event"
168169
/>
169170
<div class="country-area">
@@ -424,10 +425,8 @@
424425
// Use the latest version available from either channel or versionDetail
425426
const displayedVersion = computed(() => {
426427
const channelVersion = currentChannelVersion.value || 0;
427-
if (versionDetail.value && Object.keys(versionDetail.value).length > 0) {
428-
const publishedVersions = Object.keys(versionDetail.value).map(v => parseInt(v, 10));
429-
const maxPublishedVersion = Math.max(...publishedVersions);
430-
return Math.max(channelVersion, maxPublishedVersion);
428+
if (versionDetail.value && versionDetail.value.version) {
429+
return Math.max(channelVersion, versionDetail.value.version);
431430
}
432431
return channelVersion;
433432
});
@@ -439,6 +438,7 @@
439438
specialPermissions,
440439
includedLicenses,
441440
checkAndTriggerAudit: checkAndTriggerLicenseAudit,
441+
currentVersionData,
442442
} = useLicenseAudit(props.channel, currentChannelVersion);
443443
444444
const allSpecialPermissionsChecked = ref(true);
@@ -465,11 +465,6 @@
465465
return conditions.every(condition => condition);
466466
});
467467
468-
const latestPublishedData = computed(() => {
469-
if (!publishedData.value || !displayedVersion.value) return undefined;
470-
return publishedData.value[displayedVersion.value];
471-
});
472-
473468
// Watch for when publishing completes - fetch publishedData to get the new version's data
474469
watch(isPublishing, async (newIsPublishing, oldIsPublishing) => {
475470
if (oldIsPublishing === true && newIsPublishing === false) {
@@ -483,14 +478,15 @@
483478
484479
if (!isPublishing.value) {
485480
await fetchPublishedData();
481+
console.log('versionDetail:', versionDetail.value);
486482
await checkAndTriggerLicenseAudit();
483+
console.log('specialPermissions:', specialPermissions.value);
484+
console.log('currentVersionData:', currentVersionData.value);
487485
}
488486
});
489487
490488
const detectedLanguages = computed(() => {
491-
// We need to filter out null values due to a backend bug
492-
// causing null values to sometimes be included in the list
493-
const languageCodes = versionDetail.value?.included_languages.filter(code => code !== null);
489+
const languageCodes = versionDetail.value?.included_languages;
494490
495491
// We distinguish here between "not loaded yet" (undefined)
496492
// and "loaded and none present" (null). This distinction is

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/licenseCheck/SpecialPermissionsList.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
totalPages,
8888
nextPage,
8989
previousPage,
90-
} = useSpecialPermissions(props.permissionIds);
90+
} = useSpecialPermissions(props.channelVersionId, props.permissionIds);
9191
9292
function togglePermission(permissionId) {
9393
const currentChecked = [...props.value];
@@ -128,6 +128,11 @@
128128
};
129129
},
130130
props: {
131+
channelVersionId: {
132+
type: String,
133+
required: false,
134+
default: null,
135+
},
131136
permissionIds: {
132137
type: Array,
133138
required: false,

contentcuration/contentcuration/tests/utils/test_publish.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ class IncrementChannelVersionTestCase(StudioTestCase):
104104
def setUp(self):
105105
super().setUp()
106106
self.channel = testdata.channel()
107-
self.channel.version = 1
108-
self.channel.save()
109-
110-
ChannelVersion.objects.filter(channel=self.channel).delete()
111-
self.channel.version_info = None
107+
self.channel.version = 0
112108
self.channel.save()
113109

114110
def test_increment_published_version(self):
@@ -155,12 +151,12 @@ def test_multiple_published_versions(self):
155151

156152
self.channel.refresh_from_db()
157153

158-
self.assertEqual(self.channel.version, 4)
154+
self.assertEqual(self.channel.version, 3)
159155

160-
self.assertEqual(self.channel.channel_versions.count(), 4)
156+
self.assertEqual(self.channel.channel_versions.count(), 3)
161157

162158
self.assertIsNotNone(self.channel.version_info)
163-
self.assertEqual(self.channel.version_info.version, 4)
159+
self.assertEqual(self.channel.version_info.version, 3)
164160

165161
def test_mixed_draft_and_published_versions(self):
166162
"""Test creating mix of draft and published versions."""
@@ -170,14 +166,14 @@ def test_mixed_draft_and_published_versions(self):
170166

171167
self.channel.refresh_from_db()
172168

173-
self.assertEqual(self.channel.version, 2)
169+
self.assertEqual(self.channel.version, 1)
174170

175-
self.assertEqual(self.channel.channel_versions.count(), 3)
171+
self.assertEqual(self.channel.channel_versions.count(), 2)
176172
self.assertEqual(uuid.UUID(str(draft1.id)), uuid.UUID(str(draft2.id)))
177173

178174
self.assertIsNotNone(draft1.secret_token)
179175
self.assertIsNotNone(draft2.secret_token)
180176

181177
self.assertIsNotNone(self.channel.version_info)
182-
self.assertEqual(self.channel.version_info.version, 2)
178+
self.assertEqual(self.channel.version_info.version, 1)
183179
self.assertIsNone(self.channel.version_info.secret_token)

contentcuration/contentcuration/urls.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
)
4040
from contentcuration.viewsets.bookmark import BookmarkViewSet
4141
from contentcuration.viewsets.channel import AdminChannelViewSet
42-
from contentcuration.viewsets.channel import AuditedSpecialPermissionsLicenseViewSet
4342
from contentcuration.viewsets.channel import CatalogViewSet
4443
from contentcuration.viewsets.channel import ChannelViewSet
4544
from contentcuration.viewsets.channelset import ChannelSetViewSet
@@ -73,11 +72,6 @@ def get_redirect_url(self, *args, **kwargs):
7372

7473

7574
router = routers.DefaultRouter(trailing_slash=False)
76-
router.register(
77-
r"audited_special_permissions_license",
78-
AuditedSpecialPermissionsLicenseViewSet,
79-
basename="audited-special-permissions-license",
80-
)
8175
router.register(r"bookmark", BookmarkViewSet, basename="bookmark")
8276
router.register(r"channel", ChannelViewSet)
8377
router.register(r"channelset", ChannelSetViewSet)

contentcuration/contentcuration/viewsets/audited_special_permissions_license.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django_filters.rest_framework import BooleanFilter
22
from django_filters.rest_framework import DjangoFilterBackend
33
from django_filters.rest_framework import FilterSet
4+
from django_filters.rest_framework import UUIDFilter
45
from rest_framework.permissions import IsAuthenticated
56

67
from contentcuration.models import AuditedSpecialPermissionsLicense
@@ -11,15 +12,19 @@
1112
class AuditedSpecialPermissionsLicenseFilter(FilterSet):
1213
"""
1314
Filter for AuditedSpecialPermissionsLicense viewset.
14-
Supports filtering by IDs and distributable status.
15+
Supports filtering by IDs, distributable status, and channelVersion.
1516
"""
1617

1718
by_ids = UUIDInFilter(field_name="id")
1819
distributable = BooleanFilter()
20+
channel_version = UUIDFilter(
21+
field_name="channel_versions__id",
22+
help_text="Filter by ChannelVersion ID",
23+
)
1924

2025
class Meta:
2126
model = None
22-
fields = ("by_ids", "distributable")
27+
fields = ("by_ids", "distributable", "channel_version")
2328

2429
def __init__(self, *args, **kwargs):
2530

@@ -30,7 +35,7 @@ def __init__(self, *args, **kwargs):
3035
class AuditedSpecialPermissionsLicenseViewSet(ReadOnlyValuesViewset):
3136
"""
3237
Read-only viewset for AuditedSpecialPermissionsLicense.
33-
Allows filtering by IDs and distributable status.
38+
Allows filtering by IDs, distributable status, and channelVersion.
3439
"""
3540

3641
permission_classes = [IsAuthenticated]

contentcuration/contentcuration/viewsets/channel.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
from django_cte import With
2323
from django_filters.rest_framework import BooleanFilter
2424
from django_filters.rest_framework import CharFilter
25-
from django_filters.rest_framework import DjangoFilterBackend
26-
from django_filters.rest_framework import FilterSet
27-
from django_filters.rest_framework import UUIDFilter
2825
from kolibri_public.utils.export_channel_to_kolibri_public import (
2926
export_channel_to_kolibri_public,
3027
)
@@ -50,7 +47,6 @@
5047
community_library_submission as community_library_submission_constants,
5148
)
5249
from contentcuration.decorators import cache_no_user_data
53-
from contentcuration.models import AuditedSpecialPermissionsLicense
5450
from contentcuration.models import Change
5551
from contentcuration.models import Channel
5652
from contentcuration.models import ChannelVersion
@@ -1330,36 +1326,3 @@ class Meta:
13301326
model = Channel
13311327
fields = ("id", "name", "editor_count", "public")
13321328
read_only_fields = ("id", "name", "editor_count", "public")
1333-
1334-
1335-
class AuditedSpecialPermissionsLicenseFilter(FilterSet):
1336-
"""Filter for AuditedSpecialPermissionsLicense by channelVersion."""
1337-
1338-
channel_version = UUIDFilter(
1339-
field_name="channel_versions__id",
1340-
help_text="Filter by ChannelVersion ID",
1341-
)
1342-
1343-
class Meta:
1344-
model = AuditedSpecialPermissionsLicense
1345-
fields = ["channel_version"]
1346-
1347-
1348-
class AuditedSpecialPermissionsLicenseViewSet(ReadOnlyValuesViewset):
1349-
"""
1350-
ViewSet for retrieving AuditedSpecialPermissionsLicense objects.
1351-
Supports filtering by channelVersion to get licenses for a specific channel version.
1352-
"""
1353-
1354-
queryset = AuditedSpecialPermissionsLicense.objects.all()
1355-
permission_classes = [IsAuthenticated]
1356-
filter_backends = [DjangoFilterBackend]
1357-
filterset_class = AuditedSpecialPermissionsLicenseFilter
1358-
1359-
values = ("id", "description", "distributable")
1360-
1361-
field_map = {
1362-
"id": "id",
1363-
"description": "description",
1364-
"distributable": "distributable",
1365-
}

0 commit comments

Comments
 (0)