ToolJet/server/src/controllers/app_import_export.controller.ts
Anantshree Chandola 03e3fd950b
New Improved App creation flow (#7209)
* App creation flow

* Add separate footer and divider

* added create app dto, updated tests

* update test

* Update server/src/dto/app-create.dto.ts

Co-authored-by: Midhun G S <gsmithun4@gmail.com>

* Update server/src/dto/app-create.dto.ts

Co-authored-by: Midhun G S <gsmithun4@gmail.com>

* updates

* Removed comments

* small updates

* rename app flow

* Import App, Create App From Template, Clone App (BE+FE)

* Edit app updates

* remove comments

* updates

* updates

* styling updates

* handle spaces in app name

* update

* styling updates

* Update permissions

* updates

* don't show toast failure message

* Update frontend/src/Editor/Header/EditAppName.jsx

Co-authored-by: Muhsin Shah C P  <muhsinshah21@gmail.com>

* styling updates

* Update server/src/controllers/app_import_export.controller.ts

Co-authored-by: Muhsin Shah C P  <muhsinshah21@gmail.com>

* remove comments

* remove comments and small corrections

* removed logs and deleted unwanted files

* correct lint error

* resolve failing tests + handled trimmed app names

* resolve failing tests + handle trimmed app names

* updates

* duplicate imports removed

* updates

* Rebase corrections and updates

* update

* resolve failing e2e test

* fix error

* fix

* length fix

* fix

---------

Co-authored-by: Midhun G S <gsmithun4@gmail.com>
Co-authored-by: Muhsin Shah C P <muhsinshah21@gmail.com>
2023-10-17 13:18:18 +05:30

48 lines
1.8 KiB
TypeScript

import { Controller, ForbiddenException, Get, Param, Post, Query, UseGuards, Body } from '@nestjs/common';
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
import { AppsService } from '../services/apps.service';
import { decamelizeKeys } from 'humps';
import { AppsAbilityFactory } from 'src/modules/casl/abilities/apps-ability.factory';
import { App } from 'src/entities/app.entity';
import { AppImportExportService } from '@services/app_import_export.service';
import { User } from 'src/decorators/user.decorator';
import { AppImportDto } from '@dto/app-import.dto';
@Controller('apps')
export class AppsImportExportController {
constructor(
private appsService: AppsService,
private appImportExportService: AppImportExportService,
private appsAbilityFactory: AppsAbilityFactory
) {}
@UseGuards(JwtAuthGuard)
@Post('/import')
async import(@User() user, @Body() appImportDto: AppImportDto) {
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 { name: appName, app: appContent } = appImportDto;
const app = await this.appImportExportService.import(user, appContent, appName);
return decamelizeKeys(app);
}
@UseGuards(JwtAuthGuard)
@Get(':id/export')
async export(@User() user, @Param('id') id, @Query() query) {
const appToExport = await this.appsService.find(id);
const ability = await this.appsAbilityFactory.appsActions(user, id);
if (!ability.can('cloneApp', appToExport)) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
const app = await this.appImportExportService.export(user, id, query);
return {
...app,
tooljetVersion: globalThis.TOOLJET_VERSION,
};
}
}