ToolJet/server/src/controllers/app_import_export.controller.ts
Akshay cc516b9ddc
Feature: Versioned exports (#4140)
* add ability to export app versions

* remove console.log

* add spec

* [ Enhancement ]: Ability to export versioned apps ( frontend ) (#4271)

* added basic UI and functionality

* added functionality to export all versions or selected versions of app

* added UI

* refactored the code

* refactored code

* use custom hook for checking if component is mounted or not and accessing  darkMode from props

* showing current version first

* added spacing between container and input tag and input tag and text

* added cursor pointer on the version container

* removed use mount to avoid extra re-rendering component

* fixed typo request

* update permissions

* fix permissions

Co-authored-by: Manish Kushare <kushare.manish9@gmail.com>
2022-12-02 14:13:28 +05:30

46 lines
1.7 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';
@Controller('apps')
export class AppsImportExportController {
constructor(
private appsService: AppsService,
private appImportExportService: AppImportExportService,
private appsAbilityFactory: AppsAbilityFactory
) {}
@UseGuards(JwtAuthGuard)
@Post('/import')
async import(@User() user, @Body() body) {
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 app = await this.appImportExportService.import(user, body);
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,
};
}
}