Scheduling infrastructure for absolutely everyone.
fix: reviewed-user-sms-lock (#16016)
Natnael Yilmaad62f9d2bdb5
diff --git a/packages/lib/checkRateLimitAndThrowError.ts b/packages/lib/checkRateLimitAndThrowError.tsindex 64fd6189a64..9ec2fca0173 100644--- a/packages/lib/checkRateLimitAndThrowError.ts+++ b/packages/lib/checkRateLimitAndThrowError.ts@@ -55,6 +55,9 @@ async function changeSMSLockState(identifier: string, status: SMSLockState) {}if (userId) {+ const user = await prisma.user.findUnique({ where: { id: userId, profiles: { none: {} } } });+ if (user?.smsLockReviewedByAdmin) return;+await prisma.user.update({where: {id: userId,@@ -65,6 +68,11 @@ async function changeSMSLockState(identifier: string, status: SMSLockState) {},});} else {+ const team = await prisma.team.findUnique({+ where: { id: teamId, parentId: null, isOrganization: false },+ });+ if (team?.smsLockReviewedByAdmin) return;+await prisma.team.update({where: {id: teamId,diff --git a/packages/prisma/migrations/20240804185106_add_sms_lock_reviewed_by_admin_flag_in_user_and_team_table/migration.sql b/packages/prisma/migrations/20240804185106_add_sms_lock_reviewed_by_admin_flag_in_user_and_team_table/migration.sqlnew file mode 100644index 00000000000..83945b98b4d--- /dev/null+++ b/packages/prisma/migrations/20240804185106_add_sms_lock_reviewed_by_admin_flag_in_user_and_team_table/migration.sql@@ -0,0 +1,5 @@+-- AlterTable+ALTER TABLE "Team" ADD COLUMN "smsLockReviewedByAdmin" BOOLEAN NOT NULL DEFAULT false;++-- AlterTable+ALTER TABLE "users" ADD COLUMN "smsLockReviewedByAdmin" BOOLEAN NOT NULL DEFAULT false;diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prismaindex 4268312f772..d745b5078a9 100644--- a/packages/prisma/schema.prisma+++ b/packages/prisma/schema.prisma@@ -320,8 +320,9 @@ model User {secondaryEmails SecondaryEmail[]isPlatformManaged Boolean @default(false)- OutOfOfficeReasons OutOfOfficeReason[]- smsLockState SMSLockState @default(UNLOCKED)+ OutOfOfficeReasons OutOfOfficeReason[]+ smsLockState SMSLockState @default(UNLOCKED)+ smsLockReviewedByAdmin Boolean @default(false)@@unique([email])@@unique([email, username])@@ -412,6 +413,7 @@ model Team {smsLockState SMSLockState @default(UNLOCKED)platformBilling PlatformBilling?activeOrgWorkflows WorkflowsOnTeams[]+ smsLockReviewedByAdmin Boolean @default(false)@@unique([slug, parentId])@@index([parentId])diff --git a/packages/trpc/server/routers/viewer/admin/setSMSLockState.handler.ts b/packages/trpc/server/routers/viewer/admin/setSMSLockState.handler.tsindex a5279cf4333..2b0400b680d 100644--- a/packages/trpc/server/routers/viewer/admin/setSMSLockState.handler.ts+++ b/packages/trpc/server/routers/viewer/admin/setSMSLockState.handler.ts@@ -16,17 +16,17 @@ type GetOptions = {const setSMSLockState = async ({ input }: GetOptions) => {const { userId, username, teamId, teamSlug, lock } = input;if (userId) {+ const userToUpdate = await prisma.user.findUnique({ where: { id: userId } });+ if (!userToUpdate) throw new TRPCError({ code: "BAD_REQUEST", message: "User not found" });const updatedUser = await prisma.user.update({where: {id: userId,},data: {smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,+ smsLockReviewedByAdmin: true,},});- if (!updatedUser) {- throw new TRPCError({ code: "BAD_REQUEST", message: "User not found" });- }return { name: updatedUser.username, locked: lock };} else if (username) {const userToUpdate = await prisma.user.findFirst({@@ -35,32 +35,33 @@ const setSMSLockState = async ({ input }: GetOptions) => {profiles: { none: {} },},});- if (!userToUpdate) {- throw new TRPCError({ code: "BAD_REQUEST", message: "User not found" });- }- if (userToUpdate) {- const updatedUser = await prisma.user.update({- where: {- id: userToUpdate.id,- },- data: {- smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,- },- });- return { name: updatedUser.username, locked: lock };- }+ if (!userToUpdate) throw new TRPCError({ code: "BAD_REQUEST", message: "User not found" });+ const updatedUser = await prisma.user.update({+ where: {+ id: userToUpdate.id,+ },+ data: {+ smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,+ smsLockReviewedByAdmin: true,+ },+ });+ return { name: updatedUser.username, locked: lock };} else if (teamId) {+ const teamToUpdate = await prisma.team.findUnique({+ where: {+ id: teamId,+ },+ });+ if (!teamToUpdate) throw new TRPCError({ code: "BAD_REQUEST", message: "Team not found" });const updatedTeam = await prisma.team.update({where: {id: teamId,},data: {smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,+ smsLockReviewedByAdmin: true,},});- if (!updatedTeam) {- throw new TRPCError({ code: "BAD_REQUEST", message: "Team not found" });- }return { name: updatedTeam.slug, locked: lock };} else if (teamSlug) {const teamToUpdate = await prisma.team.findFirst({@@ -69,20 +70,17 @@ const setSMSLockState = async ({ input }: GetOptions) => {parentId: null,},});- if (!teamToUpdate) {- throw new TRPCError({ code: "BAD_REQUEST", message: "Team not found" });- }- if (teamToUpdate) {- const updatedTeam = await prisma.team.update({- where: {- id: teamToUpdate.id,- },- data: {- smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,- },- });- return { name: updatedTeam.slug, locked: lock };- }+ if (!teamToUpdate) throw new TRPCError({ code: "BAD_REQUEST", message: "Team not found" });+ const updatedTeam = await prisma.team.update({+ where: {+ id: teamToUpdate.id,+ },+ data: {+ smsLockState: lock ? SMSLockState.LOCKED : SMSLockState.UNLOCKED,+ smsLockReviewedByAdmin: true,+ },+ });+ return { name: updatedTeam.slug, locked: lock };}throw new TRPCError({ code: "BAD_REQUEST", message: "Input data missing" });};