Skip to content

Commit

Permalink
Modified validators in few files according to new ValidateObject
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-Punhani committed Jan 22, 2025
1 parent 0b44855 commit dbd7c9c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
46 changes: 45 additions & 1 deletion kolibri/plugins/learn/assets/src/views/ContentPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
},
});
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: {
Expand Down

0 comments on commit dbd7c9c

Please sign in to comment.