FusionAuth / fusionauth-issues

FusionAuth issue submission project
https://fusionauth.io
91 stars 12 forks source link

API: Unable to patch a theme template when field are missing after an upgrade #1406

Open soullivaneuh opened 3 years ago

soullivaneuh commented 3 years ago

Unable to patch a theme template when field are missing after an upgrade

Description

Some new release provide more templates to provide on the theme.

I have a setup script that will make a POST /api/theme/${theme_id} with the sourceThemeId body parameter in order to have a copy of it.

Then, I make a PATCH /api/theme/${theme_id} with only the templates to change as body parameters.

However, this script does not work after an upgrade providing new template, because they are required even on the PATCH method.

We can indeed see them on the admin panel:

image

Fix to provide

To me, a PATCH method should not required field we do not provide, this is how it works.

However, if you need to keep this complete validation for some reasons, we may add the sourceThemeId on this method, telling to fill automatically the missing field with the default template.

:warning: For the second option, the controller MUST changes only the empty templates, not the others.

Thanks for reading

mooreds commented 3 years ago

Hmmm. I'm not sure I understand the issue. Are these the steps?

Is that correct?

soullivaneuh commented 3 years ago

Not really:

  1. At the first installation, the script create a new theme called "Company" based from the default one (sourceThemeId)
  2. At any new deployment, the script call the PATCH resource to update only the templates we override.
  3. If a new FusionAuth release, containing new templates, is deployed, the PATCH resource will fail because of the missing new templates.

But we don't override those templates, we should not need to supply them on a PATCH method.

Is that better? :slightly_smiling_face:

mooreds commented 3 years ago

Is this related to https://github.com/FusionAuth/fusionauth-issues/issues/441 ? templates is an array, so we take what is presented (your list of old templates) and replace the entire array. But that doesn't contain the new templates, so validation fails.