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

[1.x] fix: return empty object if selected mail driver is unavailable #4113

Conversation

DavideIadeluca
Copy link
Contributor

@DavideIadeluca DavideIadeluca commented Nov 15, 2024

Fixes #0000

The email page is broken in the following scenario:

  1. An extension is installed which adds a new email driver (e.g. https://github.com/glowingblue/flarum-ext-null-driver)
  2. The new email driver is selected in the email page
  3. The extension which added the new email driver is disabled/uninstalled
  4. The email page is broken with the following error:
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at MailPage.contentItems (MailPage.tsx:102:30)
    ...

Changes proposed in this pull request:
Return an empty object if the previously selected mail driver is unavailable.

Reviewers should focus on:
While no driver is selected in the frontend after this change and the page is working again, mail_driver in the DB still has the previously selected driver as the value. What we shouldn't do here is change this to another valid driver in core (such as log) because extensions might remove existing core drivers. Besides that, it will cause unexpected side effects.

The only thing that could be looked at is if this value should be reset to NULL. As I see it, resetting it to NULL would just be a cosmetic change, as Flarum doesn't error when trying to send emails using an inexistent driver (though perhaps it should?).

Screenshot

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)

@DavideIadeluca DavideIadeluca marked this pull request as ready for review November 15, 2024 10:51
@DavideIadeluca DavideIadeluca requested a review from a team as a code owner November 15, 2024 10:51
@imorland imorland added this to the 1.8.9 milestone Nov 18, 2024
@imorland imorland added type/cleanup javascript Pull requests that update Javascript code labels Nov 18, 2024
@imorland imorland merged commit 00329ea into flarum:1.x Nov 19, 2024
274 checks passed
@imorland imorland deleted the di/fix-mail-page-broken-after-uninstalling-selected-driver branch November 19, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code type/cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants