fix: fix guard

pull/26/head
fantasticit 2022-04-11 22:24:09 +08:00
parent 806467c5e4
commit 1a9b565572
1 changed files with 17 additions and 4 deletions

View File

@ -25,8 +25,6 @@ import { UpdateWikiDto } from '@dtos/update-wiki.dto';
import { ShareWikiDto } from '@dtos/share-wiki.dto'; import { ShareWikiDto } from '@dtos/share-wiki.dto';
@Controller('wiki') @Controller('wiki')
@UseGuards(WikiUserRoleGuard)
@UseGuards(WikiStatusGuard)
export class WikiController { export class WikiController {
constructor(private readonly wikiService: WikiService) {} constructor(private readonly wikiService: WikiService) {}
@ -96,6 +94,7 @@ export class WikiController {
@Get('detail/:id') @Get('detail/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole() @CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getWikiDetail(@Request() req, @Param('id') wikiId) { async getWikiDetail(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDetail(req.user, wikiId); return await this.wikiService.getWikiDetail(req.user, wikiId);
@ -111,6 +110,7 @@ export class WikiController {
@Get('homedoc/:id') @Get('homedoc/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole() @CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getWikiHomeDocument(@Request() req, @Param('id') wikiId) { async getWikiHomeDocument(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiHomeDocument(req.user, wikiId); return await this.wikiService.getWikiHomeDocument(req.user, wikiId);
@ -128,6 +128,7 @@ export class WikiController {
@Patch('update/:id') @Patch('update/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async updateWiki(@Request() req, @Param('id') wikiId, @Body() dto: UpdateWikiDto) { async updateWiki(@Request() req, @Param('id') wikiId, @Body() dto: UpdateWikiDto) {
return await this.wikiService.updateWiki(req.user, wikiId, dto); return await this.wikiService.updateWiki(req.user, wikiId, dto);
@ -144,6 +145,7 @@ export class WikiController {
@Delete('delete/:id') @Delete('delete/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async deleteWiki(@Request() req, @Param('id') wikiId) { async deleteWiki(@Request() req, @Param('id') wikiId) {
return await this.wikiService.deleteWiki(req.user, wikiId); return await this.wikiService.deleteWiki(req.user, wikiId);
@ -160,6 +162,7 @@ export class WikiController {
@Get('user/:id') @Get('user/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getWikiUsers(@Param('id') wikiId) { async getWikiUsers(@Param('id') wikiId) {
return await this.wikiService.getWikiUsers(wikiId); return await this.wikiService.getWikiUsers(wikiId);
@ -177,6 +180,7 @@ export class WikiController {
@Post('user/:id/add') @Post('user/:id/add')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async addWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) { async addWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
return await this.wikiService.addWikiUser(req.user, wikiId, dto); return await this.wikiService.addWikiUser(req.user, wikiId, dto);
@ -194,6 +198,7 @@ export class WikiController {
@Post('user/:id/update') @Post('user/:id/update')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async updateWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) { async updateWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
return await this.wikiService.updateWikiUser(req.user, wikiId, dto); return await this.wikiService.updateWikiUser(req.user, wikiId, dto);
@ -211,6 +216,7 @@ export class WikiController {
@Post('user/:id/delete') @Post('user/:id/delete')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async deleteWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) { async deleteWikiUser(@Request() req, @Param('id') wikiId, @Body() dto: WikiUserDto) {
return await this.wikiService.deleteWikiUser(req.user, wikiId, dto); return await this.wikiService.deleteWikiUser(req.user, wikiId, dto);
@ -228,6 +234,7 @@ export class WikiController {
@Post('share/:id') @Post('share/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole(WikiUserRole.admin) @CheckWikiUserRole(WikiUserRole.admin)
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async toggleWorkspaceStatus(@Request() req, @Param('id') wikiId, @Body() dto: ShareWikiDto) { async toggleWorkspaceStatus(@Request() req, @Param('id') wikiId, @Body() dto: ShareWikiDto) {
return await this.wikiService.shareWiki(req.user, wikiId, dto); return await this.wikiService.shareWiki(req.user, wikiId, dto);
@ -243,6 +250,7 @@ export class WikiController {
@Get('tocs/:id') @Get('tocs/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole() @CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getWikiTocs(@Request() req, @Param('id') wikiId) { async getWikiTocs(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiTocs(req.user, wikiId); return await this.wikiService.getWikiTocs(req.user, wikiId);
@ -259,6 +267,7 @@ export class WikiController {
@Post('tocs/:id/update') @Post('tocs/:id/update')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole() @CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async orderWikiTocs(@Body() relations) { async orderWikiTocs(@Body() relations) {
return await this.wikiService.orderWikiTocs(relations); return await this.wikiService.orderWikiTocs(relations);
@ -274,6 +283,7 @@ export class WikiController {
@Get('docs/:id') @Get('docs/:id')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@CheckWikiUserRole() @CheckWikiUserRole()
@UseGuards(WikiUserRoleGuard)
@UseGuards(JwtGuard) @UseGuards(JwtGuard)
async getWikiDocs(@Request() req, @Param('id') wikiId) { async getWikiDocs(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getWikiDocs(req.user, wikiId); return await this.wikiService.getWikiDocs(req.user, wikiId);
@ -288,6 +298,7 @@ export class WikiController {
@UseInterceptors(ClassSerializerInterceptor) @UseInterceptors(ClassSerializerInterceptor)
@Get('public/homedoc/:id') @Get('public/homedoc/:id')
@CheckWikiStatus(WikiStatus.public) @CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async getWikiPublicHomeDocument(@Request() req, @Param('id') wikiId) { async getWikiPublicHomeDocument(@Request() req, @Param('id') wikiId) {
return await this.wikiService.getPublicWikiHomeDocument(wikiId, req.headers['user-agent']); return await this.wikiService.getPublicWikiHomeDocument(wikiId, req.headers['user-agent']);
@ -301,6 +312,7 @@ export class WikiController {
@UseInterceptors(ClassSerializerInterceptor) @UseInterceptors(ClassSerializerInterceptor)
@Post('public/detail/:id') @Post('public/detail/:id')
@CheckWikiStatus(WikiStatus.public) @CheckWikiStatus(WikiStatus.public)
@UseGuards(WikiStatusGuard)
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async getPublicWorkspaceDetail(@Param('id') wikiId) { async getPublicWorkspaceDetail(@Param('id') wikiId) {
return await this.wikiService.getPublicWikiDetail(wikiId); return await this.wikiService.getPublicWikiDetail(wikiId);
@ -312,9 +324,10 @@ export class WikiController {
* @returns * @returns
*/ */
@UseInterceptors(ClassSerializerInterceptor) @UseInterceptors(ClassSerializerInterceptor)
@HttpCode(HttpStatus.OK)
@Post('public/tocs/:id') @Post('public/tocs/:id')
@CheckWikiStatus(WikiStatus.public) @CheckWikiStatus(WikiStatus.public)
@HttpCode(HttpStatus.OK) @UseGuards(WikiStatusGuard)
async getPublicWikiTocs(@Param('id') wikiId) { async getPublicWikiTocs(@Param('id') wikiId) {
return await this.wikiService.getPublicWikiTocs(wikiId); return await this.wikiService.getPublicWikiTocs(wikiId);
} }
@ -325,8 +338,8 @@ export class WikiController {
* @returns * @returns
*/ */
@UseInterceptors(ClassSerializerInterceptor) @UseInterceptors(ClassSerializerInterceptor)
@Get('public/wikis')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
@Get('public/wikis')
async getAllPublicWikis(@Query() pagination: IPagination) { async getAllPublicWikis(@Query() pagination: IPagination) {
return await this.wikiService.getAllPublicWikis(pagination); return await this.wikiService.getAllPublicWikis(pagination);
} }