mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
docs: improved auto-generated openapi docs
With these additional annotations the openapi docs under `/apidoc` and `/private/apidoc` will be improved by adding errors that the requests can return Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
2bc8c0d6da
commit
796b8294cf
10 changed files with 183 additions and 34 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -15,9 +15,14 @@ import {
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
|
ApiConflictResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
ApiUnprocessableEntityResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { SessionGuard } from '../../../identity/session.guard';
|
import { SessionGuard } from '../../../identity/session.guard';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
|
@ -29,6 +34,13 @@ import { NotesService } from '../../../notes/notes.service';
|
||||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import { UsersService } from '../../../users/users.service';
|
import { UsersService } from '../../../users/users.service';
|
||||||
|
import {
|
||||||
|
badRequestDescription,
|
||||||
|
conflictDescription,
|
||||||
|
notFoundDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
unprocessableEntityDescription,
|
||||||
|
} from '../../utils/descriptions';
|
||||||
import { RequestUser } from '../../utils/request-user.decorator';
|
import { RequestUser } from '../../utils/request-user.decorator';
|
||||||
|
|
||||||
@UseGuards(SessionGuard)
|
@UseGuards(SessionGuard)
|
||||||
|
@ -46,6 +58,9 @@ export class AliasController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiConflictResponse({ description: conflictDescription })
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async addAlias(
|
async addAlias(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Body() newAliasDto: AliasCreateDto,
|
@Body() newAliasDto: AliasCreateDto,
|
||||||
|
@ -64,6 +79,9 @@ export class AliasController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':alias')
|
@Put(':alias')
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async makeAliasPrimary(
|
async makeAliasPrimary(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('alias') alias: string,
|
@Param('alias') alias: string,
|
||||||
|
@ -84,6 +102,11 @@ export class AliasController {
|
||||||
|
|
||||||
@Delete(':alias')
|
@Delete(':alias')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
|
@ApiUnprocessableEntityResponse({
|
||||||
|
description: unprocessableEntityDescription,
|
||||||
|
})
|
||||||
async removeAlias(
|
async removeAlias(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('alias') alias: string,
|
@Param('alias') alias: string,
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Body,
|
Body,
|
||||||
ConflictException,
|
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Post,
|
Post,
|
||||||
|
@ -14,10 +13,14 @@ import {
|
||||||
Req,
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
|
ApiConflictResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
import { Session } from 'express-session';
|
import { Session } from 'express-session';
|
||||||
|
|
||||||
import { AlreadyInDBError } from '../../../errors/errors';
|
|
||||||
import { IdentityService } from '../../../identity/identity.service';
|
import { IdentityService } from '../../../identity/identity.service';
|
||||||
import { LocalAuthGuard } from '../../../identity/local/local.strategy';
|
import { LocalAuthGuard } from '../../../identity/local/local.strategy';
|
||||||
import { LoginDto } from '../../../identity/local/login.dto';
|
import { LoginDto } from '../../../identity/local/login.dto';
|
||||||
|
@ -27,6 +30,11 @@ import { SessionGuard } from '../../../identity/session.guard';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import { UsersService } from '../../../users/users.service';
|
import { UsersService } from '../../../users/users.service';
|
||||||
|
import {
|
||||||
|
badRequestDescription,
|
||||||
|
conflictDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
} from '../../utils/descriptions';
|
||||||
import { LoginEnabledGuard } from '../../utils/login-enabled.guard';
|
import { LoginEnabledGuard } from '../../utils/login-enabled.guard';
|
||||||
import { RegistrationEnabledGuard } from '../../utils/registration-enabled.guard';
|
import { RegistrationEnabledGuard } from '../../utils/registration-enabled.guard';
|
||||||
import { RequestUser } from '../../utils/request-user.decorator';
|
import { RequestUser } from '../../utils/request-user.decorator';
|
||||||
|
@ -44,29 +52,21 @@ export class AuthController {
|
||||||
|
|
||||||
@UseGuards(RegistrationEnabledGuard)
|
@UseGuards(RegistrationEnabledGuard)
|
||||||
@Post('local')
|
@Post('local')
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
|
@ApiConflictResponse({ description: conflictDescription })
|
||||||
async registerUser(@Body() registerDto: RegisterDto): Promise<void> {
|
async registerUser(@Body() registerDto: RegisterDto): Promise<void> {
|
||||||
try {
|
const user = await this.usersService.createUser(
|
||||||
const user = await this.usersService.createUser(
|
registerDto.username,
|
||||||
registerDto.username,
|
registerDto.displayname,
|
||||||
registerDto.displayname,
|
);
|
||||||
);
|
// ToDo: Figure out how to rollback user if anything with this calls goes wrong
|
||||||
// ToDo: Figure out how to rollback user if anything with this calls goes wrong
|
await this.identityService.createLocalIdentity(user, registerDto.password);
|
||||||
await this.identityService.createLocalIdentity(
|
|
||||||
user,
|
|
||||||
registerDto.password,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} catch (e) {
|
|
||||||
// This special handling can't be omitted since AlreadyInDBErrors get mapped to BadRequestException usually.
|
|
||||||
if (e instanceof AlreadyInDBError) {
|
|
||||||
throw new ConflictException(e.message);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(LoginEnabledGuard, SessionGuard)
|
@UseGuards(LoginEnabledGuard, SessionGuard)
|
||||||
@Put('local')
|
@Put('local')
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
async updatePassword(
|
async updatePassword(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Body() changePasswordDto: UpdatePasswordDto,
|
@Body() changePasswordDto: UpdatePasswordDto,
|
||||||
|
@ -84,6 +84,7 @@ export class AuthController {
|
||||||
|
|
||||||
@UseGuards(LoginEnabledGuard, LocalAuthGuard)
|
@UseGuards(LoginEnabledGuard, LocalAuthGuard)
|
||||||
@Post('local/login')
|
@Post('local/login')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
login(
|
login(
|
||||||
@Req() request: Request & { session: { user: string } },
|
@Req() request: Request & { session: { user: string } },
|
||||||
@Body() loginDto: LoginDto,
|
@Body() loginDto: LoginDto,
|
||||||
|
@ -94,6 +95,7 @@ export class AuthController {
|
||||||
|
|
||||||
@UseGuards(SessionGuard)
|
@UseGuards(SessionGuard)
|
||||||
@Delete('logout')
|
@Delete('logout')
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
logout(@Req() request: Request & { session: Session }): void {
|
logout(@Req() request: Request & { session: Session }): void {
|
||||||
request.session.destroy((err) => {
|
request.session.destroy((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -13,7 +13,11 @@ import {
|
||||||
UseGuards,
|
UseGuards,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { HistoryEntryImportDto } from '../../../../history/history-entry-import.dto';
|
import { HistoryEntryImportDto } from '../../../../history/history-entry-import.dto';
|
||||||
import { HistoryEntryUpdateDto } from '../../../../history/history-entry-update.dto';
|
import { HistoryEntryUpdateDto } from '../../../../history/history-entry-update.dto';
|
||||||
|
@ -23,6 +27,10 @@ import { SessionGuard } from '../../../../identity/session.guard';
|
||||||
import { ConsoleLoggerService } from '../../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../../logger/console-logger.service';
|
||||||
import { Note } from '../../../../notes/note.entity';
|
import { Note } from '../../../../notes/note.entity';
|
||||||
import { User } from '../../../../users/user.entity';
|
import { User } from '../../../../users/user.entity';
|
||||||
|
import {
|
||||||
|
notFoundDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
} from '../../../utils/descriptions';
|
||||||
import { GetNoteInterceptor } from '../../../utils/get-note.interceptor';
|
import { GetNoteInterceptor } from '../../../utils/get-note.interceptor';
|
||||||
import { RequestNote } from '../../../utils/request-note.decorator';
|
import { RequestNote } from '../../../utils/request-note.decorator';
|
||||||
import { RequestUser } from '../../../utils/request-user.decorator';
|
import { RequestUser } from '../../../utils/request-user.decorator';
|
||||||
|
@ -39,6 +47,8 @@ export class HistoryController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async getHistory(@RequestUser() user: User): Promise<HistoryEntryDto[]> {
|
async getHistory(@RequestUser() user: User): Promise<HistoryEntryDto[]> {
|
||||||
const foundEntries = await this.historyService.getEntriesByUser(user);
|
const foundEntries = await this.historyService.getEntriesByUser(user);
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
|
@ -47,6 +57,8 @@ export class HistoryController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async setHistory(
|
async setHistory(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Body('history') history: HistoryEntryImportDto[],
|
@Body('history') history: HistoryEntryImportDto[],
|
||||||
|
@ -55,11 +67,15 @@ export class HistoryController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete()
|
@Delete()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async deleteHistory(@RequestUser() user: User): Promise<void> {
|
async deleteHistory(@RequestUser() user: User): Promise<void> {
|
||||||
await this.historyService.deleteHistory(user);
|
await this.historyService.deleteHistory(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':noteIdOrAlias')
|
@Put(':noteIdOrAlias')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
async updateHistoryEntry(
|
async updateHistoryEntry(
|
||||||
@RequestNote() note: Note,
|
@RequestNote() note: Note,
|
||||||
|
@ -75,6 +91,8 @@ export class HistoryController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':noteIdOrAlias')
|
@Delete(':noteIdOrAlias')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
async deleteHistoryEntry(
|
async deleteHistoryEntry(
|
||||||
@RequestNote() note: Note,
|
@RequestNote() note: Note,
|
||||||
|
|
|
@ -12,7 +12,12 @@ import {
|
||||||
Post,
|
Post,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiInternalServerErrorResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { SessionGuard } from '../../../identity/session.guard';
|
import { SessionGuard } from '../../../identity/session.guard';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
|
@ -21,6 +26,11 @@ import { MediaService } from '../../../media/media.service';
|
||||||
import { UserInfoDto } from '../../../users/user-info.dto';
|
import { UserInfoDto } from '../../../users/user-info.dto';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import { UsersService } from '../../../users/users.service';
|
import { UsersService } from '../../../users/users.service';
|
||||||
|
import {
|
||||||
|
internalServerErrorDescription,
|
||||||
|
notFoundDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
} from '../../utils/descriptions';
|
||||||
import { RequestUser } from '../../utils/request-user.decorator';
|
import { RequestUser } from '../../utils/request-user.decorator';
|
||||||
|
|
||||||
@UseGuards(SessionGuard)
|
@UseGuards(SessionGuard)
|
||||||
|
@ -35,11 +45,13 @@ export class MeController {
|
||||||
this.logger.setContext(MeController.name);
|
this.logger.setContext(MeController.name);
|
||||||
}
|
}
|
||||||
@Get()
|
@Get()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
getMe(@RequestUser() user: User): UserInfoDto {
|
getMe(@RequestUser() user: User): UserInfoDto {
|
||||||
return this.userService.toUserDto(user);
|
return this.userService.toUserDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('media')
|
@Get('media')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
async getMyMedia(@RequestUser() user: User): Promise<MediaUploadDto[]> {
|
async getMyMedia(@RequestUser() user: User): Promise<MediaUploadDto[]> {
|
||||||
const media = await this.mediaService.listUploadsByUser(user);
|
const media = await this.mediaService.listUploadsByUser(user);
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
|
@ -49,6 +61,11 @@ export class MeController {
|
||||||
|
|
||||||
@Delete()
|
@Delete()
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
async deleteUser(@RequestUser() user: User): Promise<void> {
|
async deleteUser(@RequestUser() user: User): Promise<void> {
|
||||||
const mediaUploads = await this.mediaService.listUploadsByUser(user);
|
const mediaUploads = await this.mediaService.listUploadsByUser(user);
|
||||||
for (const mediaUpload of mediaUploads) {
|
for (const mediaUpload of mediaUploads) {
|
||||||
|
@ -61,6 +78,7 @@ export class MeController {
|
||||||
|
|
||||||
@Post('profile')
|
@Post('profile')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
async updateDisplayName(
|
async updateDisplayName(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Body('name') newDisplayName: string,
|
@Body('name') newDisplayName: string,
|
||||||
|
|
|
@ -16,12 +16,15 @@ import {
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import {
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
ApiBody,
|
ApiBody,
|
||||||
ApiConsumes,
|
ApiConsumes,
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiForbiddenResponse,
|
ApiForbiddenResponse,
|
||||||
ApiHeader,
|
ApiHeader,
|
||||||
|
ApiInternalServerErrorResponse,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
ApiTags,
|
ApiTags,
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
@ -36,7 +39,10 @@ import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import {
|
import {
|
||||||
|
badRequestDescription,
|
||||||
forbiddenDescription,
|
forbiddenDescription,
|
||||||
|
internalServerErrorDescription,
|
||||||
|
notFoundDescription,
|
||||||
successfullyDeletedDescription,
|
successfullyDeletedDescription,
|
||||||
unauthorizedDescription,
|
unauthorizedDescription,
|
||||||
} from '../../utils/descriptions';
|
} from '../../utils/descriptions';
|
||||||
|
@ -72,14 +78,19 @@ export class MediaController {
|
||||||
name: 'HedgeDoc-Note',
|
name: 'HedgeDoc-Note',
|
||||||
description: 'ID or alias of the parent note',
|
description: 'ID or alias of the parent note',
|
||||||
})
|
})
|
||||||
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
|
@HttpCode(201)
|
||||||
@ApiCreatedResponse({
|
@ApiCreatedResponse({
|
||||||
description: 'The file was uploaded successfully',
|
description: 'The file was uploaded successfully',
|
||||||
type: MediaUploadUrlDto,
|
type: MediaUploadUrlDto,
|
||||||
})
|
})
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
@ApiForbiddenResponse({ description: forbiddenDescription })
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@HttpCode(201)
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
async uploadMedia(
|
async uploadMedia(
|
||||||
@UploadedFile() file: MulterFile,
|
@UploadedFile() file: MulterFile,
|
||||||
@Headers('HedgeDoc-Note') noteId: string,
|
@Headers('HedgeDoc-Note') noteId: string,
|
||||||
|
@ -99,6 +110,9 @@ export class MediaController {
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
||||||
@FullApi
|
@FullApi
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
async deleteMedia(
|
async deleteMedia(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('filename') filename: string,
|
@Param('filename') filename: string,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -14,7 +14,14 @@ import {
|
||||||
UseGuards,
|
UseGuards,
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
|
ApiConflictResponse,
|
||||||
|
ApiInternalServerErrorResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { HistoryService } from '../../../history/history.service';
|
import { HistoryService } from '../../../history/history.service';
|
||||||
import { SessionGuard } from '../../../identity/session.guard';
|
import { SessionGuard } from '../../../identity/session.guard';
|
||||||
|
@ -32,6 +39,13 @@ import { RevisionDto } from '../../../revisions/revision.dto';
|
||||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import { UsersService } from '../../../users/users.service';
|
import { UsersService } from '../../../users/users.service';
|
||||||
|
import {
|
||||||
|
badRequestDescription,
|
||||||
|
conflictDescription,
|
||||||
|
internalServerErrorDescription,
|
||||||
|
notFoundDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
} from '../../utils/descriptions';
|
||||||
import { GetNoteInterceptor } from '../../utils/get-note.interceptor';
|
import { GetNoteInterceptor } from '../../utils/get-note.interceptor';
|
||||||
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
||||||
import { PermissionsGuard } from '../../utils/permissions.guard';
|
import { PermissionsGuard } from '../../utils/permissions.guard';
|
||||||
|
@ -54,6 +68,7 @@ export class NotesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':noteIdOrAlias')
|
@Get(':noteIdOrAlias')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@Permissions(Permission.READ)
|
@Permissions(Permission.READ)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -66,6 +81,7 @@ export class NotesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':noteIdOrAlias/media')
|
@Get(':noteIdOrAlias/media')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@Permissions(Permission.READ)
|
@Permissions(Permission.READ)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -78,6 +94,7 @@ export class NotesController {
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@HttpCode(201)
|
@HttpCode(201)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@Permissions(Permission.CREATE)
|
@Permissions(Permission.CREATE)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
async createNote(
|
async createNote(
|
||||||
|
@ -92,6 +109,10 @@ export class NotesController {
|
||||||
|
|
||||||
@Post(':noteAlias')
|
@Post(':noteAlias')
|
||||||
@HttpCode(201)
|
@HttpCode(201)
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
|
@ApiConflictResponse({ description: conflictDescription })
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@Permissions(Permission.CREATE)
|
@Permissions(Permission.CREATE)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
async createNamedNote(
|
async createNamedNote(
|
||||||
|
@ -107,6 +128,11 @@ export class NotesController {
|
||||||
|
|
||||||
@Delete(':noteIdOrAlias')
|
@Delete(':noteIdOrAlias')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
@Permissions(Permission.OWNER)
|
@Permissions(Permission.OWNER)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -130,6 +156,8 @@ export class NotesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':noteIdOrAlias/revisions')
|
@Get(':noteIdOrAlias/revisions')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@Permissions(Permission.READ)
|
@Permissions(Permission.READ)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -147,6 +175,8 @@ export class NotesController {
|
||||||
|
|
||||||
@Delete(':noteIdOrAlias/revisions')
|
@Delete(':noteIdOrAlias/revisions')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@Permissions(Permission.READ)
|
@Permissions(Permission.READ)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -167,6 +197,8 @@ export class NotesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':noteIdOrAlias/revisions/:revisionId')
|
@Get(':noteIdOrAlias/revisions/:revisionId')
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
@Permissions(Permission.READ)
|
@Permissions(Permission.READ)
|
||||||
@UseInterceptors(GetNoteInterceptor)
|
@UseInterceptors(GetNoteInterceptor)
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
|
|
@ -14,7 +14,11 @@ import {
|
||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiTags,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
|
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
|
||||||
import { AuthTokenDto } from '../../../auth/auth-token.dto';
|
import { AuthTokenDto } from '../../../auth/auth-token.dto';
|
||||||
|
@ -23,6 +27,10 @@ import { SessionGuard } from '../../../identity/session.guard';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import { TimestampMillis } from '../../../utils/timestamp';
|
import { TimestampMillis } from '../../../utils/timestamp';
|
||||||
|
import {
|
||||||
|
notFoundDescription,
|
||||||
|
unauthorizedDescription,
|
||||||
|
} from '../../utils/descriptions';
|
||||||
import { RequestUser } from '../../utils/request-user.decorator';
|
import { RequestUser } from '../../utils/request-user.decorator';
|
||||||
|
|
||||||
@UseGuards(SessionGuard)
|
@UseGuards(SessionGuard)
|
||||||
|
@ -37,6 +45,7 @@ export class TokensController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
async getUserTokens(@RequestUser() user: User): Promise<AuthTokenDto[]> {
|
async getUserTokens(@RequestUser() user: User): Promise<AuthTokenDto[]> {
|
||||||
return (await this.authService.getTokensByUser(user)).map((token) =>
|
return (await this.authService.getTokensByUser(user)).map((token) =>
|
||||||
this.authService.toAuthTokenDto(token),
|
this.authService.toAuthTokenDto(token),
|
||||||
|
@ -44,6 +53,7 @@ export class TokensController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
async postTokenRequest(
|
async postTokenRequest(
|
||||||
@Body('label') label: string,
|
@Body('label') label: string,
|
||||||
@Body('validUntil') validUntil: TimestampMillis,
|
@Body('validUntil') validUntil: TimestampMillis,
|
||||||
|
@ -54,6 +64,8 @@ export class TokensController {
|
||||||
|
|
||||||
@Delete('/:keyId')
|
@Delete('/:keyId')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
async deleteToken(
|
async deleteToken(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('keyId') keyId: string,
|
@Param('keyId') keyId: string,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -20,6 +20,7 @@ import {
|
||||||
ApiOkResponse,
|
ApiOkResponse,
|
||||||
ApiSecurity,
|
ApiSecurity,
|
||||||
ApiTags,
|
ApiTags,
|
||||||
|
ApiUnprocessableEntityResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
|
@ -31,6 +32,7 @@ import { AliasService } from '../../../notes/alias.service';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
|
import { unprocessableEntityDescription } from '../../utils/descriptions';
|
||||||
import { FullApi } from '../../utils/fullapi-decorator';
|
import { FullApi } from '../../utils/fullapi-decorator';
|
||||||
import { RequestUser } from '../../utils/request-user.decorator';
|
import { RequestUser } from '../../utils/request-user.decorator';
|
||||||
|
|
||||||
|
@ -101,6 +103,9 @@ export class AliasController {
|
||||||
description: 'The alias was deleted',
|
description: 'The alias was deleted',
|
||||||
})
|
})
|
||||||
@FullApi
|
@FullApi
|
||||||
|
@ApiUnprocessableEntityResponse({
|
||||||
|
description: unprocessableEntityDescription,
|
||||||
|
})
|
||||||
async removeAlias(
|
async removeAlias(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@Param('alias') alias: string,
|
@Param('alias') alias: string,
|
||||||
|
|
|
@ -16,12 +16,15 @@ import {
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import {
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
ApiBody,
|
ApiBody,
|
||||||
ApiConsumes,
|
ApiConsumes,
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiForbiddenResponse,
|
ApiForbiddenResponse,
|
||||||
ApiHeader,
|
ApiHeader,
|
||||||
|
ApiInternalServerErrorResponse,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
ApiSecurity,
|
ApiSecurity,
|
||||||
ApiTags,
|
ApiTags,
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
|
@ -37,7 +40,10 @@ import { Note } from '../../../notes/note.entity';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import {
|
import {
|
||||||
|
badRequestDescription,
|
||||||
forbiddenDescription,
|
forbiddenDescription,
|
||||||
|
internalServerErrorDescription,
|
||||||
|
notFoundDescription,
|
||||||
successfullyDeletedDescription,
|
successfullyDeletedDescription,
|
||||||
unauthorizedDescription,
|
unauthorizedDescription,
|
||||||
} from '../../utils/descriptions';
|
} from '../../utils/descriptions';
|
||||||
|
@ -78,8 +84,13 @@ export class MediaController {
|
||||||
description: 'The file was uploaded successfully',
|
description: 'The file was uploaded successfully',
|
||||||
type: MediaUploadUrlDto,
|
type: MediaUploadUrlDto,
|
||||||
})
|
})
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
@ApiForbiddenResponse({ description: forbiddenDescription })
|
||||||
|
@ApiNotFoundResponse({ description: notFoundDescription })
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
@HttpCode(201)
|
@HttpCode(201)
|
||||||
async uploadMedia(
|
async uploadMedia(
|
||||||
|
@ -100,6 +111,9 @@ export class MediaController {
|
||||||
@Delete(':filename')
|
@Delete(':filename')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
@FullApi
|
@FullApi
|
||||||
async deleteMedia(
|
async deleteMedia(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -17,8 +17,11 @@ import {
|
||||||
UseInterceptors,
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
|
ApiBadRequestResponse,
|
||||||
|
ApiConflictResponse,
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiForbiddenResponse,
|
ApiForbiddenResponse,
|
||||||
|
ApiInternalServerErrorResponse,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
ApiOkResponse,
|
ApiOkResponse,
|
||||||
ApiProduces,
|
ApiProduces,
|
||||||
|
@ -48,7 +51,10 @@ import { RevisionDto } from '../../../revisions/revision.dto';
|
||||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
import { User } from '../../../users/user.entity';
|
import { User } from '../../../users/user.entity';
|
||||||
import {
|
import {
|
||||||
|
badRequestDescription,
|
||||||
|
conflictDescription,
|
||||||
forbiddenDescription,
|
forbiddenDescription,
|
||||||
|
internalServerErrorDescription,
|
||||||
successfullyDeletedDescription,
|
successfullyDeletedDescription,
|
||||||
unauthorizedDescription,
|
unauthorizedDescription,
|
||||||
} from '../../utils/descriptions';
|
} from '../../utils/descriptions';
|
||||||
|
@ -115,6 +121,8 @@ export class NotesController {
|
||||||
description: 'Get information about the newly created note',
|
description: 'Get information about the newly created note',
|
||||||
type: NoteDto,
|
type: NoteDto,
|
||||||
})
|
})
|
||||||
|
@ApiBadRequestResponse({ description: badRequestDescription })
|
||||||
|
@ApiConflictResponse({ description: conflictDescription })
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
@ApiForbiddenResponse({ description: forbiddenDescription })
|
||||||
async createNamedNote(
|
async createNamedNote(
|
||||||
|
@ -135,6 +143,9 @@ export class NotesController {
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
||||||
@FullApi
|
@FullApi
|
||||||
|
@ApiInternalServerErrorResponse({
|
||||||
|
description: internalServerErrorDescription,
|
||||||
|
})
|
||||||
async deleteNote(
|
async deleteNote(
|
||||||
@RequestUser() user: User,
|
@RequestUser() user: User,
|
||||||
@RequestNote() note: Note,
|
@RequestNote() note: Note,
|
||||||
|
|
Loading…
Reference in a new issue