From dbd7c9ce28d2d7325fd19838a5a435a54f77e33f Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 22 Jan 2025 00:08:45 +0530 Subject: [PATCH] Modified validators in few files according to new ValidateObject --- .../learn/assets/src/views/ContentPage.vue | 46 ++++++++++++++++++- .../SearchFiltersPanel/SelectGroup.vue | 17 ++++++- .../FacilityAdminCredentialsForm.vue | 16 ++++++- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/kolibri/plugins/learn/assets/src/views/ContentPage.vue b/kolibri/plugins/learn/assets/src/views/ContentPage.vue index 4bb51983ec7..a614dcdab40 100644 --- a/kolibri/plugins/learn/assets/src/views/ContentPage.vue +++ b/kolibri/plugins/learn/assets/src/views/ContentPage.vue @@ -111,6 +111,7 @@ import Modalities from 'kolibri-constants/Modalities'; import useUser from 'kolibri/composables/useUser'; import useSnackbar from 'kolibri/composables/useSnackbar'; + import { validateObject } from 'kolibri/utils/objectSpecs'; import { setContentNodeProgress } from '../composables/useContentNodeProgress'; import useProgressTracking from '../composables/useProgressTracking'; import useContentLink from '../composables/useContentLink'; @@ -186,7 +187,50 @@ type: Object, required: true, validator(val) { - return val.kind && val.content_id; + return validateObject(val, { + kind: { + type: String, + required: true, + }, + content_id: { + type: String, + required: true, + }, + title: { + type: String, + required: true, + }, + ancestors: { + type: Array, + required: false, + default: () => [], + }, + files: { + type: Array, + required: false, + default: () => [], + }, + options: { + type: Object, + required: false, + default: () => ({}), + }, + available: { + type: Boolean, + required: false, + default: true, + }, + duration: { + type: Number, + required: false, + default: 0, + }, + assessmentmetadata: { + type: Object, + required: false, + default: () => ({}), + }, + }); }, }, // only present when the content node is being viewed as part of lesson diff --git a/packages/kolibri-common/components/SearchFiltersPanel/SelectGroup.vue b/packages/kolibri-common/components/SearchFiltersPanel/SelectGroup.vue index cf26123bff5..be6aab31509 100644 --- a/packages/kolibri-common/components/SearchFiltersPanel/SelectGroup.vue +++ b/packages/kolibri-common/components/SearchFiltersPanel/SelectGroup.vue @@ -47,6 +47,7 @@ import { ContentLevels, AccessibilityCategories } from 'kolibri/constants'; import commonCoreStrings from 'kolibri/uiText/commonCoreStrings'; import { injectBaseSearch } from 'kolibri-common/composables/useBaseSearch'; + import { validateObject } from 'kolibri/utils/objectSpecs'; export default { name: 'SelectGroup', @@ -70,8 +71,20 @@ type: Object, required: true, validator(value) { - const inputKeys = ['accessibility_labels', 'languages', 'grade_levels']; - return inputKeys.every(k => Object.prototype.hasOwnProperty.call(value, k)); + return validateObject(value, { + accessibility_labels: { + type: Array, + required: true, + }, + languages: { + type: Array, + required: true, + }, + grade_levels: { + type: Array, + required: true, + }, + }); }, }, }, diff --git a/packages/kolibri-common/components/syncComponentSet/FacilityAdminCredentialsForm.vue b/packages/kolibri-common/components/syncComponentSet/FacilityAdminCredentialsForm.vue index 662ada7e3eb..b2df9440081 100644 --- a/packages/kolibri-common/components/syncComponentSet/FacilityAdminCredentialsForm.vue +++ b/packages/kolibri-common/components/syncComponentSet/FacilityAdminCredentialsForm.vue @@ -48,6 +48,7 @@ import commonSyncElements from 'kolibri-common/mixins/commonSyncElements'; import UsernameTextbox from 'kolibri-common/components/userAccounts/UsernameTextbox'; import PasswordTextbox from 'kolibri-common/components/userAccounts/PasswordTextbox'; + import { validateObject } from 'kolibri/utils/objectSpecs'; export default { name: 'FacilityAdminCredentialsForm', @@ -61,7 +62,20 @@ type: Object, required: true, validator(val) { - return val.name && val.id && val.baseurl; + return validateObject(val, { + name: { + type: String, + required: true, + }, + id: { + type: String, + required: true, + }, + baseurl: { + type: String, + required: true, + }, + }); }, }, facility: {