mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-16 05:28:28 +00:00
* multi org changes * Initial changes * changes * manage sso page * Multi-organization changes * Multi organization changes * multi-org changes * multi-org changes * multi-org changes * multi-org fixes * env variables app.json changes * multi-org-fix * user invitation token fix * multi-org group permission fix * multi-org app privilege * google oauth fix * Remove enable signup for form login * Multi organization fixes * multi-org user invite flow changes * multi-org sign up fix * rebase and multi-org fixes * revert testing logs * test logs revert * migration changes * migration file fix * error message changes * git login for private email fix * dropdown fix * test cases * e2e test cases added * test cases fix * documentation changes * testcases fix * testcases added * replace findOne with findOneOrFail * accept invite testcases * login page fixes * added encrypted tag * review comments * migration fixes * improvements * manage sso loading fix * review comments * migration file changes * new organization creation bug fix * added e2e testcases * added testcases * Update data_sources.controller.ts
87 lines
3.4 KiB
TypeScript
87 lines
3.4 KiB
TypeScript
import { BadRequestException, Body, Controller, Get, Param, Patch, Post, Request, UseGuards } from '@nestjs/common';
|
|
import { OrganizationsService } from '@services/organizations.service';
|
|
import { decamelizeKeys } from 'humps';
|
|
import { User } from 'src/decorators/user.decorator';
|
|
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
|
|
import { AuthService } from '@services/auth.service';
|
|
import { AppAbility } from 'src/modules/casl/casl-ability.factory';
|
|
import { CheckPolicies } from 'src/modules/casl/check_policies.decorator';
|
|
import { PoliciesGuard } from 'src/modules/casl/policies.guard';
|
|
import { User as UserEntity } from 'src/entities/user.entity';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { MultiOrganizationGuard } from 'src/modules/auth/multi-organization.guard';
|
|
|
|
@Controller('organizations')
|
|
export class OrganizationsController {
|
|
constructor(
|
|
private organizationsService: OrganizationsService,
|
|
private authService: AuthService,
|
|
private readonly configService: ConfigService
|
|
) {}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get('users')
|
|
async getUsers(@Request() req) {
|
|
const result = await this.organizationsService.fetchUsers(req.user);
|
|
return decamelizeKeys({ users: result });
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get()
|
|
async get(@User() user) {
|
|
const result = await this.organizationsService.fetchOrganisations(user);
|
|
return decamelizeKeys({ organizations: result });
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, MultiOrganizationGuard)
|
|
@Post()
|
|
async create(@Body('name') name, @User() user) {
|
|
if (!name) {
|
|
throw new BadRequestException('name can not be empty');
|
|
}
|
|
const result = await this.organizationsService.create(name, user);
|
|
|
|
if (!result) {
|
|
throw new Error();
|
|
}
|
|
return await this.authService.switchOrganization(result.id, user, true);
|
|
}
|
|
|
|
@Get(['/:organizationId/public-configs', '/public-configs'])
|
|
async getOrganizationDetails(@Param('organizationId') organizationId: string) {
|
|
if (!organizationId && this.configService.get<string>('MULTI_ORGANIZATION') !== 'true') {
|
|
// Request from single organization login page - find one from organization and setting
|
|
organizationId = (await this.organizationsService.getSingleOrganization()).id;
|
|
}
|
|
if (!organizationId) {
|
|
throw new BadRequestException();
|
|
}
|
|
|
|
const result = await this.organizationsService.fetchOrganisationDetails(organizationId, [true], true);
|
|
return decamelizeKeys({ ssoConfigs: result });
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, PoliciesGuard)
|
|
@CheckPolicies((ability: AppAbility) => ability.can('updateOrganizations', UserEntity))
|
|
@Get('/configs')
|
|
async getConfigs(@User() user) {
|
|
const result = await this.organizationsService.fetchOrganisationDetails(user.organizationId);
|
|
return decamelizeKeys({ organizationDetails: result });
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, PoliciesGuard)
|
|
@CheckPolicies((ability: AppAbility) => ability.can('updateOrganizations', UserEntity))
|
|
@Patch()
|
|
async update(@Body() body, @User() user) {
|
|
await this.organizationsService.updateOrganization(user.organizationId, body);
|
|
return {};
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, PoliciesGuard)
|
|
@CheckPolicies((ability: AppAbility) => ability.can('updateOrganizations', UserEntity))
|
|
@Patch('/configs')
|
|
async updateConfigs(@Body() body, @User() user) {
|
|
const result: any = await this.organizationsService.updateOrganizationConfigs(user.organizationId, body);
|
|
return decamelizeKeys({ id: result.id });
|
|
}
|
|
}
|