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

[server, dashboard] Refactor User.getPrimaryEmail to return "string | undefined" instead of throwing an error #9446

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

geropl
Copy link
Member

@geropl geropl commented Apr 21, 2022

Description

Related Issue(s)

Fixes #8359

How to test

  • signup with two users: 1st becomes admin, 2 is our test account
  • login with 2, and remove all git integrations. Verify in the DB that there are no more indentities for this account (if there still are, just delete them from the DB
  • login with 1, and open the user admin page for 2
  • verify that you see more than a blank page

Release Notes

fixed a bug around email address rendering

Documentation

@geropl geropl requested a review from a team April 21, 2022 07:25
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Apr 21, 2022
@geropl
Copy link
Member Author

geropl commented Apr 21, 2022

/werft run

👍 started the job as gitpod-build-gpl-8359-primary.2

Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like in various places, we treat an empty or undefined email differently. Sometimes we use empty string, sometimes we use "---", sometimes we keep it as undefined. Is it at all possible to choose one? In practice, we could encode that logic inside getPrimaryEmail() and not have to cast or convert in so many places.

@easyCZ easyCZ self-assigned this Apr 21, 2022
@geropl
Copy link
Member Author

geropl commented Apr 21, 2022

Sometimes we use empty string, sometimes we use "---", sometimes we keep it as undefined. Is it at all possible to choose one?

I think in general it is not possible, because depending on your context, this has different meaning. getPrimaryEmail is also not about rendering, but status retrieval.

Wrt to the different options to render in the dashboard("---" vs ""): I basically kept the previous decisions in place, scoping this PR solely on the reliability parts to never break the renderning.
If we want to align this I'm all open for a follow-up.

Copy link
Member

@easyCZ easyCZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd personally split this across 2 PRs - one for server and one for dashboard to keep the changes independent and better communicate nature of distributed systems but this is only a suggestion.

@@ -50,7 +50,7 @@ export default function UserDetail(p: { user: User }) {
}, [p.user]);

const email = User.getPrimaryEmail(p.user);
const emailDomain = email.split("@")[email.split("@").length - 1];
const emailDomain = email ? email.split("@")[email.split("@").length - 1] : undefined;
Copy link
Member

@easyCZ easyCZ Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Nothing to fix here, just a comment. This is in general quite fishy, but oh well. In practice, it's extremely hard to parse email addresses well as the spec is so very broad, the best we can often do is check the email is valid by sending an email.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely agree in theory. Currently the only assumptions we make is that a) it has a '@' and b) non-empty domain part.
I know that both are not guaranteed by the spec, but held in practice well enough.
And then there is the other point that we should not be doing this randomly in the frontend, but should try to keep in a central place (or library).... 👍

@roboquat roboquat merged commit c26d1dc into main Apr 21, 2022
@roboquat roboquat deleted the gpl/8359-primary branch April 21, 2022 07:45
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note size/M team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request getWorkspace failed with message: No identity with primary email for user: [...]!
3 participants