Skip to content

fix: localize usernames#242

Merged
JFronny merged 8 commits intomasterfrom
feature/guest-username-localize
Mar 7, 2025
Merged

fix: localize usernames#242
JFronny merged 8 commits intomasterfrom
feature/guest-username-localize

Conversation

@antoniaammon
Copy link
Copy Markdown
Contributor

@antoniaammon antoniaammon commented Mar 4, 2025

ich dachte dass das so am einfachsten ist oder ist das hässlich?

closes #208

@JFronny
Copy link
Copy Markdown
Collaborator

JFronny commented Mar 4, 2025

Diese Logik ist auch für die Nutzerliste relevant und ich finde, dass sie in JteContext rausgefactort werden sollte.

@JFronny JFronny moved this to In Review in Solidarische Raumnutzung Mar 4, 2025
@antoniaammon antoniaammon changed the title fix: localize guest in layout.jte fix: localize usernames Mar 5, 2025
@antoniaammon
Copy link
Copy Markdown
Contributor Author

Hab jetzt was in JTE context gemacht, ist das so okay? @JFronny

Copy link
Copy Markdown
Collaborator

@JFronny JFronny left a comment

Choose a reason for hiding this comment

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

Not quite happy with the implementation here, but the basic idea is definitely good

? context.lookup("user.visitor")
: layout.getLogin().name())}</label>
<label>
${context.localize("layout.welcome", context.getUserName(layout.getLogin()))}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will cause a NPE if the user is not logged in.
Please handle the case of user == null in getUserName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aber das ist doch die Variante, die das LoginStateModel und nicht den User nutzt, und das ist immer vorhanden oder?

return new PageSpec(lookup(key), "SOLI");
}

public String getUserName(LoginStateModel login) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be named format and return Content

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wie mach ich dann das login.name() zu Content?

}
}

public String getUserName(User user) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be named format and return Content

}

public String getUserName(LoginStateModel login) {
switch (login.kind()) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use a switch expression, not a statement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wo ist der Unterschied?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Die curly braces sind unnötig und du kannst return rausziehen. Ich fixe es.

}

public String getUserName(User user) {
if (Objects.equals(user.getUsername(), "Guest")) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be based on the implementation of this check in UserService, not an ad-hoc check using the username. The service can be injected indirectly through the constructor.
Also, admin users should be handled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wird gemacht!

@JFronny JFronny merged commit ce5ddaa into master Mar 7, 2025
4 checks passed
@JFronny JFronny deleted the feature/guest-username-localize branch March 7, 2025 19:49
@github-project-automation github-project-automation bot moved this from In Review to Done in Solidarische Raumnutzung Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Language consistency

2 participants