diff --git a/src/app/UserItemsPage.js b/src/app/UserItemsPage.js index 9f203c4..e0dc9d1 100644 --- a/src/app/UserItemsPage.js +++ b/src/app/UserItemsPage.js @@ -555,6 +555,24 @@ function UserSupportMenu({ children, user }) { const { supportSecret } = useSupport(); const toast = useToast(); + const { loading, error, data } = useQuery( + gql` + query UserSupportMenu($userId: ID!, $supportSecret: String!) { + user(id: $userId) { + id + emailForSupportUsers(supportSecret: $supportSecret) + } + } + `, + { + variables: { + userId: user.id, + supportSecret, + onError: (e) => console.error(e), + }, + } + ); + const [sendEditUsernameMutation] = useMutation( gql` mutation UserSupportMenuRename( @@ -615,6 +633,23 @@ function UserSupportMenu({ children, user }) { Edit username + + Send email + {error && <> (Error: {error.message})} + diff --git a/src/server/types/MutationsForSupport.js b/src/server/types/MutationsForSupport.js index dd1c5ee..f219d37 100644 --- a/src/server/types/MutationsForSupport.js +++ b/src/server/types/MutationsForSupport.js @@ -878,4 +878,4 @@ function assertSupportSecretOrThrow(supportSecret) { } } -module.exports = { typeDefs, resolvers }; +module.exports = { typeDefs, resolvers, assertSupportSecretOrThrow }; diff --git a/src/server/types/User.js b/src/server/types/User.js index a928270..9d8507a 100644 --- a/src/server/types/User.js +++ b/src/server/types/User.js @@ -1,5 +1,7 @@ import { gql } from "apollo-server"; +import { assertSupportSecretOrThrow } from "./MutationsForSupport"; + const typeDefs = gql` type User { id: ID! @@ -23,6 +25,9 @@ const typeDefs = gql` # This user's outfits. Returns an empty list if the current user is not # authorized to see them. outfits: [Outfit!]! + + # This user's email address. Requires the correct supportSecret to view. + emailForSupportUsers(supportSecret: String!): String! } extend type Query { @@ -218,7 +223,6 @@ const resolvers = { isDefaultList: true, userId: id, ownsOrWantsItems: "WANTS", - isDefaultList: true, items: defaultListWantedHangers.map((h) => ({ id: h.itemId })), }); } @@ -239,6 +243,23 @@ const resolvers = { const outfits = await userOutfitsLoader.load(id); return outfits.map((outfit) => ({ id: outfit.id })); }, + + emailForSupportUsers: async ({ id }, { supportSecret }, { db }) => { + assertSupportSecretOrThrow(supportSecret); + + const [rows] = await db.query( + ` + SELECT email FROM openneo_id.users + WHERE id = (SELECT remote_id FROM users WHERE id = ?) + `, + [id] + ); + if (rows.length === 0) { + throw new Error(`could not find user ${id} in openneo_id database`); + } + + return rows[0].email; + }, }, Query: {