This is an old revision of the document!
Employee roles deletion causing the creation form to open (Resolved)
Reported by: Khaled Tarabay on 2026-08-01T10:48:30+01:00
Assigned to: Claude
Resolved by: Claude on 2026-08-01T11:11:02+01:00
Priority: normal
Severity: minor
Reproducibility: always
Category: General
Description: right now when you try to delete a role that has an employee assigned this role it opens the create custom role form also outputs the error message, what should happen is that the form shouldn't open when you delete a role it should only output the error message
Resolution: FIXED.
WHAT: Deleting a role that still has an employee assigned showed the “can't delete” error AND popped the Create/Edit Role modal open. Now it only shows the error; the form stays closed.
WHERE: app/controllers/RoleController.php (destroy) + app/views/roles/index.php.
WHY: roles/index.php opens the modal whenever $errors is non-empty (the line: data-role-modal <?= $errors ? : 'hidden' ?>). That's correct for a failed CREATE/EDIT (the modal reopens so you can fix your input) — but destroy() was re-rendering the same page with errors['form'] on a blocked delete, and a delete has no form to correct, so the modal opened for no reason.
FIX: destroy() now, on a blocked delete (deleteCustom() returns false), calls flash_set('error', …) and redirects to /roles instead of re-rendering with $errors. The redirect lands on a fresh roles page whose $errors is empty, so the modal keeps its “hidden” attribute (stays closed) and the error shows as a normal flash toast. (A successful delete now also flashes “Role deleted.”)
VERIFIED: confirmed the modal-open trigger in the view (non-empty $errors → modal open) and that the fixed path carries no $errors to the response, so the modal is closed — with the error surfaced as a flash. php -l clean.
===== Activity / Notes =====
* 2026-08-01T11:10:58+01:00 - Claude: FIXED.
WHAT: Deleting a role that still has an employee assigned showed the “can't delete” error AND popped the Create/Edit Role modal open. Now it only shows the error; the form stays closed.
WHERE: app/controllers/RoleController.php (destroy) + app/views/roles/index.php.
WHY: roles/index.php opens the modal whenever $errors is non-empty (the line: data-role-modal <?= $errors ? : 'hidden' ?>). That's correct for a failed CREATE/EDIT (the modal reopens so you can fix your input) — but destroy() was re-rendering the same page with errors['form'] on a blocked delete, and a delete has no form to correct, so the modal opened for no reason.
FIX: destroy() now, on a blocked delete (deleteCustom() returns false), calls flash_set('error', …) and redirects to /roles instead of re-rendering with $errors. The redirect lands on a fresh roles page whose $errors is empty, so the modal keeps its “hidden” attribute (stays closed) and the error shows as a normal flash toast. (A successful delete now also flashes “Role deleted.”)
VERIFIED: confirmed the modal-open trigger in the view (non-empty $errors → modal open) and that the fixed path carries no $errors to the response, so the modal is closed — with the error surfaced as a flash. php -l clean.
Full History
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-08-01T10:48:30+01:00 | Khaled Tarabay | issue-new | New Issue |
| 2026-08-01T11:10:52+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-08-01T11:10:55+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-08-01T11:10:58+01:00 | Claude | note-added | Note Added: 0000116 |
| 2026-08-01T11:11:02+01:00 | Claude | Status | new ⇒ resolved |
Synced automatically from MantisBT issue #158.
