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

78 lines
3.2 KiB
TypeScript
Raw Normal View History

import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
import { decamelizeKeys } from 'humps';
import { JwtAuthGuard } from '../modules/auth/jwt-auth.guard';
import { ForbiddenException } from '@nestjs/common';
import { User } from 'src/decorators/user.decorator';
import { AppEnvironmentService } from '@services/app_environments.service';
import { GlobalDataSourceAbilityFactory } from 'src/modules/casl/abilities/global-datasource-ability.factory';
import { DataSource } from 'src/entities/data_source.entity';
import { OrgEnvironmentVariablesAbilityFactory } from 'src/modules/casl/abilities/org-environment-variables-ability.factory';
import { OrgEnvironmentVariable } from 'src/entities/org_envirnoment_variable.entity';
import { AbilityService } from '@services/permissions-ability.service';
import { AppEnvironmentActionParametersDto } from '@dto/environment_action_parameters.dto';
@Controller('app-environments')
export class AppEnvironmentsController {
constructor(
private appEnvironmentServices: AppEnvironmentService,
private service: AbilityService,
private globalDataSourcesAbilityFactory: GlobalDataSourceAbilityFactory,
private orgEnvironmentVariablesAbilityFactory: OrgEnvironmentVariablesAbilityFactory
) {}
@UseGuards(JwtAuthGuard)
@Get('init')
async init(@User() user, @Query('editing_version_id') editingVersionId: string) {
/*
init is a method in the AppEnvironmentService class that is used to initialize the app environment mananger.
Should not use for any other purpose.
*/
return await this.appEnvironmentServices.init(editingVersionId, user.organizationId);
}
@UseGuards(JwtAuthGuard)
@Post('/post-action/:action')
async environmentActions(
@Param('action') action: string,
@Body() appEnvironmentActionParametersDto: AppEnvironmentActionParametersDto
) {
/*
init is a method in the AppEnvironmentService class that is used to initialize the app environment mananger.
Should not use for any other purpose.
*/
return await this.appEnvironmentServices.processActions(action, appEnvironmentActionParametersDto);
}
@UseGuards(JwtAuthGuard)
@Get()
[Improvements] Environment changes (#6762) * Added priority, enabled, current_environment_id columns - added data-migrations to backfill the priority and current environment id for each version * working on multi environments improvement - added checks for promoted env - promote env feature - released app & production env check - promoted version definition check * added import support * working on migration issues * fixed failing migration * fixed failing migration once again * Fixed possible bugs - seed - test case helpers - app version release * fixed migration bug * working on migration progress * working on migration progress class * added migration progress * fixed unit tests * fixed e2e cases * added default priority * added PR changes * changed import logic * added global datasource design and api changes * changed default env if the id is null * added unique constraint and a bug fix * changed app versions api - added current environment id to the where conditions * fixed failing test cases * added new test cases * added new api changes * added back the enabled check * fixed test case * change: added environment to create versions dto * typo: environmentId * added new api for fetching versions * added appVersions count changes to CE * Changed app versions by environmentid logic * added PR changes for EE * fixed wrong promoted env id issue * fix: can't switch to staging * added import export changes - update delete modal text * added EE import export code, modal updated text * added common migration code for CE and EE * fixes - enable run button for released version - disable change datasource for queries * changed released version popup design to new EE design * add: hide delete icons for released version
2023-07-11 04:40:03 +00:00
async index(@User() user, @Query('app_id') appId: string) {
const ability = await this.globalDataSourcesAbilityFactory.globalDataSourceActions(user);
const orgEnvironmentAbility = await this.orgEnvironmentVariablesAbilityFactory.orgEnvironmentVariableActions(
user,
{}
);
const { organizationId } = user;
if (
!ability.can('fetchEnvironments', DataSource) &&
!orgEnvironmentAbility.can('fetchEnvironments', OrgEnvironmentVariable)
) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
[Improvements] Environment changes (#6762) * Added priority, enabled, current_environment_id columns - added data-migrations to backfill the priority and current environment id for each version * working on multi environments improvement - added checks for promoted env - promote env feature - released app & production env check - promoted version definition check * added import support * working on migration issues * fixed failing migration * fixed failing migration once again * Fixed possible bugs - seed - test case helpers - app version release * fixed migration bug * working on migration progress * working on migration progress class * added migration progress * fixed unit tests * fixed e2e cases * added default priority * added PR changes * changed import logic * added global datasource design and api changes * changed default env if the id is null * added unique constraint and a bug fix * changed app versions api - added current environment id to the where conditions * fixed failing test cases * added new test cases * added new api changes * added back the enabled check * fixed test case * change: added environment to create versions dto * typo: environmentId * added new api for fetching versions * added appVersions count changes to CE * Changed app versions by environmentid logic * added PR changes for EE * fixed wrong promoted env id issue * fix: can't switch to staging * added import export changes - update delete modal text * added EE import export code, modal updated text * added common migration code for CE and EE * fixes - enable run button for released version - disable change datasource for queries * changed released version popup design to new EE design * add: hide delete icons for released version
2023-07-11 04:40:03 +00:00
const environments = await this.appEnvironmentServices.getAll(organizationId, null, appId);
return decamelizeKeys({ environments });
}
[Improvements] Environment changes (#6762) * Added priority, enabled, current_environment_id columns - added data-migrations to backfill the priority and current environment id for each version * working on multi environments improvement - added checks for promoted env - promote env feature - released app & production env check - promoted version definition check * added import support * working on migration issues * fixed failing migration * fixed failing migration once again * Fixed possible bugs - seed - test case helpers - app version release * fixed migration bug * working on migration progress * working on migration progress class * added migration progress * fixed unit tests * fixed e2e cases * added default priority * added PR changes * changed import logic * added global datasource design and api changes * changed default env if the id is null * added unique constraint and a bug fix * changed app versions api - added current environment id to the where conditions * fixed failing test cases * added new test cases * added new api changes * added back the enabled check * fixed test case * change: added environment to create versions dto * typo: environmentId * added new api for fetching versions * added appVersions count changes to CE * Changed app versions by environmentid logic * added PR changes for EE * fixed wrong promoted env id issue * fix: can't switch to staging * added import export changes - update delete modal text * added EE import export code, modal updated text * added common migration code for CE and EE * fixes - enable run button for released version - disable change datasource for queries * changed released version popup design to new EE design * add: hide delete icons for released version
2023-07-11 04:40:03 +00:00
@UseGuards(JwtAuthGuard)
@Get(':id/versions')
async getVersionsByEnvironment(@User() user, @Param('id') environmentId: string, @Query('app_id') appId: string) {
const appVersions = await this.appEnvironmentServices.getVersionsByEnvironment(
user?.organizationId,
appId,
environmentId
);
return { appVersions };
[Improvements] Environment changes (#6762) * Added priority, enabled, current_environment_id columns - added data-migrations to backfill the priority and current environment id for each version * working on multi environments improvement - added checks for promoted env - promote env feature - released app & production env check - promoted version definition check * added import support * working on migration issues * fixed failing migration * fixed failing migration once again * Fixed possible bugs - seed - test case helpers - app version release * fixed migration bug * working on migration progress * working on migration progress class * added migration progress * fixed unit tests * fixed e2e cases * added default priority * added PR changes * changed import logic * added global datasource design and api changes * changed default env if the id is null * added unique constraint and a bug fix * changed app versions api - added current environment id to the where conditions * fixed failing test cases * added new test cases * added new api changes * added back the enabled check * fixed test case * change: added environment to create versions dto * typo: environmentId * added new api for fetching versions * added appVersions count changes to CE * Changed app versions by environmentid logic * added PR changes for EE * fixed wrong promoted env id issue * fix: can't switch to staging * added import export changes - update delete modal text * added EE import export code, modal updated text * added common migration code for CE and EE * fixes - enable run button for released version - disable change datasource for queries * changed released version popup design to new EE design * add: hide delete icons for released version
2023-07-11 04:40:03 +00:00
}
}