oppia: Implement missing domain objects with full `validate()` function.

Please note that for any model picked up, first describe in a comment what will be the domain object properties and what validation checks will be put in place and only after that is approved, the model can be assigned to you. Please avoid adding any code here to explain the checks. It is difficult to review that. So, stick to describing the checks as you would do in a design doc.

Additionally, please note that you will need to ensure that, after your refactor, none of the instances of the corresponding storage model should be used in the rest of the codebase, except for the get/save methods that convert a datastore model to a domain object and vice versa. All other usages besides those two methods should be of the domain object. (See ExplorationModel and the Exploration domain object for an example.)


Implement missing domain objects for the following storage models with full validate() function:

  • AnswerSubmittedEventLogEntryModel
  • BlogPostReadEventLogEntryModel
  • BlogPostViewedEventLogEntryModel
  • BlogPostExitedEventLogEntryModel
  • BulkEmailModel
  • CollectionCommitLogEntryModel
  • CollectionProgressModel
  • CollectionRightsModel
  • CollectionRightsSnapshotMetadataModel
  • CollectionSnapshotContentModel
  • CollectionSnapshotMetadataModel
  • CompleteExplorationEventLogEntryModel
  • CsrfSecretModel
  • DeletedUserModel
  • DeletedUsernameModel
  • ExplorationActualStartEventLogEntryModel
  • ExplorationAnnotationsModel
  • ExplorationContextModel
  • ExplorationIssuesModel
  • ExplorationRecommendationsModel: @aasmaa11
  • ExplorationRightsModel: @Somnath-Mishra
  • ExplorationRightsSnapshotMetadataModel
  • ExplorationSnapshotMetadataModel
  • ExplorationStatsTaskEntryModel
  • ExplorationUserDataModel
  • ExplorationVoiceArtistsLinkModel
  • FirebaseSeedModel
  • JobModel
  • LearnerGoalsModel
  • LearnerGroupsUserModel
  • LearnerPlaylistModel
  • LeaveForRefresherExplorationEventLogEntryModel
  • MaybeLeaveExplorationEventLogEntryModel
  • PinnedOpportunityModel
  • PlatformParameterSnapshotMetadataModel
  • PlaythroughModel
  • PseudonymizedUserModel
  • QuestionCommitLogEntryModel
  • QuestionSnapshotMetadataModel
  • RateExplorationEventLogEntryModel
  • RoleQueryAuditModel
  • SentEmailModel
  • SkillCommitLogEntryModel
  • SkillSnapshotMetadataModel
  • SolutionHitEventLogEntryModel
  • StartExplorationEventLogEntryModel
  • StateCompleteEventLogEntryModel
  • StateCounterModel
  • StateHitEventLogEntryModel
  • StoryCommitLogEntryModel
  • StoryProgressModel
  • StorySnapshotMetadataModel
  • SubtopicPageCommitLogEntryModel
  • SubtopicPageSnapshotMetadataModel
  • TopicCommitLogEntryModel
  • TopicRightsSnapshotMetadataModel
  • TopicSimilaritiesModel
  • TopicSnapshotMetadataModel
  • TranslationCoordinatorsModel
  • UnsentFeedbackEmailModel
  • UserBulkEmailsModel
  • UserEmailPreferencesModel
  • UserIdByFirebaseAuthIdModel
  • UserIdentifiersModel
  • UsernameChangeAuditModel
  • UserRecentChangesBatchModel
  • UserStatsModel
  • UserSubscribersModel
  • UserSubscriptionsModel @FCancella
  • VoiceArtistMetadataModel
  • VoiceoverAutogenerationPolicyModel: @aasmaa11

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 94 (49 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @Ashu463, I will take a look and add comments on the doc in a couple hours.

Hi @ankita240796 I think your approach for having “libraries with validation logic for email and html” is totally fine, even once I thought the same of unify email and html validations for whole codebase at one single place which will be helpful for upcoming devs. I can definitely open up a doc and suggest to discuss with other maintainers too once (@seanlip) over this approach.

And yeah you were right with validate_rte_tags and validate_tabs_and_collapsible_rte_tags, we have to look closely which one should we choose based upon current need of html_body with respect to emails. Yep clean is called before sending it to save(at least I could see at one place at state_domain), and if we assume that clean is called before saving data to db then its totally fine to ignore it.

Sorry for the delay, was busy with ExplorationVoiceArtistsLinkModel, will open up a PR soon. Pls let me know my upcoming tasks, which I could currently see as :

  • Writing a well detailed doc for html_body and email validations.
  • Searching which validate method should we go through to validate tags within html_body.

Thanks.

Thanks @Ashu463, all that sounds great, feel free to let me know if you need any help. You do not have to worry about polishing the doc, just having a list of what checks exist in the codebase is good enough to determine the next steps.

@ankita240796 I got an observation which helps us to choose whether strict or not. I’d gone through all domain objects exists in codebase, there were only five models in which strict parameter is made; and those are: BlogPost, Classroom, Collection, Exploration, Topic. In these models, strict validation is used whenever any of these is published or is going to be published. Here are the proofs:

Image

Image

It was my mistake for suggesting usage of strict param in ExplorationVoiceArtistsLinkModel as it is not published somewhere, pls excuse me for this mistake I’m also peeling off codebase day by day.

No worries at all, I found it only when I went through your comment and started digging deeper. I don’t expect you to know the entire codebase but just develop to skill to go through it and find required learnings which you are doing well!

So validation for this model is made on: whether the incoming data followed dict structure as expected or not as explained in earlier cmnts.

Thanks.

I think that makes sense. I have assigned this model to you, thanks!

Thanks @Esheshwari, all that makes sense. Assigned the models to you!

Thank you so much @ankita240796 This opportunity means a lot to me. I’ll begin making the changes asap and will update you once I make progress.

All, just a note: @ankita240796 is away this week. She will be back next week and I think she will look at your comments then.

I don’t currently have the bandwidth to go through all the suggestions in detail, but here are a few quick observations in case you want to edit your comments before she gets back:

  • I noticed that a part of this issue description was missing, so I’ve added it. Please see the 2nd paragraph of the original comment in this issue (“Additionally, please note that you will need to ensure that…”).
  • When validating strings, consider validating the charset as well.
  • When validating exp IDs, validate the charset and that they’re nonempty.
  • Some properties within a domain object are logically connected to each other, and one can’t be set without the other. You should handle those cases as well. An example of an approach that isn’t correct in this regard is @Vanshitaaa20’s.
  • Emails, language codes and HTML need more validation than “it has @ in it” or “it has an HTML tag in it”. Think about what exactly what makes an email or HTML string valid. Your validity check should be such that anything that passes that check is valid, and anything that doesn’t pass it is not valid.
  • It is not helpful for your validity check description to include the word “valid”, because it just results in the question of “what does valid mean in this context”.