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!

RolesGuard added to all necessary files

Yevhenii Kulisidibc375d52e2fd
diff --git a/src/alert/alert.controller.ts b/src/alert/alert.controller.ts
index 4d96e4537..177bca091 100644
--- a/src/alert/alert.controller.ts
+++ b/src/alert/alert.controller.ts
@@ -20,6 +20,7 @@ import { UserType } from 'src/user/entities/user.entity'
import { Alert } from './entity/alert.entity'
import { AlertDTO, CreateAlertDTO } from './dto/alert.dto'
import { ACCOUNT_PLANS, PlanCode } from 'src/user/entities/user.entity'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
const ALERTS_MAXIMUM = ACCOUNT_PLANS[PlanCode.free].maxAlerts
@@ -35,7 +36,7 @@ export class AlertController {
@Get('/')
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN, UserType.CUSTOMER)
@ApiResponse({ status: 200, type: Alert })
async getAllAlerts(
@@ -65,7 +66,7 @@ export class AlertController {
@Post('/')
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN, UserType.CUSTOMER)
@ApiResponse({ status: 201, type: Alert })
async createAlert(
@@ -129,7 +130,7 @@ export class AlertController {
@Put('/:id')
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN, UserType.CUSTOMER)
@ApiResponse({ status: 200, type: Alert })
async updateAlert(
@@ -164,7 +165,7 @@ export class AlertController {
@Delete('/:id')
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN, UserType.CUSTOMER)
@ApiResponse({ status: 204, description: 'Empty body' })
async deleteAlert(
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.ts
index 63632b7ea..3742520b9 100644
--- a/src/analytics/analytics.controller.ts
+++ b/src/analytics/analytics.controller.ts
@@ -65,6 +65,7 @@ import {
} from '../common/constants'
import { BotDetection } from '../common/decorators/bot-detection.decorator'
import { BotDetectionGuard } from '../common/guards/bot-detection.guard'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
dayjs.extend(utc)
dayjs.extend(timezone)
@@ -200,7 +201,7 @@ const TRANSPARENT_GIF_BUFFER = Buffer.from(
)
@ApiTags('Analytics')
-@UseGuards(RolesGuard)
+@UseGuards(JwtAccessTokenGuard, RolesGuard)
@Controller('log')
export class AnalyticsController {
constructor(
diff --git a/src/marketplace/categories/categories.controller.ts b/src/marketplace/categories/categories.controller.ts
index b6b5b4c51..711cb208d 100644
--- a/src/marketplace/categories/categories.controller.ts
+++ b/src/marketplace/categories/categories.controller.ts
@@ -27,6 +27,7 @@ import { UpdateCategoryParams } from './dtos/update-category-params.dto'
import { UpdateCategory } from './dtos/update-category.dto'
import { ISaveCategory } from './interfaces/save-category.interface'
import { BodyValidationPipe } from '../common/pipes/body-validation.pipe'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
@ApiTags('categories')
@UsePipes(
@@ -90,7 +91,7 @@ export class CategoriesController {
return category
}
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@Post()
async createCategory(
@@ -113,7 +114,7 @@ export class CategoriesController {
example: 1,
type: Number,
})
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@Patch(':categoryId')
async updateCategory(
@@ -145,7 +146,7 @@ export class CategoriesController {
example: 1,
type: Number,
})
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@Delete(':categoryId')
async deleteCategory(@Param() params: DeleteCategoryParams): Promise<void> {
diff --git a/src/marketplace/complaints/complaints.controller.ts b/src/marketplace/complaints/complaints.controller.ts
index 13c8cf069..39d3b5ee2 100644
--- a/src/marketplace/complaints/complaints.controller.ts
+++ b/src/marketplace/complaints/complaints.controller.ts
@@ -22,6 +22,7 @@ import { Complaint } from './entities/complaint.entity'
import { UserType } from 'src/user/entities/user.entity'
import { RolesGuard } from 'src/auth/guards/roles.guard'
import { Roles } from 'src/auth/decorators/roles.decorator'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
@ApiTags('complaints')
@Controller('complaints')
@@ -37,7 +38,7 @@ export class ComplaintsController {
@ApiQuery({ name: 'limit', required: false, type: String })
@ApiQuery({ name: 'extensionId', required: false, type: String })
@ApiQuery({ name: 'userId', required: false, type: String })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
async getComplaints(@Query() queries: GetComplaintsQueryDto): Promise<{
complaints: Complaint[]
@@ -57,7 +58,7 @@ export class ComplaintsController {
@Get(':complaintId')
@ApiParam({ name: 'complaintId', required: true, type: String })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
async getComplaint(
@Param() params: GetComplaintParamDto,
@@ -102,7 +103,7 @@ export class ComplaintsController {
@Post(':complaintId/resolve')
@ApiParam({ name: 'complaintId', required: true, type: String })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
async resolveComplaint(
@Param() params: ResolveComplaintParamDto,
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index 3ed4b6e90..4dce9c3b6 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -49,6 +49,7 @@ import { Roles } from '../../auth/decorators/roles.decorator'
import { RolesGuard } from '../../auth/guards/roles.guard'
import { UserType } from '../../user/entities/user.entity'
import { ExtensionStatus } from './enums/extension-status.enum'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
@ApiTags('extensions')
@UsePipes(
@@ -159,7 +160,7 @@ export class ExtensionsController {
type: String,
})
@Roles(UserType.ADMIN)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Get('admin')
async getAllExtensionsAdmin(@Query() queries: GetAllExtensionsQueries): Promise<{
extensions: Extension[]
@@ -367,7 +368,7 @@ export class ExtensionsController {
type: String,
})
@Roles(UserType.ADMIN)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Get('admin/search')
async searchExtensionAdmin(@Query() queries: SearchExtensionQueries): Promise<{
extensions: Extension[]
@@ -494,7 +495,7 @@ export class ExtensionsController {
{ name: 'file', maxCount: 1 },
]),
)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN, UserType.CUSTOMER)
@Patch(':extensionId')
async updateExtension(
@@ -627,7 +628,7 @@ export class ExtensionsController {
example: 'de025965-3221-4d09-ba35-a09da59793a6',
type: String,
})
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@Patch(':extensionId/approve')
async approveExtension(@Param() params: UpdateExtensionParams): Promise<Extension> {
@@ -652,7 +653,7 @@ export class ExtensionsController {
example: 'de025965-3221-4d09-ba35-a09da59793a6',
type: String,
})
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@Patch(':extensionId/reject')
async rejectExtension(@Param() params: UpdateExtensionParams): Promise<Extension> {
diff --git a/src/project/project.controller.ts b/src/project/project.controller.ts
index 92165c3e8..d607ec763 100644
--- a/src/project/project.controller.ts
+++ b/src/project/project.controller.ts
@@ -55,6 +55,7 @@ import {
updateProjectClickhouse,
deleteProjectClickhouse,
} from '../common/utils'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
// const updateProjectRedis = async (id: string, project: Project) => {
// const key = getRedisProjectKey(id)
@@ -107,7 +108,7 @@ export class ProjectController {
@ApiQuery({ name: 'skip', required: false })
@ApiQuery({ name: 'relatedonly', required: false, type: Boolean })
@ApiResponse({ status: 200, type: [Project] })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async get(
@CurrentUserId() userId: string,
@@ -152,7 +153,7 @@ export class ProjectController {
@ApiQuery({ name: 'skip', required: false })
@ApiQuery({ name: 'relatedonly', required: false, type: Boolean })
@ApiResponse({ status: 200, type: [Project] })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async getShared(
@CurrentUserId() userId: string,
@@ -184,7 +185,7 @@ export class ProjectController {
@ApiQuery({ name: 'take', required: false })
@ApiQuery({ name: 'skip', required: false })
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
@ApiResponse({ status: 200, type: Project })
async getAllProjects(
@@ -203,7 +204,7 @@ export class ProjectController {
@ApiQuery({ name: 'relatedonly', required: false, type: Boolean })
@ApiResponse({ status: 200, type: [Project] })
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
async getUserProject(
@Param('id') userId: string,
@@ -266,7 +267,7 @@ export class ProjectController {
@Post('/admin/:id')
@ApiResponse({ status: 201, type: Project })
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.ADMIN)
async createForAdmin(
@Param('id') userId: string,
@@ -320,7 +321,7 @@ export class ProjectController {
@Post('/')
@ApiResponse({ status: 201, type: Project })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async create(
@Body() projectDTO: ProjectDTO,
@@ -389,7 +390,7 @@ export class ProjectController {
@Delete('/reset/:id')
@HttpCode(204)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
async reset(
@@ -447,7 +448,7 @@ export class ProjectController {
@Put('/:id')
@HttpCode(200)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 200, type: Project })
async update(
@@ -503,7 +504,7 @@ export class ProjectController {
@Delete('/:id')
@HttpCode(204)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
async delete(
@@ -569,7 +570,7 @@ export class ProjectController {
@Delete('/:pid/:shareId')
@HttpCode(204)
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
async deleteShare(
@@ -612,7 +613,7 @@ export class ProjectController {
@Post('/:pid/share')
@HttpCode(200)
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 200, type: Project })
async share(
@@ -733,7 +734,7 @@ export class ProjectController {
@Put('/share/:shareId')
@HttpCode(200)
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 200, type: Project })
async updateShare(
@@ -773,7 +774,7 @@ export class ProjectController {
@HttpCode(204)
@UseGuards(SelfhostedGuard)
- // @UseGuards(RolesGuard)
+ // @UseGuards(JwtAccessTokenGuard, RolesGuard)
// @Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
@Get('/share/:id')
diff --git a/src/twoFactorAuth/twoFactorAuth.controller.ts b/src/twoFactorAuth/twoFactorAuth.controller.ts
index ff4987682..2bfe09aa5 100644
--- a/src/twoFactorAuth/twoFactorAuth.controller.ts
+++ b/src/twoFactorAuth/twoFactorAuth.controller.ts
@@ -24,6 +24,7 @@ import { TwoFaNotRequired } from '../auth/decorators/two-fa-not-required.decorat
import { RolesGuard } from '../auth/guards/roles.guard'
import { TwoFactorAuthDTO } from './dto/2fa-auth.dto'
import { generateRecoveryCode, checkRateLimit } from '../common/utils'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
@ApiTags('2fa')
@Controller('2fa')
@@ -37,7 +38,7 @@ export class TwoFactorAuthController {
) {}
@Post('generate')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard) // temporary this feature is not available for selfhosted
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@TwoFaNotRequired()
@@ -50,7 +51,7 @@ export class TwoFactorAuthController {
}
@Post('enable')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard) // temporary this feature is not available for selfhosted
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@TwoFaNotRequired()
@@ -90,7 +91,7 @@ export class TwoFactorAuthController {
user.isTwoFactorAuthenticationEnabled = true
- const authData = this.authService.generateJwtTokens(user.id, true)
+ const authData = await this.authService.generateJwtTokens(user.id, true)
return {
twoFactorRecoveryCode,
@@ -100,7 +101,7 @@ export class TwoFactorAuthController {
@Post('disable')
@HttpCode(200)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard) // temporary this feature is not available for selfhosted
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async turnOffTwoFactorAuthentication(
@@ -140,7 +141,7 @@ export class TwoFactorAuthController {
@Post('authenticate')
@HttpCode(200)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard) // temporary this feature is not available for selfhosted
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@TwoFaNotRequired()
@@ -170,6 +171,6 @@ export class TwoFactorAuthController {
throw new BadRequestException('Wrong authentication code')
}
- return this.authService.generateJwtTokens(user.id, true)
+ return await this.authService.generateJwtTokens(user.id, true)
}
}
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index d6d15b00a..3ca74d3c2 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -56,6 +56,7 @@ import { UserProfileDTO } from './dto/user.dto'
import { checkRateLimit } from '../common/utils'
import { InjectBot } from 'nestjs-telegraf'
import { Scenes, Telegraf } from 'telegraf'
+import { JwtAccessTokenGuard } from 'src/auth/guards'
dayjs.extend(utc)
@@ -63,7 +64,7 @@ export type TelegrafContext = Scenes.SceneContext
@ApiTags('User')
@Controller('user')
-@UseGuards(RolesGuard)
+@UseGuards(JwtAccessTokenGuard, RolesGuard)
export class UserController {
constructor(
private readonly userService: UserService,
@@ -78,7 +79,7 @@ export class UserController {
@Get('/')
@ApiQuery({ name: 'take', required: false })
@ApiQuery({ name: 'skip', required: false })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.ADMIN)
async get(
@@ -91,7 +92,7 @@ export class UserController {
// set theme
@Put('/theme')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async setTheme(
@@ -103,7 +104,7 @@ export class UserController {
@Get('/search')
@ApiQuery({ name: 'query', required: false })
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.ADMIN)
async searchUsers(
@@ -114,7 +115,7 @@ export class UserController {
}
@Post('/')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.ADMIN)
async create(@Body() userDTO: UserProfileDTO): Promise<User> {
@@ -135,7 +136,7 @@ export class UserController {
}
@Post('/api-key')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async generateApiKey(
@@ -166,7 +167,7 @@ export class UserController {
}
@Delete('/api-key')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async deleteApiKey(@CurrentUserId() userId: string): Promise<void> {
@@ -183,7 +184,7 @@ export class UserController {
@Delete('/:id')
@HttpCode(204)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.ADMIN)
async delete(
@@ -227,7 +228,7 @@ export class UserController {
@Delete('/')
@HttpCode(204)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async deleteSelf(@CurrentUserId() id: string): Promise<any> {
@@ -267,7 +268,7 @@ export class UserController {
@Delete('/share/:shareId')
@HttpCode(204)
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
async deleteShare(
@@ -297,7 +298,7 @@ export class UserController {
@Get('/share/:shareId')
@HttpCode(204)
@UseGuards(SelfhostedGuard)
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@ApiResponse({ status: 204, description: 'Empty body' })
async acceptShare(
@@ -327,7 +328,7 @@ export class UserController {
}
@Post('/confirm_email')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async sendEmailConfirmation(
@@ -361,7 +362,7 @@ export class UserController {
}
@Put('/:id')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.ADMIN)
async update(
@@ -397,7 +398,7 @@ export class UserController {
}
@Delete('/tg/:id')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
@HttpCode(204)
@@ -418,7 +419,7 @@ export class UserController {
}
@Put('/')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async updateCurrentUser(
@@ -535,7 +536,7 @@ export class UserController {
}
@Get('/export')
- @UseGuards(RolesGuard)
+ @UseGuards(JwtAccessTokenGuard, RolesGuard)
@UseGuards(SelfhostedGuard)
@Roles(UserType.CUSTOMER, UserType.ADMIN)
async exportUserData(@CurrentUserId() user_id: string): Promise<User> {