mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
Add new API to purge note history #1064
Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com> Combine the describe block Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com> Fix naming Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com> Rename purgeRevision to purgeRevisions Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com> Fix notes e2e test description Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com> Add yarn.lock Fix lint and format Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>
This commit is contained in:
parent
170f4f6759
commit
f63a2b79b7
4 changed files with 147 additions and 0 deletions
|
@ -182,6 +182,39 @@ export class NotesController {
|
|||
}
|
||||
}
|
||||
|
||||
@Delete(':noteIdOrAlias/revisions')
|
||||
@HttpCode(204)
|
||||
async purgeNoteRevisions(
|
||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||
): Promise<void> {
|
||||
try {
|
||||
// ToDo: use actual user here
|
||||
const user = await this.userService.getUserByUsername('hardcoded');
|
||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
if (!this.permissionsService.mayRead(user, note)) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
this.logger.debug(
|
||||
'Purging history of note: ' + noteIdOrAlias,
|
||||
'purgeNoteRevisions',
|
||||
);
|
||||
await this.revisionsService.purgeRevisions(note);
|
||||
this.logger.debug(
|
||||
'Successfully purged history of note ' + noteIdOrAlias,
|
||||
'purgeNoteRevisions',
|
||||
);
|
||||
return;
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
}
|
||||
if (e instanceof ForbiddenIdError) {
|
||||
throw new BadRequestException(e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':noteIdOrAlias/revisions/:revisionId')
|
||||
async getNoteRevision(
|
||||
@Param('noteIdOrAlias', GetNotePipe) note: Note,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue