gocodebox / gocodebox/lifterlms

Cannot delete enrollments with non 'order_X' trigger from the enrollment metabox in the order edit screen.

Open
#951 3 comments 0 reactions 0 assignees View on GitHub
Type: Bug Type: Question
Dominant language
PHP
Stars
212
Forks
140
Avg merge
2d 14h
Merged PRs (30d)
19

Description

### Reproduction Steps

+ In admin open the order edit screen on an order which has a related enrollment to a course triggered by the order itself:
![Schermata 2019-09-27 alle 14 06 32](https://user-images.githubusercontent.com/7689242/65768036-10ea9680-e130-11e9-862c-b16812129acd.png)
+ Update the enrollment status to non active, e.g. Expired.
+ Now go edit the course related to the order and from the students table *re-enroll* the student:
![Schermata 2019-09-27 alle 14 34 29](https://user-images.githubusercontent.com/7689242/65769498-f87c7b00-e133-11e9-9ba6-40c356325ebf.png)
The enrollment's trigger is now changed, as it became the "privileged" user who re-enrolled the student.
+ Now click on the 'x' to unenroll (cancel) the user again, now that you can:
![Schermata 2019-09-27 alle 14 38 06](https://user-images.githubusercontent.com/7689242/65769696-7d679480-e134-11e9-950f-c8b7ff7e5f90.png)

+ Go back to the order screen, you'll see the Enrollment status and the trigger changed, also now you have the ability to delete the enrollment: the red button appears as the enrollment status is 'cancelled':
![Schermata 2019-09-27 alle 14 40 40](https://user-images.githubusercontent.com/7689242/65769958-43e35900-e135-11e9-815b-6011b2cc00a4.png)

+ Click on `Delete Enrollment` and wait for the page reload.

### Expected Behavior

+ I'd expect the Enrollment to be deleted, hence the meta box showing something of the sort:
![Schermata 2019-09-27 alle 14 53 26](https://user-images.githubusercontent.com/7689242/65770560-a0934380-e136-11e9-83e9-ec232767f728.png)

### Actual Behavior

+ The Enrollment is not deleted, and the meta box looks like this:

![Schermata 2019-09-27 alle 14 55 18](https://user-images.githubusercontent.com/7689242/65770692-dfc19480-e136-11e9-905c-7e64e05803ab.png)

The reason for this is that, in the order screen, we delete the [enrollment passing](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L147) `"order_{$order_id}"` as enrollment trigger, but the trigger has been changed, is not that one anymore.

I'm not sure this is completely intended as it was not so at the beginning (when the enrollments deletion was introduced but before the "button refactoring"). Also consider that when unenrolling, from the same meta box, [we pass 'any' as trigger](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L175). We pass ['any' as trigger](https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/class.llms.ajax.handler.php#L878) even when deleting the enrollment from the student's table mb in the course edit screen.

Of course keeping this different behavior for similar, but not equal, actions can make totally sense, and I actually think it does, but in this case we should not display the `Delete Enrollment` button in the order screen if the enrollment trigger is not the order itself.
Do you agree?

Please also note that under Order Notes a new entry has been added, saying that the student enrollment records have been deleted, while they're not.
The reason for this is that we don't expect a deletion failure and always log the success of that action:
https://github.com/gocodebox/lifterlms/blob/3.36.1/includes/admin/post-types/meta-boxes/class.llms.meta.box.order.enrollment.php#L149

### Error Messages / Logs
n/a

### System Information

LifterLMS 3.36.1 (but this issue is there since the introduction of the Delete Enrollment button in v3.33.0 I guess)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.