forked from DhanushNehru/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_users.controller.ts
More file actions
35 lines (30 loc) · 1.25 KB
/
app_users.controller.ts
File metadata and controls
35 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Controller, ForbiddenException, Post, Request, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard';
import { decamelizeKeys } from 'humps';
import { AppsAbilityFactory } from 'src/modules/casl/abilities/apps-ability.factory';
import { AppUsersService } from '@services/app_users.service';
import { AppsService } from '@services/apps.service';
@Controller('app_users')
export class AppUsersController {
constructor(
private appUsersService: AppUsersService,
private appsService: AppsService,
private appsAbilityFactory: AppsAbilityFactory
) {}
// TODO: remove deprecated
@UseGuards(JwtAuthGuard)
@Post()
async create(@Request() req) {
const params = req.body;
const appId = params['app_id'];
const organizationUserId = params['org_user_id'];
const { role } = params;
const app = await this.appsService.find(appId);
const ability = await this.appsAbilityFactory.appsActions(req.user, appId);
if (!ability.can('createUsers', app)) {
throw new ForbiddenException('you do not have permissions to perform this action');
}
const appUser = await this.appUsersService.create(req.user, appId, organizationUserId, role);
return decamelizeKeys(appUser);
}
}