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 Failing Course Deletion if Approved/Rejected Enrol Requests Exist #7642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bivanalhar
Copy link
Contributor

@bivanalhar bivanalhar commented Nov 18, 2024

Background

Previously, having at least one Approved/Rejected enrol requests inside the course will give an error if one wants to delete the course

Root Causes

Based on this PR #4212, we wants to keep track on the enrol requests that are approved/rejected, and hence we disallow the requester to retract their enrol requests if theirs have been approved / rejected (not pending) by adding validation rules before destroying the enrol requests. However, this same validation will also takes place when we delete course, since enrol_request is the child of course and hence enrol_request will be subsequently deleted due to cascading.

Approach

We moved the validation for destroy towards enrol_request_controller, since we noticed that the validation will only be accessed should we send the request through controller and not through parent deletion

@@ -24,6 +24,7 @@ def create
# Allow users to withdraw their requests to register for a course that are pending
# approval/rejection.
def destroy
@enrol_request.is_validation_for_destroy_required = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Since course deletion will bypass controller and go straight to model, why not move the workflow_state == 'pending' check to the controller instead?

Then we can save on an additional is_validation_for_destroy_required attribute which is only set in the controller destroy anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed, we decided to move the validation logic for deletion to the controller instead of model, since the validation will only be called while destroying object through controller

@bivanalhar bivanalhar force-pushed the bivan/course-delete-enrol-request-fix branch from a60bc37 to 4a68336 Compare November 18, 2024 09:07
@bivanalhar bivanalhar force-pushed the bivan/course-delete-enrol-request-fix branch from 4a68336 to 4395490 Compare November 21, 2024 08:53
Copy link
Contributor

@cysjonathan cysjonathan left a comment

Choose a reason for hiding this comment

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

LGTM

@cysjonathan cysjonathan enabled auto-merge (rebase) November 21, 2024 08:55
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.

2 participants