Skip to content

Commit

Permalink
chore(api): Skip workspace creation when user is admin (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaMajmudar authored Jul 29, 2024
1 parent a055701 commit cf6a125
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/api/src/common/create-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { Logger } from '@nestjs/common'
const createUser = async (
dto: Partial<CreateUserDto> & { authProvider: AuthProvider },
prisma: PrismaService
): Promise<
User & {
defaultWorkspace: Workspace
}
> => {
): Promise<User & { defaultWorkspace?: Workspace }> => {
const logger = new Logger('createUser')

// Create the user
Expand All @@ -27,6 +23,11 @@ const createUser = async (
}
})

if (user.isAdmin) {
logger.log(`Created admin user ${user.id}`)
return user
}

// Create the user's default workspace
const workspace = await createWorkspace(
user,
Expand Down
20 changes: 20 additions & 0 deletions apps/api/src/user/user.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ describe('User Controller Tests', () => {
expect(workspace.ownerId).toEqual(createUserResponse.id)
})

it('should skip workspace creation for admin users', async () => {
const createAdminUserResponse = await userService.createUser({
email: '',
isAdmin: true,
isOnboardingFinished: true,
profilePictureUrl: null
})

expect(createAdminUserResponse.defaultWorkspace).toBeUndefined()

const workspace = await prisma.workspace.findFirst({
where: {
ownerId: createAdminUserResponse.id,
isDefault: true
}
})

expect(workspace).toBeNull()
})

test('regular user should not be able to access other routes if onboarding is not finished', async () => {
// Flip the user's onboarding status to false
await prisma.user.update({
Expand Down

0 comments on commit cf6a125

Please sign in to comment.