ToolJet/server/src/controllers/import_export_resources.controller.ts

62 lines
2.3 KiB
TypeScript
Raw Normal View History

Feature: Import export tjdb schema (#5752) * add ability to import export app and tjdb schema * init * feat ::global settings popover new ui * feat :: ui for version export modal * fix :: import export modal * cleanup * ui updates * header footer style fixes * closing settings modal while showing export modal * style fix header * feat :: added button to download table schema * fix :: styling for fx * add ability to import and export apps with tjdb schema * handle duplicate table in workspace * fix table rename * fix selected table on edit and delete * fix invalid toast on table delete * fix column default value * handle exports to strip '::' and quotes * make import/export backward compatible * handle page redirects based on resource import * handle import without tjdb schema * fix column delete and addition * make data migrations to be run per organizations * wip * update migration * fix credentials to be included * fix specific version export * make use of apps ability for import export resource * fix import navigation * fix lint * fix failing tests * fix lint * enable tjdb for public apps * update export error message on tjdb table blank * fix table not selected after creation * fix :: styling for imp exp modal , and functionality bug fixes after dev merge * fixes blank slate and columns selection * fix table delete * fix invalid toast on table edit * fix column information missing tjdb query manager * make ds imports to either reuse global or create * export only unique table ids * create default datasources if not present in export data * reuse existing table on imports * add timestamp to table name if name already exists * add ability to clone with tjdb * make imports work with marketplace plugin * skip dataqueries for which plugins are not installed * fix filter input width * fix failing spec * fix marketplace plugin installation in diff workspaces * fix check for plugin installed in workspace * fix export when table name is empty --------- Co-authored-by: stepinfwd <stepinfwd@gmail.com>
2023-08-28 15:53:15 +00:00
import { Controller, Post, UseGuards, Body, ForbiddenException } from '@nestjs/common';
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
import { User } from 'src/decorators/user.decorator';
import { ExportResourcesDto } from '@dto/export-resources.dto';
import { ImportResourcesDto } from '@dto/import-resources.dto';
import { ImportExportResourcesService } from '@services/import_export_resources.service';
import { App } from 'src/entities/app.entity';
import { AppsAbilityFactory } from 'src/modules/casl/abilities/apps-ability.factory';
import { CloneResourcesDto } from '@dto/clone-resources.dto';
@Controller({
path: 'resources',
version: '2',
})
export class ImportExportResourcesController {
constructor(
private importExportResourcesService: ImportExportResourcesService,
private appsAbilityFactory: AppsAbilityFactory
) {}
@UseGuards(JwtAuthGuard)
@Post('/export')
async export(@User() user, @Body() exportResourcesDto: ExportResourcesDto) {
const ability = await this.appsAbilityFactory.appsActions(user);
if (!ability.can('createApp', App)) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
const result = await this.importExportResourcesService.export(user, exportResourcesDto);
return {
...result,
tooljet_version: globalThis.TOOLJET_VERSION,
};
}
@UseGuards(JwtAuthGuard)
@Post('/import')
async import(@User() user, @Body() importResourcesDto: ImportResourcesDto) {
const ability = await this.appsAbilityFactory.appsActions(user);
if (!ability.can('cloneApp', App)) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
const imports = await this.importExportResourcesService.import(user, importResourcesDto);
return { imports, success: true };
}
@UseGuards(JwtAuthGuard)
@Post('/clone')
async clone(@User() user, @Body() cloneResourcesDto: CloneResourcesDto) {
const ability = await this.appsAbilityFactory.appsActions(user);
if (!ability.can('cloneApp', App)) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
const imports = await this.importExportResourcesService.clone(user, cloneResourcesDto);
return { imports, success: true };
}
}