flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.39k stars 834 forks source link

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

Closed DavideIadeluca closed 1 week ago

DavideIadeluca commented 1 week ago

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

Confirmed

Required changes: