43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import {
|
|
BadRequestException,
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOAuth2, ApiTags } from '@nestjs/swagger';
|
|
import { Privileges } from 'src/decorators/privileges.decorator';
|
|
import { Scopes } from 'src/decorators/scopes.decorator';
|
|
import { OAuth2Guard } from 'src/guards/oauth2.guard';
|
|
import { PrivilegesGuard } from 'src/guards/privileges.guard';
|
|
import { ScopesGuard } from 'src/guards/scopes.guard';
|
|
import { PrivilegeService } from 'src/modules/objects/privilege/privilege.service';
|
|
|
|
@ApiBearerAuth()
|
|
@ApiTags('admin')
|
|
@ApiOAuth2(['management'])
|
|
@Controller('/api/admin/privileges')
|
|
@UseGuards(OAuth2Guard, PrivilegesGuard, ScopesGuard)
|
|
export class PrivilegeAdminController {
|
|
constructor(private _privilege: PrivilegeService) {}
|
|
|
|
@Get('')
|
|
@Scopes('management')
|
|
@Privileges('admin', 'admin:user', 'admin:user:privilege')
|
|
async privilegeList() {
|
|
return this._privilege.getAllPrivileges();
|
|
}
|
|
|
|
@Post('')
|
|
@Scopes('management')
|
|
@Privileges('admin', 'admin:user', 'admin:user:privilege')
|
|
async newPrivilege(@Body() body: { privilege: string }) {
|
|
if (!body.privilege) {
|
|
throw new BadRequestException('Privilege is required');
|
|
}
|
|
|
|
return this._privilege.createPrivilege(body.privilege);
|
|
}
|
|
}
|