Closed peterkeijsers closed 1 year ago
Many thanks.
Merge done.
Hi @bobopinna
Thank you for merging my fix so soon!
Hi guys, I have a trouble similar to what you described after upgrading to v 2.3.9 (for a 2.3.4 version). I could not have anymore courses with both guest access and autoenrol access (the autoenrol has conditions on the user profile...). It seems users are now all welcomed as guest and nobody is autoenrolled automatically. I installed the version including the fix referred above but it doesn't change. What can I do to help identifying this issue ? (I'm unfortunately not a developer...)
I've discovered a bug. When using the guest login feature of Moodle. When you have visited the Moodle environment as a guest user. And then create an account and login. The autoenrolment skips the enrolment of the newly loggedin user because it thinks this user is a guest. This is due to the fact that in the "enrol_allowed" method the Moodle isguestuser() method is called without the current logged in $user argument given. Moodle then falls back to using the $USER constant which uses the $SESSION user object which is still the guest user at that time.
https://github.com/bobopinna/moodle-enrol_autoenrol/blob/66b52dc5f57a6236a160fd3c0ace747010add72c/lib.php#L183
This method should be passed the $user as argument.
See PR: https://github.com/bobopinna/moodle-enrol_autoenrol/pull/45