Posting custom user fields via the Ember side User model just ignores the fields

AI-generated summary

fzngagan is trying to add a custom setting to the user-preferences-profile outlet via a plugin, but the Ember side user model ignores the fields. This is because the user model’s save method only accepts fields already named in userFields, userOptionFields, etc. fzngagan proposes an API to send custom data to the server via the user model or seeks an explanation for this design choice, as their use case requires adding a setting to the preferences page and saving it with other preferences using the same Save Changes button.

Continuing the discussion from Adding Custom Fields via Plugin Outlet:

I just tried to add a custom setting to user-preferences-profile outlet.

I also reopened the controllers/preferences/profile.js to add my attribute to saveAttrNames array in order for my custom attributes to be passed to the save method of the ember side user model. But with some debugging, I found out that the user model’s save method simply drops the field if it isn’t already named in userFields, userOptionFields or so with one of those _.intersection calls.

I’m proposing an API to be able to send that data to the server via the user model itself or if its an intentional design choice, I am looking to understand the rationale behind it or whether there’s a different way to achieve this.

My use case is adding a setting to the preferences pages via a plugin and saving them with the other preferences using the same Save Changes button.

I’m aware of the fact that discourse-cakeday does so but the date_of_birth field is present in the userFields array which makes it work.

2 Likes