Skip to content

llms_is_user_enrolled always return false for non existing or unlogged users#2315

Merged
ideadude merged 2 commits into
gocodebox:devfrom
eri-trabiccolo:check_user_existence_on_checking_enrollment
Mar 1, 2023
Merged

llms_is_user_enrolled always return false for non existing or unlogged users#2315
ideadude merged 2 commits into
gocodebox:devfrom
eri-trabiccolo:check_user_existence_on_checking_enrollment

Conversation

@eri-trabiccolo

@eri-trabiccolo eri-trabiccolo commented Dec 30, 2022

Copy link
Copy Markdown
Contributor

Description

While looking at https://github.com/gocodebox/private-issues/issues/63
I realized that we "try" to query the DB looking for enrollments even for not logged in users, and generally for non existing users (e.g. deleted users). In this PR I just return immediately false when checking for enrollments of non existing users when using llms_is_user_enrolled().
This is technically a breaking change (so will ideally push the next LifterLMS version to 8.0), as we're changing the default behavior of a public function although we internally always used that assuming that the user was existing: with that function you could theoretically query the enrollment status of a student in a course even if the student was deleted.
Also consider that in the future we want to delete the enrollment related data of a user upon its removal (see #940 bullet Delete data from lifterlms_user_postmeta table). Maybe we want take the occasion and implement a fix for #940 so to release a new major version including this PR?

This PR will also basically fix https://github.com/gocodebox/private-issues/issues/63

Also this PR has some perfomance impact (improvements) on not logged in users visiting e.g. courses or membership catalogs: for each course/membership in the current catalog page we check whether or not the current user (user with ID 0 for non logged in users) is enrolled in the course/membership performing a custom and not simple DB query (although on an index of the table).

How has this been tested?

manually and existing unit tests

Types of changes

Breaking change (fix or feature that would cause existing functionality to not work as expected) -->

Checklist:

  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

@eri-trabiccolo eri-trabiccolo requested a review from a team December 30, 2022 18:05
@eri-trabiccolo eri-trabiccolo self-assigned this Dec 30, 2022
@ideadude ideadude added this to the 7.1 milestone Feb 20, 2023
@eri-trabiccolo eri-trabiccolo force-pushed the check_user_existence_on_checking_enrollment branch from 2081d37 to 05baf66 Compare February 28, 2023 15:18
@eri-trabiccolo

Copy link
Copy Markdown
Contributor Author

@ideadude
changelog entries done and rebased to the current dev: ready to be merged.

@ideadude ideadude merged commit abea035 into gocodebox:dev Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants