From 12082f5547f8f8febcaabe424b5873b453554f99 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Sat, 31 Jan 2026 13:35:41 +0100 Subject: [PATCH] fix(api): return all privacy values so client can update them (#65620) --- api/src/routes/public/user.test.ts | 10 ++++++++- .../schemas/settings/update-my-profile-ui.ts | 16 +++----------- api/src/schemas/types.ts | 22 +++++++++---------- api/src/schemas/user/get-session-user.ts | 2 +- api/src/utils/normalize.test.ts | 22 +++++++++---------- api/src/utils/normalize.ts | 4 ++-- 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/api/src/routes/public/user.test.ts b/api/src/routes/public/user.test.ts index 1366b9cdc56..e5c7cdc6cc5 100644 --- a/api/src/routes/public/user.test.ts +++ b/api/src/routes/public/user.test.ts @@ -258,7 +258,15 @@ describe('userRoutes', () => { const lockedUserProfileUI = { isLocked: true, showAbout: true, - showPortfolio: false + showCerts: true, + showDonation: true, + showExperience: true, + showHeatMap: true, + showLocation: true, + showName: true, + showPoints: true, + showPortfolio: true, + showTimeLine: true }; const unlockedUserProfileUI = { isLocked: false, diff --git a/api/src/schemas/settings/update-my-profile-ui.ts b/api/src/schemas/settings/update-my-profile-ui.ts index 05e0deebeca..9c6f0116348 100644 --- a/api/src/schemas/settings/update-my-profile-ui.ts +++ b/api/src/schemas/settings/update-my-profile-ui.ts @@ -1,20 +1,10 @@ import { Type } from '@fastify/type-provider-typebox'; +import { profileUI } from '../types.js'; + export const updateMyProfileUI = { body: Type.Object({ - profileUI: Type.Object({ - isLocked: Type.Boolean(), - showAbout: Type.Boolean(), - showCerts: Type.Boolean(), - showDonation: Type.Boolean(), - showHeatMap: Type.Boolean(), - showLocation: Type.Boolean(), - showName: Type.Boolean(), - showPoints: Type.Boolean(), - showPortfolio: Type.Boolean(), - showExperience: Type.Boolean(), - showTimeLine: Type.Boolean() - }) + profileUI }), response: { 200: Type.Object({ diff --git a/api/src/schemas/types.ts b/api/src/schemas/types.ts index 1acb3833ed0..8b03922c51b 100644 --- a/api/src/schemas/types.ts +++ b/api/src/schemas/types.ts @@ -70,17 +70,17 @@ export const surveyTitles = Type.Union([ ]); export const profileUI = Type.Object({ - isLocked: Type.Optional(Type.Boolean()), - showAbout: Type.Optional(Type.Boolean()), - showCerts: Type.Optional(Type.Boolean()), - showDonation: Type.Optional(Type.Boolean()), - showHeatMap: Type.Optional(Type.Boolean()), - showLocation: Type.Optional(Type.Boolean()), - showName: Type.Optional(Type.Boolean()), - showPoints: Type.Optional(Type.Boolean()), - showPortfolio: Type.Optional(Type.Boolean()), - showTimeLine: Type.Optional(Type.Boolean()), - showExperience: Type.Optional(Type.Boolean()) + isLocked: Type.Boolean(), + showAbout: Type.Boolean(), + showCerts: Type.Boolean(), + showDonation: Type.Boolean(), + showHeatMap: Type.Boolean(), + showLocation: Type.Boolean(), + showName: Type.Boolean(), + showPoints: Type.Boolean(), + showPortfolio: Type.Boolean(), + showTimeLine: Type.Boolean(), + showExperience: Type.Boolean() }); export const experience = Type.Object({ diff --git a/api/src/schemas/user/get-session-user.ts b/api/src/schemas/user/get-session-user.ts index bca81419637..0bfadc0d2fe 100644 --- a/api/src/schemas/user/get-session-user.ts +++ b/api/src/schemas/user/get-session-user.ts @@ -124,7 +124,7 @@ export const getSessionUser = { }) ), experience: Type.Optional(Type.Array(experience)), - profileUI: Type.Optional(profileUI), + profileUI, sendQuincyEmail: Type.Union([Type.Null(), Type.Boolean()]), // // Tri-state: null (likely new user), true (subscribed), false (unsubscribed) theme: Type.String(), twitter: Type.Optional(Type.String()), diff --git a/api/src/utils/normalize.test.ts b/api/src/utils/normalize.test.ts index 4ae8121303c..d2331003dc9 100644 --- a/api/src/utils/normalize.test.ts +++ b/api/src/utils/normalize.test.ts @@ -78,7 +78,7 @@ describe('normalize', () => { expect(normalizeProfileUI(input)).toEqual(defaultProfileUI); }); - test('should convert all "null" values to "undefined"', () => { + test('should convert all "null" values to "false"', () => { const input = { isLocked: null, showAbout: false, @@ -93,17 +93,17 @@ describe('normalize', () => { showExperience: null }; expect(normalizeProfileUI(input)).toEqual({ - isLocked: undefined, + isLocked: false, showAbout: false, - showCerts: undefined, - showDonation: undefined, - showHeatMap: undefined, - showLocation: undefined, - showName: undefined, - showPoints: undefined, - showPortfolio: undefined, - showTimeLine: undefined, - showExperience: undefined + showCerts: false, + showDonation: false, + showHeatMap: false, + showLocation: false, + showName: false, + showPoints: false, + showPortfolio: false, + showTimeLine: false, + showExperience: false }); }); }); diff --git a/api/src/utils/normalize.ts b/api/src/utils/normalize.ts index b9c5e932f66..8f9dc14fa36 100644 --- a/api/src/utils/normalize.ts +++ b/api/src/utils/normalize.ts @@ -124,9 +124,9 @@ export const normalizeChallengeType = ( */ export const normalizeProfileUI = ( maybeProfileUI: ProfileUI | null -): NoNullProperties => { +): DefaultToFalse => { return maybeProfileUI - ? removeNulls(maybeProfileUI) + ? normalizeFlags(maybeProfileUI) : { isLocked: true, showAbout: false,