Skip to content

Conversation

@donny-wong
Copy link
Contributor

@donny-wong donny-wong commented Apr 2, 2025

Proposed Changes

Bulk uploading students to a course with an incorrect CSV column order results in incorrect students being created. This is one reason why this feature was implemented, which is, enabling the deletion of a single student from a course.

In order to allow the deletion of a student, they would need to not be associated to any groups, meaning there should not be any records in the memberships table for this student for the course they are being deleted from.

...

Screenshots of your changes (if applicable) For testing, I created a new course with a new student: new student creation I then associated this student to a group: associated student to a group I then tried to delete the student, but got the following error: error in deletion I then disassociated the student from the group and was able to delete the student: successful deletion of student
Associated documentation repository pull request (if applicable)
Instructions to remove a student: https://github.com/MarkUsProject/Wiki/pull/232

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) x
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@donny-wong donny-wong added this to the v2.6.2 milestone Apr 2, 2025
@donny-wong donny-wong changed the title Enable deletion of a student from a course Enable Deletion of a Student From a Course Apr 2, 2025
@donny-wong donny-wong changed the title Enable Deletion of a Student From a Course Enable deletion of a student from a course Apr 2, 2025
@donny-wong donny-wong linked an issue Apr 2, 2025 that may be closed by this pull request
@coveralls
Copy link
Collaborator

coveralls commented Apr 3, 2025

Pull Request Test Coverage Report for Build 14629824156

Details

  • 85 of 87 (97.7%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 91.92%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/javascript/Components/student_table.jsx 6 7 85.71%
app/javascript/Components/ta_table.jsx 0 1 0.0%
Totals Coverage Status
Change from base Build 14629035342: 0.01%
Covered Lines: 41711
Relevant Lines: 44693

💛 - Coveralls

@donny-wong donny-wong requested a review from david-yz-liu April 3, 2025 16:42
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@donny-wong excellent work! This PR is good, I just left a few stylistic comments.

Please also make an update to the MarkUs wiki.

@donny-wong donny-wong requested a review from david-yz-liu April 7, 2025 18:51
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@donny-wong make sure to link the Wiki PR to this one (there's a section for doing so in the PR description).

Also I realized that there should be one other restriction on student deletion: if there are associated grade_entry_students, and the grade_entry_student has an associated grade with a non-nil grade, then we should also prevent deletion. I expect the easiest way to implement this is to set the grade_entry_student association to dependent: :destroy and then in the grade entry student model, a check for non-nil grades.

@donny-wong donny-wong changed the title Enable deletion of a student from a course Enable removal of a student from a course Apr 8, 2025
@donny-wong
Copy link
Contributor Author

@donny-wong make sure to link the Wiki PR to this one (there's a section for doing so in the PR description).

Also I realized that there should be one other restriction on student deletion: if there are associated grade_entry_students, and the grade_entry_student has an associated grade with a non-nil grade, then we should also prevent deletion. I expect the easiest way to implement this is to set the grade_entry_student association to dependent: :destroy and then in the grade entry student model, a check for non-nil grades.

@david-yz-liu, I am not able to delete the student role, regardless of having dependent: :destroy, as it still raises the following error on the DB level:

ActiveRecord::NotNullViolation - PG::NotNullViolation: ERROR:  null value in column "role_id" of relation "grade_entry_students" violates not-null constraint
2025-04-10T15:08:09.662828042Z DETAIL:  Failing row contains (450, f, 2025-04-10 15:06:43.54127, 2025-04-10 15:06:43.54127, 21, null).:

I would like to get your thoughts if it would be ok to remove the DB foreign key constraint of role_id in the grade_entry_students table, which would then allow me to proceed with the deletion and use dependent: :destroy. I would create a migration for this foreign constraint removal, and add the foreign key constraint on the Model level. I'm not sure if there is another way to go about this? Thank you.

@david-yz-liu
Copy link
Collaborator

@donny-wong you don't need to remove the foreign key constraint. The point of doing the destroy is that the associated records (i.e., grade entry forms) should be deleted as well. If this is not happening there may be something else going on that you need to investigate and fix.

@donny-wong
Copy link
Contributor Author

@donny-wong you don't need to remove the foreign key constraint. The point of doing the destroy is that the associated records (i.e., grade entry forms) should be deleted as well. If this is not happening there may be something else going on that you need to investigate and fix.

@david-yz-liu , you are correct. I was putting the dependent: :destroy in the parent role instead of the student subclass, which was overwriting it. It all makes sense now. Thank you!

@donny-wong donny-wong force-pushed the enable_remove_student branch from 9555528 to f0d5516 Compare April 16, 2025 03:22
@donny-wong donny-wong requested a review from david-yz-liu April 16, 2025 03:54
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@donny-wong please add a test case for when there is a grade entry form (and GradeEntryStudent) but all of the grades are nil.

Also I'm not sure where in the code you are checking for non-nil grades before deletion?

@donny-wong
Copy link
Contributor Author

@donny-wong please add a test case for when there is a grade entry form (and GradeEntryStudent) but all of the grades are nil.

Also I'm not sure where in the code you are checking for non-nil grades before deletion?

@david-yz-liu I am checking for non-nil grades before deleting in app/models/grade_entry_student.rb line 27

@david-yz-liu
Copy link
Collaborator

@donny-wong ah yes I missed that (line 27), thanks for clarifying 👍

@donny-wong donny-wong force-pushed the enable_remove_student branch 2 times, most recently from 630c7c0 to 3d24ffc Compare April 23, 2025 21:55
@donny-wong donny-wong force-pushed the enable_remove_student branch from 3d24ffc to d29c060 Compare April 23, 2025 23:09
@donny-wong donny-wong requested a review from david-yz-liu April 23, 2025 23:35
@david-yz-liu david-yz-liu merged commit 63052b4 into MarkUsProject:master Apr 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow removing students

3 participants