|
101 | 101 | * {@code required: [...]} mandates them. Service-managed fields |
102 | 102 | * ({@code _id}, {@code password}, {@code roles}, {@code profile.name}, |
103 | 103 | * {@code profile.surname}, {@code emailVerificationToken}, |
104 | | - * {@code emailVerificationCreatedAt}) are never overwritten by the body. |
| 104 | + * {@code emailVerificationCreatedAt}) are never overwritten by the body, and the |
| 105 | + * body fields of the mapping table above ({@code firstName}, {@code lastName}, |
| 106 | + * {@code email}, {@code teamName}) are not carried over either — they already |
| 107 | + * reach the document, or the team, through that mapping. |
105 | 108 | * |
106 | 109 | * <p><strong>The document is validated as it is inserted, which is not its final shape.</strong> |
107 | 110 | * {@code createInitialTeam} runs after the insert and adds {@code teams} and {@code team} |
@@ -279,8 +282,8 @@ public void handle(JsonRequest req, JsonResponse res) throws Exception { |
279 | 282 | // remaining body fields are carried into the document as-is; the schema |
280 | 283 | // becomes the contract — additionalProperties:false rejects extensions, |
281 | 284 | // required:[...] mandates them. |
282 | | - // Service-managed fields (_id, password, roles, profile.name, profile.surname, |
283 | | - // emailVerificationToken, emailVerificationCreatedAt) are never overwritten. |
| 285 | + // Service-managed fields are never overwritten, and the mapped body fields |
| 286 | + // (firstName, lastName, email, teamName) are not carried over as extras. |
284 | 287 | if (db(req).hasSchema()) { |
285 | 288 | mergeExtraBodyProperties(body, userDoc); |
286 | 289 | } |
@@ -357,12 +360,24 @@ private static String extractString(JsonObject obj, String key) { |
357 | 360 | } |
358 | 361 |
|
359 | 362 | /** |
360 | | - * Top-level fields managed by the registration service. These are never |
361 | | - * overwritten by additional body properties. |
| 363 | + * Body keys that must not be carried into the user document as additional |
| 364 | + * properties. |
| 365 | + * |
| 366 | + * <p>Two groups: the document fields the service owns ({@code _id}, |
| 367 | + * {@code password}, {@code roles}, {@code profile}, |
| 368 | + * {@code emailVerificationToken}, {@code emailVerificationCreatedAt}), and the |
| 369 | + * body fields the mapping table sends somewhere else ({@code firstName} and |
| 370 | + * {@code lastName} to {@code profile.name}/{@code profile.surname}, |
| 371 | + * {@code email} to {@code _id}, {@code teamName} to the team document). Without |
| 372 | + * the second group the stored document would duplicate its own mapped fields |
| 373 | + * and carry the team name, and a schema with {@code additionalProperties: false} |
| 374 | + * would reject every registration over properties the client never sent as |
| 375 | + * extras. |
362 | 376 | */ |
363 | 377 | private static final java.util.Set<String> SERVICE_MANAGED_FIELDS = java.util.Set.of( |
364 | 378 | "_id", "password", "roles", "profile", |
365 | | - "emailVerificationToken", "emailVerificationCreatedAt"); |
| 379 | + "emailVerificationToken", "emailVerificationCreatedAt", |
| 380 | + "firstName", "lastName", "email", "teamName"); |
366 | 381 |
|
367 | 382 | /** |
368 | 383 | * Fields inside {@code profile} managed by the registration service. |
|
0 commit comments