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!

added share accept

Blue Mouse608701e7c9e2
diff --git a/src/project/project.service.ts b/src/project/project.service.ts
index e34bb441e..2f3cca4bb 100644
--- a/src/project/project.service.ts
+++ b/src/project/project.service.ts
@@ -108,6 +108,10 @@ export class ProjectService {
return this.projectShareRepository.find(params)
}
+ async findOneShare(id: string, params: Object = {}): Promise<ProjectShare | null> {
+ return this.projectShareRepository.findOne(id, params)
+ }
+
findOneWithRelations(id: string): Promise<Project | null> {
return this.projectsRepository.findOne(id, { relations: ['admin'] })
}
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index e2d74800d..0009d79d4 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -2,7 +2,7 @@ import {
Controller, Query, Req, Body, Param, Get, Post, Put, Delete, HttpCode, BadRequestException, UseGuards, MethodNotAllowedException,
} from '@nestjs/common'
import { Request } from 'express'
-import { ApiTags, ApiQuery } from '@nestjs/swagger'
+import { ApiTags, ApiQuery, ApiResponse } from '@nestjs/swagger'
import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
import * as _map from 'lodash/map'
@@ -170,24 +170,22 @@ export class UserController {
@UseGuards(SelfhostedGuard)
@UseGuards(RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
+ @ApiResponse({ status: 204, description: 'Empty body' })
async deleteShare(
@Param('shareId') shareId: string,
@CurrentUserId() uid: string,
): Promise<any> {
this.logger.log({ uid, shareId }, 'DELETE /user/share/:shareId')
- const share = await this.projectService.findShare({
- where: {
- id: shareId,
- },
+ const share = await this.projectService.findOneShare(shareId, {
relations: ['user'],
})
if (_isEmpty(share)) {
- throw new BadRequestException('The provided share id is not valid')
+ throw new BadRequestException('The provided share ID is not valid')
}
- if (share[0]?.user?.id !== uid) {
+ if (share.user?.id !== uid) {
throw new BadRequestException('You are not allowed to delete this share')
}
@@ -196,6 +194,37 @@ export class UserController {
return 'shareDeleted'
}
+ @Get('/share/:shareId')
+ @HttpCode(204)
+ @UseGuards(SelfhostedGuard)
+ @UseGuards(RolesGuard)
+ @Roles(UserType.CUSTOMER, UserType.ADMIN)
+ @ApiResponse({ status: 204, description: 'Empty body' })
+ async acceptShare(
+ @Param('shareId') shareId: string,
+ @CurrentUserId() uid: string,
+ ): Promise<any> {
+ this.logger.log({ uid, shareId }, 'GET /user/share/:shareId')
+
+ const share = await this.projectService.findOneShare(shareId, {
+ relations: ['user'],
+ })
+
+ if (_isEmpty(share)) {
+ throw new BadRequestException('The provided share ID is not valid')
+ }
+
+ if (share[0]?.user?.id !== uid) {
+ throw new BadRequestException('You are not allowed to delete this share')
+ }
+
+ share.confirmed = true
+
+ await this.projectService.updateShare(shareId, share)
+
+ return 'shareAccepted'
+ }
+
@Post('/confirm_email')
@UseGuards(RolesGuard)
@UseGuards(SelfhostedGuard)