Steps to reproduce:
- (This is optional to make the error more obvious) Edit your config.php and add: $CFG->debug_developer_use_pretty_exceptions = true;
- Create a course with a lesson activity. Do NOT change any page or question; the error only occurs with an empty lesson.
- Enrol a non-editing teacher
- Login as the non-editing teacher and go inside the lesson
- Expected: the teacher can access the activity
- What happens: the page throws an error
The problem is with the "mod/lesson:edit" capability. When the lesson has no content, the "edit.php" requires this capability, but the non-editing teacher does not have it. However, the capability is not necessary if the lesson has some content.