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!

Developed to remove extensions globally or for a project

Yevhenii Kulisidi84c441e6958c
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index 2b7c0f2cb..36a4ceda2 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -435,5 +435,56 @@ export class ExtensionsController {
@Body() body: UninstallExtensionBodyDto,
): Promise<void> {
this.logger.debug({ params, queries, body })
+
+ const extension = await this.extensionsService.findOne({
+ where: { id: params.extensionId },
+ })
+ if (!extension) {
+ throw new NotFoundException('Extension not found.')
+ }
+
+ const user = await this.userService.findOne(queries.userId)
+ if (!user) {
+ throw new NotFoundException('User not found.')
+ }
+
+ if (!body.projectId) {
+ const extensionToUser =
+ await this.extensionsService.findOneExtensionToUser({
+ where: {
+ extensionId: extension.id,
+ userId: user.id,
+ },
+ })
+ if (!extensionToUser) {
+ throw new NotFoundException('Extension not installed.')
+ }
+
+ return await this.extensionsService.deleteExtensionToUser(
+ extension.id,
+ user.id,
+ )
+ }
+
+ const project = await this.projectService.findOne(body.projectId)
+ if (!project) {
+ throw new NotFoundException('Project not found.')
+ }
+
+ const extensionToProject =
+ await this.extensionsService.findOneExtensionToProject({
+ where: {
+ extensionId: extension.id,
+ projectId: project.id,
+ },
+ })
+ if (!extensionToProject) {
+ throw new NotFoundException('Extension not installed.')
+ }
+
+ return await this.extensionsService.deleteExtensionToProject(
+ extension.id,
+ project.id,
+ )
}
}
diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.ts
index 8e8d7d8c7..53e9579d0 100644
--- a/src/marketplace/extensions/extensions.service.ts
+++ b/src/marketplace/extensions/extensions.service.ts
@@ -41,6 +41,13 @@ export class ExtensionsService {
return await this.extensionToProjectRepository.save(extensionToProject)
}
+ async deleteExtensionToProject(
+ extensionId: string,
+ projectId: string,
+ ): Promise<void> {
+ await this.extensionToProjectRepository.delete({ extensionId, projectId })
+ }
+
async findOneExtensionToUser(
options: FindOneOptions<ExtensionToUser>,
): Promise<ExtensionToUser> {
@@ -55,6 +62,13 @@ export class ExtensionsService {
return await this.extensionToUserRepository.save(extensionToUser)
}
+ async deleteExtensionToUser(
+ extensionId: string,
+ userId: string,
+ ): Promise<void> {
+ await this.extensionToUserRepository.delete({ extensionId, userId })
+ }
+
// async createInstall(
// installExtension: InstallExtension,
// ): Promise<InstallExtension> {