Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(API): Skip workspace creation when user is admin #376

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading