Skip to content

Commit d80c10a

Browse files
taoermanpre-commit-ci-lite[bot]
authored andcommitted
Use channelVersion objects instead of special permission ids (learningequality#5622)
* Use channelVersion objects instead of special permission ids * [pre-commit.ci lite] apply automatic fixes * fix linting * fix code * fix code * [pre-commit.ci lite] apply automatic fixes * fix code * fix code * [pre-commit.ci lite] apply automatic fixes * fix code --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 56da446 commit d80c10a

File tree

5 files changed

+157
-34
lines changed

5 files changed

+157
-34
lines changed

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

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const ITEMS_PER_PAGE = 3;
55

66
/**
77
* Composable that fetches and paginates audited special-permissions licenses
8-
* for a given set of permission IDs.
8+
* for a given channel version ID.
99
*
10-
* @param {Array<string|number>|import('vue').Ref<Array<string|number>>} permissionIds
11-
* A list (or ref to a list) of special-permissions license IDs to fetch.
10+
* @param {string|number|import('vue').Ref<string|number>|null} channelVersionId
11+
* The ChannelVersion ID to fetch special permissions for via ManyToMany relationship.
1212
*
1313
* @returns {{
1414
* permissions: import('vue').Ref<Array<Object>>,
@@ -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(channelVersionId, permissionIds) {
26+
export function useSpecialPermissions(channelVersionId) {
2727
const permissions = ref([]);
2828
const isLoading = ref(false);
2929
const error = ref(null);
@@ -39,30 +39,20 @@ export function useSpecialPermissions(channelVersionId, permissionIds) {
3939
return permissions.value.slice(start, end);
4040
});
4141

42-
async function fetchPermissions(versionId, ids) {
42+
async function fetchPermissions(versionId) {
4343
isLoading.value = true;
4444
error.value = null;
4545
permissions.value = [];
4646

4747
try {
48-
let response = [];
4948
if (versionId) {
50-
response = await AuditedSpecialPermissionsLicense.fetchCollection({
49+
const response = await AuditedSpecialPermissionsLicense.fetchCollection({
5150
channel_version: versionId,
5251
distributable: false,
5352
});
54-
} else if (ids && ids.length > 0) {
55-
response = await AuditedSpecialPermissionsLicense.fetchCollection({
56-
by_ids: ids.join(','),
57-
distributable: false,
58-
});
59-
}
6053

61-
permissions.value = response.map(permission => ({
62-
id: permission.id,
63-
description: permission.description,
64-
distributable: permission.distributable,
65-
}));
54+
permissions.value = response;
55+
}
6656
} catch (err) {
6757
error.value = err;
6858
permissions.value = [];
@@ -84,9 +74,9 @@ export function useSpecialPermissions(channelVersionId, permissionIds) {
8474
}
8575

8676
watch(
87-
[() => unref(channelVersionId), () => unref(permissionIds)],
88-
([versionId, ids]) => {
89-
fetchPermissions(versionId, ids);
77+
() => unref(channelVersionId),
78+
versionId => {
79+
fetchPermissions(versionId);
9080
},
9181
{ immediate: true },
9282
);

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@
161161
:licenses="includedLicenses"
162162
/>
163163
<SpecialPermissionsList
164-
v-if="licenseAuditIsFinished && specialPermissions.length > 0"
164+
v-if="licenseAuditIsFinished && channelVersionId"
165165
v-model="checkedSpecialPermissions"
166-
:channel-version-id="versionDetail && versionDetail.id"
167-
:permission-ids="specialPermissions"
166+
:channel-version-id="channelVersionId"
168167
@update:allChecked="allSpecialPermissionsChecked = $event"
169168
/>
170169
<div class="country-area">
@@ -426,11 +425,14 @@
426425
return channelVersion;
427426
});
428427
428+
const channelVersionId = computed(() => {
429+
return versionDetail.value?.id;
430+
});
431+
429432
const {
430433
isLoading: licenseAuditIsLoading,
431434
isFinished: licenseAuditIsFinished,
432435
invalidLicenses,
433-
specialPermissions,
434436
includedLicenses,
435437
checkAndTriggerAudit: checkAndTriggerLicenseAudit,
436438
} = useLicenseAudit(props.channel, currentChannelVersion);
@@ -569,6 +571,7 @@
569571
isCurrentVersionAlreadySubmitted,
570572
canBeEdited,
571573
displayedVersion,
574+
channelVersionId,
572575
canBeSubmitted,
573576
versionDetail,
574577
versionDetailIsLoading,
@@ -578,7 +581,6 @@
578581
licenseAuditIsLoading,
579582
licenseAuditIsFinished,
580583
invalidLicenses,
581-
specialPermissions,
582584
includedLicenses,
583585
onSubmit,
584586
// Translation functions

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
totalPages,
8888
nextPage,
8989
previousPage,
90-
} = useSpecialPermissions(props.channelVersionId, props.permissionIds);
90+
} = useSpecialPermissions(props.channelVersionId);
9191
9292
function togglePermission(permissionId) {
9393
const currentChecked = [...props.value];
@@ -133,11 +133,6 @@
133133
required: false,
134134
default: null,
135135
},
136-
permissionIds: {
137-
type: Array,
138-
required: false,
139-
default: () => [],
140-
},
141136
value: {
142137
type: Array,
143138
required: false,
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Generated by Django 3.2.24 on 2026-01-19 17:37
2+
import django.contrib.postgres.fields
3+
from django.db import migrations
4+
from django.db import models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("contentcuration", "0160_add_channel_version_model"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="channelversion",
16+
name="included_categories",
17+
field=django.contrib.postgres.fields.ArrayField(
18+
base_field=models.CharField(
19+
choices=[
20+
("d&WXdXWF.qs0Xlaxq.0t5msbL5", "Algebra"),
21+
("d&WXdXWF.K80UMYnW.ViBlbQR&", "Anthropology"),
22+
("d&WXdXWF.qs0Xlaxq.nG96nHDc", "Arithmetic"),
23+
("d&WXdXWF.5QAjgfv7", "Arts"),
24+
("d&WXdXWF.i1IdaNwr.mjSF4QlF", "Astronomy"),
25+
("d&WXdXWF.i1IdaNwr.uErN4PdS", "Biology"),
26+
("d&WXdXWF.qs0Xlaxq.8rJ57ht6", "Calculus"),
27+
("d&WXdXWF.i1IdaNwr.#r5ocgid", "Chemistry"),
28+
("d&WXdXWF.K80UMYnW.F863vKiF", "Civic Education"),
29+
("d&WXdXWF.e#RTW9E#", "Computer Science"),
30+
("PbGoe2MV.J7CU1IxN", "Current Events"),
31+
("PbGoe2MV", "Daily Life"),
32+
("d&WXdXWF.5QAjgfv7.BUMJJBnS", "Dance"),
33+
("BCG3&slG.wZ3EAedB", "Digital Literacy"),
34+
("PbGoe2MV.EHcbjuKq", "Diversity"),
35+
("d&WXdXWF.5QAjgfv7.XsWznP4o", "Drama"),
36+
("d&WXdXWF.i1IdaNwr.zbDzxDE7", "Earth Science"),
37+
("PbGoe2MV.kyxTNsRS", "Entrepreneurship"),
38+
("PbGoe2MV.tS7WKnZ7", "Environment"),
39+
("PbGoe2MV.HGIc9sZq", "Financial Literacy"),
40+
("ziJ6PCuU", "For Teachers"),
41+
("BCG3&slG", "Foundations"),
42+
(
43+
"BCG3&slG.0&d0qTqS",
44+
"Foundations Logic And Critical Thinking",
45+
),
46+
("d&WXdXWF.qs0Xlaxq.lb7ELcK5", "Geometry"),
47+
("ziJ6PCuU.RLfhp37t", "Guides"),
48+
("d&WXdXWF.zWtcJ&F2", "History"),
49+
("l7DsPDlm.ISEXeZt&.pRvOzJTE", "Industry And Sector Specific"),
50+
("d&WXdXWF.JDUfJNXc", "Language Learning"),
51+
("BCG3&slG.fP2j70bj", "Learning Skills"),
52+
("ziJ6PCuU.lOBPr5ix", "Lesson Plans"),
53+
("BCG3&slG.HLo9TbNq", "Literacy"),
54+
("d&WXdXWF.kHKJ&PbV.DJLBbaEk", "Literature"),
55+
("d&WXdXWF.kHKJ&PbV.YMBXStib", "Logic And Critical Thinking"),
56+
("d&WXdXWF.qs0Xlaxq", "Mathematics"),
57+
("d&WXdXWF.e#RTW9E#.8ZoaPsVW", "Mechanical Engineering"),
58+
("PbGoe2MV.UOTL#KIV", "Media Literacy"),
59+
("PbGoe2MV.d8&gCo2N", "Mental Health"),
60+
("d&WXdXWF.5QAjgfv7.u0aKjT4i", "Music"),
61+
("BCG3&slG.Tsyej9ta", "Numeracy"),
62+
("d&WXdXWF.i1IdaNwr.r#wbt#jF", "Physics"),
63+
("d&WXdXWF.K80UMYnW.K72&pITr", "Political Science"),
64+
("l7DsPDlm.#N2VymZo", "Professional Skills"),
65+
("d&WXdXWF.e#RTW9E#.CfnlTDZ#", "Programming"),
66+
("PbGoe2MV.kivAZaeX", "Public Health"),
67+
("d&WXdXWF.kHKJ&PbV", "Reading And Writing"),
68+
("d&WXdXWF.kHKJ&PbV.r7RxB#9t", "Reading Comprehension"),
69+
("d&WXdXWF", "School"),
70+
("d&WXdXWF.i1IdaNwr", "Sciences"),
71+
("l7DsPDlm.ISEXeZt&.&1WpYE&n", "Skills Training"),
72+
("d&WXdXWF.K80UMYnW", "Social Sciences"),
73+
("d&WXdXWF.K80UMYnW.75WBu1ZS", "Sociology"),
74+
("d&WXdXWF.qs0Xlaxq.jNm15RLB", "Statistics"),
75+
("l7DsPDlm.ISEXeZt&", "Technical And Vocational Training"),
76+
("l7DsPDlm.ISEXeZt&.1JfIbP&N", "Tools And Software Training"),
77+
("d&WXdXWF.5QAjgfv7.4LskOFXj", "Visual Art"),
78+
("d&WXdXWF.e#RTW9E#.P7s8FxQ8", "Web Design"),
79+
("l7DsPDlm", "Work"),
80+
("d&WXdXWF.kHKJ&PbV.KFJOCr&6", "Writing"),
81+
],
82+
max_length=100,
83+
),
84+
blank=True,
85+
null=True,
86+
size=None,
87+
),
88+
),
89+
migrations.AlterField(
90+
model_name="channelversion",
91+
name="included_licenses",
92+
field=django.contrib.postgres.fields.ArrayField(
93+
base_field=models.IntegerField(
94+
choices=[
95+
(1, "CC BY"),
96+
(2, "CC BY-SA"),
97+
(3, "CC BY-ND"),
98+
(4, "CC BY-NC"),
99+
(5, "CC BY-NC-SA"),
100+
(6, "CC BY-NC-ND"),
101+
(7, "All Rights Reserved"),
102+
(8, "Public Domain"),
103+
(9, "Special Permissions"),
104+
]
105+
),
106+
blank=True,
107+
null=True,
108+
size=None,
109+
),
110+
),
111+
migrations.AlterField(
112+
model_name="channelversion",
113+
name="non_distributable_licenses_included",
114+
field=django.contrib.postgres.fields.ArrayField(
115+
base_field=models.IntegerField(
116+
choices=[
117+
(1, "CC BY"),
118+
(2, "CC BY-SA"),
119+
(3, "CC BY-ND"),
120+
(4, "CC BY-NC"),
121+
(5, "CC BY-NC-SA"),
122+
(6, "CC BY-NC-ND"),
123+
(7, "All Rights Reserved"),
124+
(8, "Public Domain"),
125+
(9, "Special Permissions"),
126+
]
127+
),
128+
blank=True,
129+
null=True,
130+
size=None,
131+
),
132+
),
133+
]

contentcuration/contentcuration/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,15 @@ def validate_language_code(value):
14941494

14951495
def get_license_choices():
14961496
"""Helper function to get license choices for ArrayField."""
1497-
return [(lic[0], lic[1]) for lic in licenses.LICENSELIST]
1497+
license_labels = dict(licenses.choices)
1498+
return [
1499+
(lic.id, license_labels.get(lic.name, lic.name)) for lic in licenses.LICENSELIST
1500+
]
14981501

14991502

15001503
def get_categories_choices():
15011504
"""Helper function to get category choices for ArrayField."""
1502-
return [(subj, subj) for subj in subjects.SUBJECTSLIST]
1505+
return subjects.choices
15031506

15041507

15051508
class ChannelVersion(models.Model):

0 commit comments

Comments
 (0)