Skip to content

Commit

Permalink
feat: prevent sending email after removing sso
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoferrall committed Dec 16, 2024
1 parent a14a7ab commit f776961
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
28 changes: 28 additions & 0 deletions packages/client/modules/demo/ClientGraphQLServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ const makeReflectionGroupThread = () => ({
}
})

const BOT_GROUP_TITLES: Record<string, string> = {
botGroup1: 'Empower Junior Staff',
botGroup2: 'Documentation Practices',
botGroup4: 'Chat Communication Issues',
botGroup5: 'Unproductive Discussions',
botGroup6: 'Meeting Overload'
}

class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
atmosphere: LocalAtmosphere
db: RetroDemoDB
Expand Down Expand Up @@ -1579,6 +1587,26 @@ class ClientGraphQLServer extends (EventEmitter as GQLDemoEmitter) {
this.emit(SubscriptionChannel.MEETING, data)
}
return {updateCommentContent: data}
},
async updateGroupTitle(reflectionGroup: DemoReflectionGroup, reflections: DemoReflection[]) {
// Use hardcoded title for bot groups, otherwise use first reflection's content
const title =
BOT_GROUP_TITLES[reflectionGroup.id] ??
reflections[0]?.plaintextContent?.slice(0, 20) ??
'New Group'

reflectionGroup.smartTitle = title
if (!reflectionGroup.titleIsUserDefined) {
reflectionGroup.title = title
}

const data = {
__typename: 'UpdateReflectionGroupTitlePayload',
meetingId: RetroDemo.MEETING_ID,
reflectionGroupId: reflectionGroup.id,
title
}
this.emit(SubscriptionChannel.MEETING, data)
}
} as const

Expand Down
12 changes: 12 additions & 0 deletions packages/client/modules/demo/getDemoEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import {fetchQuery} from 'relay-runtime'
import {getDemoEntitiesQuery} from '~/__generated__/getDemoEntitiesQuery.graphql'
import Atmosphere from '../../Atmosphere'

const BOT_GROUP_TITLES: Record<string, string> = {
botGroup1: 'Empower Junior Staff',
botGroup2: 'Documentation Practices',
botGroup4: 'Chat Communication Issues',
botGroup5: 'Unproductive Discussions',
botGroup6: 'Meeting Overload'
}

export const getDemoGroupTitle = (groupId: string, firstReflectionContent?: string) => {
return BOT_GROUP_TITLES[groupId] ?? firstReflectionContent ?? 'New Group'
}

const query = graphql`
query getDemoEntitiesQuery($text: String!) {
getDemoEntities(text: $text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const processEmailPasswordReset = async (
ip: string,
email: string,
identities: AuthIdentity[],
userId: string
userId: string,
sendEmail?: boolean | null
) => {
const pg = getKysely()
const tokenBuffer = await randomBytes(48)
Expand All @@ -38,6 +39,8 @@ const processEmailPasswordReset = async (

await updateUser({identities}, userId)

if (sendEmail === false) return {success: true}

const {subject, body, html} = resetPasswordEmailCreator({resetPasswordToken})
const success = await getMailManager().sendEmail({
to: email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MutationResolvers} from '../../private/resolverTypes'

const removeAuthIdentity: MutationResolvers['removeAuthIdentity'] = async (
_source,
{domain, identityType, addLocal},
{domain, identityType, addLocal, sendEmail = true},
{ip}
) => {
// VALIDATION
Expand Down Expand Up @@ -44,7 +44,7 @@ const removeAuthIdentity: MutationResolvers['removeAuthIdentity'] = async (

await Promise.all(
usersWithUpdatedIdentities.map(({identities, id: userId, email}) =>
processEmailPasswordReset(ip, email, identities, userId)
processEmailPasswordReset(ip, email, identities, userId, sendEmail)
)
)

Expand Down
5 changes: 5 additions & 0 deletions packages/server/graphql/private/typeDefs/Mutation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ type Mutation {
Add a local auth with a dummy hashed password
"""
addLocal: Boolean!

"""
Send an email to the user to let them know their auth identity has been removed and they need to reset their password. Defaults to true.
"""
sendEmail: Boolean
): RemoveAuthIdentityPayload!

"""
Expand Down

0 comments on commit f776961

Please sign in to comment.