(core) When reporting email in log metadata, use normalized email.

Summary:
There has been inconsistency in using display email vs normalized email, which
ends up creating some duplication in downstream analyses (e.g. the same user
showing up twice with different capitalization).

1. Add UserProfile.loginEmail field with normalized email to prefer, when set, over the inconsistently used UserProfile.email.
2. In one place where it's not available, normalize the display email manually.
3. Clean up some code in Client.ts.

Unrelated tweak to API Console to be clear when a URL parameter wasn't found (rather than show whatever happens to be the first value).

Several test robustness improvements:
- Misplaced parenthesis in gristWebDriverUtils has been causing optTimeout argument to be ignored in tests, and treated always as indefinite.
- Attempt to fix SortMenu test by ignoring (retrying with logging) errors in waitForServer, which include "script timeout" errors that come from a non-configurable selenium or chromedriver timeout.
- Attempt to improve onNewTab() helper, which plays a role in failing Billing tests.

Test Plan: Tested manually the capitalization of logged emails. Counting on existing tests to catch issues.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4188
This commit is contained in:
Dmitry S
2024-02-14 11:01:02 -05:00
parent cd339ce7cb
commit fc44a60edf
7 changed files with 58 additions and 50 deletions

View File

@@ -514,9 +514,14 @@ export class HomeDBManager extends EventEmitter {
if (!user.logins?.[0]?.displayEmail) {
throw new ApiError("unable to find mandatory user email", 400);
}
const displayEmail = user.logins[0].displayEmail;
const loginEmail = user.loginEmail;
const result: FullUser = {
id: user.id,
email: user.logins[0].displayEmail,
email: displayEmail,
// Only include loginEmail when it's different, to avoid overhead when FullUser is sent
// around, and also to avoid updating too many tests.
loginEmail: loginEmail !== displayEmail ? loginEmail : undefined,
name: user.name,
picture: user.picture,
ref: user.ref,
@@ -2391,6 +2396,7 @@ export class HomeDBManager extends EventEmitter {
const access = userRoleMap[u.id];
return {
...this.makeFullUser(u),
loginEmail: undefined, // Not part of PermissionData.
access,
isMember: access !== 'guests',
};
@@ -2447,6 +2453,7 @@ export class HomeDBManager extends EventEmitter {
const orgAccess = orgMapWithMembership[u.id] || null;
return {
...this.makeFullUser(u),
loginEmail: undefined, // Not part of PermissionData.
access: wsMap[u.id] || null,
parentAccess: roles.getEffectiveRole(orgMap[u.id] || null),
isMember: orgAccess && orgAccess !== 'guests',
@@ -2509,6 +2516,7 @@ export class HomeDBManager extends EventEmitter {
const orgAccess = orgMapWithMembership[u.id] || null;
return {
...this.makeFullUser(u),
loginEmail: undefined, // Not part of PermissionData.
access: docMap[u.id] || null,
parentAccess: roles.getEffectiveRole(
roles.getStrongestRole(wsMap[u.id] || null, inheritFromOrg)