Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix teacher can see all students on the Students screen #7367

Merged
merged 11 commits into from Dec 14, 2023

Conversation

m1r0
Copy link
Member

@m1r0 m1r0 commented Dec 6, 2023

Resolves #6044

Proposed Changes

  • Add a hook to limit the students to ones that are part of the teacher's courses.

Testing Instructions

  1. Make sure you have a few student users.
  2. Make sure you have a user with the teacher role.
  3. Login with the teacher and go to Sense LMS -> Students.
  4. Make sure you see no students.
  5. Create a course and assign it to the teacher.
  6. Have a student take that course.
  7. Login with the teacher and go to Sense LMS -> Students.
  8. Make sure you see only the student that has taken the teacher's course.
  9. Repeat the steps above when HPPS is enabled.

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

@m1r0 m1r0 added the [Type] Bug label Dec 6, 2023
@m1r0 m1r0 added this to the 4.19.3 milestone Dec 6, 2023
@m1r0 m1r0 requested a review from a team December 6, 2023 19:23
@m1r0 m1r0 self-assigned this Dec 6, 2023
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Merging #7367 (6fbf3e3) into trunk (934fb41) will increase coverage by 0.11%.
Report is 1 commits behind head on trunk.
The diff coverage is 95.65%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #7367      +/-   ##
============================================
+ Coverage     50.77%   50.88%   +0.11%     
- Complexity    11145    11149       +4     
============================================
  Files           613      613              
  Lines         47042    47064      +22     
  Branches        404      404              
============================================
+ Hits          23884    23950      +66     
+ Misses        22831    22787      -44     
  Partials        327      327              
Files Coverage Δ
includes/class-sensei-temporary-user.php 85.71% <100.00%> (ø)
includes/class-sensei-teacher.php 50.00% <95.45%> (+6.73%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4a8c2b...6fbf3e3. Read the comment docs.

Imran92
Imran92 previously approved these changes Dec 7, 2023
Copy link
Contributor

@Imran92 Imran92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Works as expected

Create a probable relevant issue here https://github.com/Automattic/sensei-pro/issues/2501


return str_replace(
'WHERE 1=1',
'WHERE 1=1 AND u.ID IN (' . implode( ',', array_map( 'absint', $teacher_learner_ids ) ) . ')',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought about it I wanted to share just in case you feel the same, not too concerned about it, usually a site doesn't have thousands of course or lessons, but students can in many cases be in the thousands. Do you think it might be a problem in some cases as the query may become too big and exceed the size limit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I agree, this could be an issue in some cases. The default query size (max_allowed_packet) on newer MySQL versions is 16 MB, but on older ones, it is only 1 MB. I will check if this can be done with a join.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Could you please take another look? 🙏

I've also added HPPS support. 😄 cc @merkushin

@donnapep
Copy link
Collaborator

There's a small linter issue here after I merged from trunk to fix the jobs. 🙂

@m1r0
Copy link
Member Author

m1r0 commented Dec 11, 2023

Fixed, thanks. 🙂

Copy link
Contributor

@Imran92 Imran92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and woks as expected. I've left some minor comments. I've found only one issue during my testing that I think can be worth looking at.

In the same page (SenseiLMS -> Students), I removed a user from the course using the dropdown action on the top. But the the student was still showing up in the student list, with Enrolled Courses as N/A. If it's relevant, maybe we can think about fixing it here. If you think it's not relevant to this PR and should be handled in a separate one, feel free to do that too in which case we can merge this one.
Screenshot 2023-12-13 at 6 46 01 PM

includes/class-sensei-teacher.php Outdated Show resolved Hide resolved
includes/class-sensei-teacher.php Outdated Show resolved Hide resolved
includes/class-sensei-teacher.php Outdated Show resolved Hide resolved
@m1r0
Copy link
Member Author

m1r0 commented Dec 13, 2023

In the same page (SenseiLMS -> Students), I removed a user from the course using the dropdown action on the top. But the the student was still showing up in the student list, with Enrolled Courses as N/A.

Hm, this is an interesting problem. In the current state, it's showing all students who have progress in the course, it doesn't check the enrollment. The student is removed from the list only if you remove the user from the course and then reset the progress.

I guess it makes some sense to keep showing students-with-progress because they could have data on the grading screen. A potential fix could be to reset the progress when a user is removed from a course.

The funny part is that we use the same check-the-progress logic in reports to count the enrolled users (1, 2) and I assume we do it because there are multiple ways to enroll the user and it can get complicated.

For now, I will open a separate issue to illustrate the problem. 👍

Thanks for the awesome feedback, btw! 💯

@m1r0 m1r0 requested a review from Imran92 December 13, 2023 19:37
Imran92
Imran92 previously approved these changes Dec 14, 2023
Copy link
Contributor

@Imran92 Imran92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Left a minor comment about a comment, feel free to merge if you chose to address it. Approved anyway 😁

For now, I will open a separate issue to illustrate the problem. 👍

Awesome! Maybe adding a mention of this PR on that issue would help us get the reference.

Thanks for the awesome feedback, btw! 💯

Thank you! <3

includes/class-sensei-teacher.php Outdated Show resolved Hide resolved
@m1r0 m1r0 merged commit 3e4fb68 into trunk Dec 14, 2023
24 checks passed
@m1r0 m1r0 deleted the fix/teacher-can-see-all-students branch December 14, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Teacher can see all students in the 'Students' screen
3 participants