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 checks from public log endpoints and update GET project endpoint

Yehor Dremliuhaef229e7b9811
diff --git a/apps/production/src/analytics/analytics.controller.ts b/apps/production/src/analytics/analytics.controller.ts
index c0772f1cf..7a2e1fb45 100644
--- a/apps/production/src/analytics/analytics.controller.ts
+++ b/apps/production/src/analytics/analytics.controller.ts
@@ -28,9 +28,8 @@ import {
ForbiddenException,
Response,
Header,
- ConflictException,
} from '@nestjs/common'
-import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'
+import { ApiTags } from '@nestjs/swagger'
import * as UAParser from 'ua-parser-js'
import * as isbot from 'isbot'
@@ -1218,7 +1217,6 @@ export class AnalyticsController {
}
// Log error event
- @ApiBearerAuth()
@Post('error')
@UseGuards(BotDetectionGuard)
@BotDetection()
@@ -1228,15 +1226,6 @@ export class AnalyticsController {
@Headers() headers,
@Ip() reqIP,
): Promise<any> {
- const project = await this.projectService.getProjectById(errorDTO.pid)
-
- if (!project || project.isArchived) {
- const message = !project
- ? 'Project is not found.'
- : 'Project is archived.'
- throw new ConflictException(message)
- }
-
const { 'user-agent': userAgent, origin } = headers
const ip = getIPFromHeaders(headers, true) || reqIP || ''
@@ -1311,7 +1300,6 @@ export class AnalyticsController {
}
// Log custom event
- @ApiBearerAuth()
@Post('custom')
@UseGuards(BotDetectionGuard)
@BotDetection()
@@ -1321,15 +1309,6 @@ export class AnalyticsController {
@Headers() headers,
@Ip() reqIP,
): Promise<any> {
- const project = await this.projectService.getProjectById(eventsDTO.pid)
-
- if (!project || project.isArchived) {
- const message = !project
- ? 'Project is not found.'
- : 'Project is archived.'
- throw new ConflictException(message)
- }
-
const { 'user-agent': userAgent, origin } = headers
const ip = getIPFromHeaders(headers, true) || reqIP || ''
@@ -1401,7 +1380,6 @@ export class AnalyticsController {
}
}
- @ApiBearerAuth()
@Post('hb')
@UseGuards(BotDetectionGuard)
@BotDetection()
@@ -1411,15 +1389,6 @@ export class AnalyticsController {
@Headers() headers,
@Ip() reqIP,
): Promise<any> {
- const project = await this.projectService.getProjectById(logDTO.pid)
-
- if (!project || project.isArchived) {
- const message = !project
- ? 'Project is not found.'
- : 'Project is archived.'
- throw new ConflictException(message)
- }
-
const { 'user-agent': userAgent } = headers
const { pid } = logDTO
const ip = getIPFromHeaders(headers, true) || reqIP || ''
@@ -1440,7 +1409,6 @@ export class AnalyticsController {
}
// Log pageview event
- @ApiBearerAuth()
@Post()
@UseGuards(BotDetectionGuard)
@BotDetection()
@@ -1450,15 +1418,6 @@ export class AnalyticsController {
@Headers() headers,
@Ip() reqIP,
): Promise<any> {
- const project = await this.projectService.getProjectById(logDTO.pid)
-
- if (!project || project.isArchived) {
- const message = !project
- ? 'Project is not found.'
- : 'Project is archived.'
- throw new ConflictException(message)
- }
-
const { 'user-agent': userAgent, origin } = headers
const ip = getIPFromHeaders(headers, true) || reqIP || ''
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.ts
index c142ba644..aea24eea4 100644
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@ -1821,10 +1821,12 @@ export class ProjectController {
await this.projectService.deleteShare(shareId)
}
+ @ApiBearerAuth()
@Get('/:id')
@Auth([], true, true)
@ApiResponse({ status: 200, type: Project })
async getOne(
+ @Query('showArchived') showArchived: string | undefined,
@Param('id') id: string,
@CurrentUserId() uid: string,
@Headers() headers: { 'x-password'?: string },
@@ -1853,6 +1855,14 @@ export class ProjectController {
this.projectService.allowedToView(project, uid, headers['x-password'])
+ const isShowArchived = showArchived === 'true'
+
+ if (project.isArchived && !isShowArchived) {
+ throw new ConflictException(
+ 'Project is archived and showArchived is false.',
+ )
+ }
+
const isDataExists = !_isEmpty(
await this.projectService.getPIDsWhereAnalyticsDataExists([id]),
)