Skip to content

Commit fdd5a84

Browse files
Create ChannelVersion model with token support (#5589)
* Create ChannelVersion model with token support * [pre-commit.ci lite] apply automatic fixes * fix linting * fix code * [pre-commit.ci lite] apply automatic fixes * fix code * [pre-commit.ci lite] apply automatic fixes * fix code * fix code * [pre-commit.ci lite] apply automatic fixes * fix test * [pre-commit.ci lite] apply automatic fixes * fix bug * fix bug * [pre-commit.ci lite] apply automatic fixes * fix code * [pre-commit.ci lite] apply automatic fixes * fix code * fix linting * [pre-commit.ci lite] apply automatic fixes * fix linting * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent eee1576 commit fdd5a84

File tree

19 files changed

+1252
-103
lines changed

19 files changed

+1252
-103
lines changed

contentcuration/contentcuration/frontend/channelEdit/components/sidePanels/SubmitToCommunityLibrarySidePanel/__tests__/SubmitToCommunityLibrarySidePanel.spec.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,10 @@ const nonPublishedChannel = {
9898
};
9999

100100
const publishedData = {
101-
2: {
102-
included_languages: ['en', null],
103-
included_licenses: [1],
104-
included_categories: [Categories.SCHOOL],
105-
},
106-
1: {
107-
included_languages: ['en', null],
108-
included_licenses: [1],
109-
included_categories: [Categories.SCHOOL],
110-
},
101+
version: 2,
102+
included_languages: ['en', null],
103+
included_licenses: [1],
104+
included_categories: [Categories.SCHOOL],
111105
};
112106

113107
const submittedLatestSubmission = { channel_version: 2, status: CommunityLibraryStatus.PENDING };
@@ -149,7 +143,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
149143
it('when channel is not published', async () => {
150144
const wrapper = await makeWrapper({
151145
channel: nonPublishedChannel,
152-
publishedData: {},
146+
publishedData: null,
153147
latestSubmission: null,
154148
});
155149

@@ -301,12 +295,10 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
301295

302296
const channel = { ...publishedNonPublicChannel, publishing: true };
303297
const publishedDataWithVersion3 = {
304-
...publishedData,
305-
3: {
306-
included_languages: ['en', null],
307-
included_licenses: [1],
308-
included_categories: [Categories.SCHOOL],
309-
},
298+
version: 3,
299+
included_languages: ['en', null],
300+
included_licenses: [1],
301+
included_categories: [Categories.SCHOOL],
310302
};
311303
const wrapper = await makeWrapper({
312304
channel,
@@ -434,7 +426,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
434426
it('when channel is not published', async () => {
435427
const wrapper = await makeWrapper({
436428
channel: nonPublishedChannel,
437-
publishedData: {},
429+
publishedData: null,
438430
latestSubmission: null,
439431
});
440432

@@ -470,7 +462,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
470462
it('when channel is not published', async () => {
471463
const wrapper = await makeWrapper({
472464
channel: nonPublishedChannel,
473-
publishedData: {},
465+
publishedData: null,
474466
latestSubmission: null,
475467
});
476468

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/usePublishedData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { useFetch } from '../../../../composables/useFetch';
22
import { Channel } from 'shared/data/resources';
33

44
export function usePublishedData(channelId) {
5-
return useFetch({ asyncFetchFunc: () => Channel.getPublishedData(channelId) });
5+
return useFetch({ asyncFetchFunc: () => Channel.getVersionDetail(channelId) });
66
}

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: 12 additions & 22 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">
@@ -417,17 +418,15 @@
417418
const {
418419
isLoading: publishedDataIsLoading,
419420
isFinished: publishedDataIsFinished,
420-
data: publishedData,
421+
data: versionDetail,
421422
fetchData: fetchPublishedData,
422423
} = usePublishedData(props.channel.id);
423424
424-
// Use the latest version available from either channel or publishedData
425+
// Use the latest version available from either channel or versionDetail
425426
const displayedVersion = computed(() => {
426427
const channelVersion = currentChannelVersion.value || 0;
427-
if (publishedData.value && Object.keys(publishedData.value).length > 0) {
428-
const publishedVersions = Object.keys(publishedData.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
});
@@ -465,11 +464,6 @@
465464
return conditions.every(condition => condition);
466465
});
467466
468-
const latestPublishedData = computed(() => {
469-
if (!publishedData.value || !displayedVersion.value) return undefined;
470-
return publishedData.value[displayedVersion.value];
471-
});
472-
473467
// Watch for when publishing completes - fetch publishedData to get the new version's data
474468
watch(isPublishing, async (newIsPublishing, oldIsPublishing) => {
475469
if (oldIsPublishing === true && newIsPublishing === false) {
@@ -488,11 +482,7 @@
488482
});
489483
490484
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 = latestPublishedData.value?.included_languages.filter(
494-
code => code !== null,
495-
);
485+
const languageCodes = versionDetail.value?.included_languages;
496486
497487
// We distinguish here between "not loaded yet" (undefined)
498488
// and "loaded and none present" (null). This distinction is
@@ -502,7 +492,7 @@
502492
if (!languageCodes) return undefined;
503493
if (languageCodes.length === 0) return null;
504494
505-
return languageCodes.map(code => LanguagesMap.get(code).readable_name).join(', ');
495+
return languageCodes.map(code => LanguagesMap.get(code)?.readable_name || code).join(', ');
506496
});
507497
508498
function categoryIdToName(categoryId) {
@@ -515,10 +505,10 @@
515505
// not used in the UI and is mostly intended to convey the
516506
// state more accurately to the developer in case of debugging.
517507
// UI code should rely on XXXIsLoading and XXXIsFinished instead.
518-
if (!latestPublishedData.value?.included_categories) return undefined;
519-
if (latestPublishedData.value.included_categories.length === 0) return null;
508+
if (!versionDetail.value?.included_categories) return undefined;
509+
if (versionDetail.value.included_categories.length === 0) return null;
520510
521-
return latestPublishedData.value.included_categories
511+
return versionDetail.value.included_categories
522512
.map(categoryId => categoryIdToName(categoryId))
523513
.join(', ');
524514
});
@@ -544,7 +534,7 @@
544534
description: description.value,
545535
channel: props.channel.id,
546536
countries: countries.value.map(country => countriesUtil.getAlpha2Code(country, 'en')),
547-
categories: latestPublishedData.value.included_categories,
537+
categories: versionDetail.value.included_categories,
548538
})
549539
.then(() => {
550540
showSnackbar({ text: submittedSnackbar$() });

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/frontend/shared/data/resources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,8 @@ export const Channel = new CreateModelResource({
14121412
.then(response => response.data.languages);
14131413
return uniq(compact(localLanguages.concat(remoteLanguages)));
14141414
},
1415-
async getPublishedData(id) {
1416-
const response = await client.get(window.Urls.channel_published_data(id));
1415+
async getVersionDetail(id) {
1416+
const response = await client.get(window.Urls.channel_version_detail(id));
14171417
return response.data;
14181418
},
14191419
async auditLicenses(id) {

0 commit comments

Comments
 (0)