src/iam/policy/policy.controller.ts
policy
Methods |
|
| Async createPolicy | |||||||||
createPolicy(policy: CreatePolicyDto, request)
|
|||||||||
Decorators :
@Post()
|
|||||||||
|
Defined in src/iam/policy/policy.controller.ts:24
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async deletePolicy | |||||||||
deletePolicy(name: string, request)
|
|||||||||
Decorators :
@Delete(':name')
|
|||||||||
|
Defined in src/iam/policy/policy.controller.ts:43
|
|||||||||
|
Parameters :
Returns :
Promise<Policy>
|
| getTuroPermissions | ||||||
getTuroPermissions(req)
|
||||||
Decorators :
@Get('turo-permissions')
|
||||||
|
Defined in src/iam/policy/policy.controller.ts:79
|
||||||
|
this function gets list of policies attached to user role
Parameters :
Returns :
Promise<object>
|
| getUserPolicies | ||||||
getUserPolicies(req)
|
||||||
Decorators :
@Get()
|
||||||
|
Defined in src/iam/policy/policy.controller.ts:68
|
||||||
|
this function gets list of policies attached to user role
Parameters :
Returns :
Promise<object>
|
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
ValidationPipe,
Request,
UnauthorizedException,
} from "@nestjs/common";
import { ApiBearerAuth } from "@nestjs/swagger";
import { CreatePolicyDto } from "./dto/create-policy.dto";
import { PolicyService } from "./policy.service";
import { Policy } from "./types/policy.interface";
import { IAM_CREATE_POLICY_ACTION, IAM_DELETE_POLICY_ACTION, IAM_RESOURCE_NAME } from "../iam.constants";
@ApiBearerAuth("access-token") // this appends authorization header for swagger UI
@Controller("policy")
export class PolicyController {
constructor(private readonly policyService: PolicyService) {}
@Post()
async createPolicy(
@Body(ValidationPipe) policy: CreatePolicyDto,
@Request() request,
) {
if (
!(await this.policyService.checkPermission(
request.user.permission,
0,
IAM_RESOURCE_NAME,
IAM_CREATE_POLICY_ACTION,
))
) {
throw new UnauthorizedException();
}
return this.policyService.createPolicy(policy);
}
@Delete(":name")
async deletePolicy(
@Param("name") name: string,
@Request() request,
): Promise<Policy> {
if (
!(await this.policyService.checkPermission(
request.user.permission,
0,
IAM_RESOURCE_NAME,
IAM_DELETE_POLICY_ACTION,
))
) {
throw new UnauthorizedException();
}
return this.policyService.deletePolicy({ name: name });
}
/**
* this function gets list of policies attached to
* user role
* @param req Request header and body
* @returns {Promise<object>}
*/
@Get()
getUserPolicies(@Request() req): Promise<object> {
return this.policyService.getUserPolicies(req.user.id);
}
/**
* this function gets list of policies attached to
* user role
* @param req Request header and body
* @returns {Promise<object>}
*/
@Get("turo-permissions")
getTuroPermissions(@Request() req): Promise<object> {
return this.policyService.getTuroPermissions(req.user.id);
}
}