Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Remove POST /bulk-add-users

Blue Mousef047fdf5a256
diff --git a/backend/apps/cloud/src/project/dto/bulk-add-users.dto.ts b/backend/apps/cloud/src/project/dto/bulk-add-users.dto.ts
deleted file mode 100644
index 00354ebfb..000000000
--- a/backend/apps/cloud/src/project/dto/bulk-add-users.dto.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import { ApiProperty } from '@nestjs/swagger'
-import {
- IsNotEmpty,
- IsArray,
- ValidateNested,
- ArrayMinSize,
- IsEnum,
- IsEmail,
-} from 'class-validator'
-import { Type } from 'class-transformer'
-
-import { ValidateProjectIds } from '../../analytics/decorators/validate-project-ids.decorator'
-import { Role } from '../entity/project-share.entity'
-
-class UserProjectAccess {
- @ApiProperty({
- example: '[email protected]',
- description: 'User you want to invite to your project',
- })
- @IsNotEmpty()
- @IsEmail()
- email: string
-
- @ApiProperty({
- example: 'viewer',
- description: 'Users role in your project',
- })
- @IsNotEmpty()
- @IsEnum(Role)
- role: Role
-
- @ApiProperty({
- example: ['project-id-1', 'project-id-2'],
- description: 'Array of project IDs to add the user to',
- })
- @IsArray()
- @IsNotEmpty()
- @ArrayMinSize(1)
- @ValidateProjectIds()
- projectIds: string[]
-}
-
-export class BulkAddUsersDto {
- @ApiProperty({
- type: [UserProjectAccess],
- description: 'Array of users and their project access details',
- })
- @IsArray()
- @ValidateNested({ each: true })
- @Type(() => UserProjectAccess)
- @ArrayMinSize(1)
- users: UserProjectAccess[]
-}
diff --git a/backend/apps/cloud/src/project/interfaces/bulk-add-users.ts b/backend/apps/cloud/src/project/interfaces/bulk-add-users.ts
deleted file mode 100644
index 4203f649c..000000000
--- a/backend/apps/cloud/src/project/interfaces/bulk-add-users.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface BulkAddUsersResponse {
- email: string
- success: boolean
- error: string | null
- failedProjectIds?: {
- projectId: string
- reason: string
- }[]
-}
diff --git a/backend/apps/cloud/src/project/project.controller.ts b/backend/apps/cloud/src/project/project.controller.ts
index 59c6ce8d0..3684ab331 100644
--- a/backend/apps/cloud/src/project/project.controller.ts
+++ b/backend/apps/cloud/src/project/project.controller.ts
@@ -113,8 +113,6 @@ import { ProjectIdDto } from './dto/project-id.dto'
import { CreateProjectViewDto } from './dto/create-project-view.dto'
import { UpdateProjectViewDto } from './dto/update-project-view.dto'
import { ProjectViewIdsDto } from './dto/project-view-ids.dto'
-import { BulkAddUsersDto } from './dto/bulk-add-users.dto'
-import { BulkAddUsersResponse } from './interfaces/bulk-add-users'
import { OrganisationService } from '../organisation/organisation.service'
import { Organisation } from '../organisation/entity/organisation.entity'
import { ProjectOrganisationDto } from './dto/project-organisation.dto'
@@ -889,156 +887,6 @@ export class ProjectController {
await this.projectService.deleteByFilters(pid, type, filters)
}
- @ApiBearerAuth()
- @Post('/bulk-add-users')
- @HttpCode(200)
- @Auth([], true)
- @ApiResponse({ status: 200, type: [BulkAddUsersDto] })
- async bulkAddUsers(
- @Body() bulkAddUsersDto: BulkAddUsersDto,
- @CurrentUserId() uid: string,
- ): Promise<BulkAddUsersResponse[]> {
- this.logger.log({ uid, bulkAddUsersDto }, 'POST /project/bulk-add-users')
-
- const inviter = await this.userService.findOne({
- where: { id: uid },
- relations: ['projects', 'sharedProjects', 'sharedProjects.project'],
- })
-
- const results: BulkAddUsersResponse[] = []
-
- await Promise.all(
- bulkAddUsersDto.users.map(async invitationObject => {
- const invitee = await this.userService.findOne({
- where: { email: invitationObject.email },
- relations: ['sharedProjects'],
- })
-
- if (!invitee) {
- this.logger.warn(
- `User with email ${invitationObject.email} is not registered`,
- )
-
- results.push({
- email: invitationObject.email,
- success: false,
- error: 'User with this email is not registered on Swetrix',
- failedProjectIds: [],
- })
-
- return null
- }
-
- if (invitee.id === inviter.id) {
- this.logger.warn(
- `Skipping self-share attempt for ${invitationObject.email}`,
- )
-
- results.push({
- email: invitationObject.email,
- success: false,
- error:
- 'User with this email is the same as the inviter initiating this request',
- failedProjectIds: [],
- })
-
- return null
- }
-
- const failedProjectIds = []
-
- const uniqueProjectIds = [...new Set(invitationObject.projectIds)]
-
- for (const pid of uniqueProjectIds) {
- if (!isValidPID(pid)) {
- this.logger.warn(`Invalid project ID: ${pid}`)
- failedProjectIds.push({
- projectId: pid,
- reason: 'Invalid project ID',
- })
- continue
- }
-
- const project = await this.projectService.getFullProject(pid)
-
- if (_isEmpty(project)) {
- this.logger.warn(`Project with ID ${pid} does not exist`)
- failedProjectIds.push({
- projectId: pid,
- reason: 'Project does not exist',
- })
- continue
- }
-
- try {
- this.projectService.allowedToManage(project, uid, inviter.roles)
- } catch {
- this.logger.warn(`User ${uid} not allowed to manage project ${pid}`)
- failedProjectIds.push({
- projectId: pid,
- reason: 'Inviter is not allowed to manage this project',
- })
- continue
- }
-
- const isSharingWithUser = !_isEmpty(
- _find(project.share, share => share.user?.id === invitee.id),
- )
-
- if (isSharingWithUser) {
- this.logger.warn(
- `Already sharing project ${pid} with ${invitee.email}`,
- )
- failedProjectIds.push({
- projectId: pid,
- reason: 'Already sharing project with this user',
- })
- continue
- }
-
- try {
- const share = new ProjectShare()
- share.role = invitationObject.role
- share.user = invitee
- share.project = project
- share.confirmed = true // Auto-confirm since we're not sending invitations
-
- await this.projectService.createShare(share)
-
- // Saving share into project
- project.share.push(share)
- await this.projectService.create(project)
-
- // Saving share into invitees shared projects
- invitee.sharedProjects.push(share)
- await this.userService.create(invitee)
-
- await deleteProjectRedis(pid)
- } catch (reason) {
- this.logger.error(
- `[ERROR] Could not share project (pid: ${pid}, invitee ID: ${invitee.id}): ${reason}`,
- )
- failedProjectIds.push({
- projectId: pid,
- reason: 'Internal error',
- })
- }
- }
-
- results.push({
- email: invitationObject.email,
- success: failedProjectIds.length === 0,
- failedProjectIds,
- error: null,
- })
-
- return null
- }),
- )
-
- return results
- }
-
@ApiBearerAuth()
@Post('/:pid/share')
@HttpCode(200)