hexpm / hexpm

API server and website for Hex
https://hex.pm
1.07k stars 285 forks source link

Unable to Update Org Gravatar Email #1153

Closed aj-foster closed 7 months ago

aj-foster commented 2 years ago

Hello there 👋🏼

I'm currently unable to update my organization's Gravatar email in the profile settings. Attempting to change it (to support@codesandbox.io) returns a 400 error with a generic message.

Other fields on the profile seem to be fine. If it matters, I am attempting to use the same email address as the public_email for the profile.

Please let me know if there is any more information that would be helpful.

nskins commented 1 year ago

Hi @aj-foster. I tested this out in the development environment and did not receive any error. I tried using both the same email address as the public_email (as you suggest might be the issue) as well as an entirely different email address. Are you still experiencing an issue with production?

aj-foster commented 1 year ago

Hi @nskins, indeed I'm still getting the issue in production. If it would be helpful, I'd be happy to give you the exact inputs via direct message on some platform (I'm @ajf@hachyderm.io on the fediverse and AJ Foster on Elixir Slack). Very interesting that it worked in a development instance!

nskins commented 1 year ago

I took a second look at it and realized that I misunderstood you, @aj-foster. I had thought you were referring to the public_email of the user account being the same as the gravatar_email of the organization. Oops!

Now, looking only at the organization profile settings, I can confirm that I am seeing the issue you describe above on my development instance. When the user enters a value into the gravatar_email field and clicks "Save," the code attempts to add a new "Email" to the database (or if there was already a value in that field, it will instead try to update the database record). But there is a unique constraint on the "tuple" of (email, user_id). This throws an error since that "tuple" is already being used for the organization's public_email.

I found out that the system is totally fine with the user's public_email and gravatar_email being the same, so maybe that could be acceptable for organization email addresses too? I don't know enough about the technical decisions behind the architecture so I think, at this stage, we need to get some feedback from a maintainer who can steer us in the right direction.

ericmj commented 1 year ago

I found out that the system is totally fine with the user's public_email and gravatar_email being the same, so maybe that could be acceptable for organization email addresses too? I don't know enough about the technical decisions behind the architecture so I think, at this stage, we need to get some feedback from a maintainer who can steer us in the right direction.

Good observation, we should allow this for organizations as well.