mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 00:24:43 -04:00
NotesController: Catch NotInDBErrors from permission checks
The permission check also tries to get the note and a non existing note needs to be handled there too. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
9ac4134198
commit
3953f6893b
1 changed files with 32 additions and 32 deletions
|
@ -111,21 +111,21 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.isOwner(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Deleting note denied!');
|
|
||||||
}
|
|
||||||
this.logger.debug('Deleting note: ' + noteIdOrAlias, 'deleteNote');
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.isOwner(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Deleting note denied!');
|
||||||
|
}
|
||||||
|
this.logger.debug('Deleting note: ' + noteIdOrAlias, 'deleteNote');
|
||||||
await this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
await this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
this.logger.debug('Successfully deleted ' + noteIdOrAlias, 'deleteNote');
|
||||||
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
throw new NotFoundException(e.message);
|
throw new NotFoundException(e.message);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
this.logger.debug('Successfully deleted ' + noteIdOrAlias, 'deleteNote');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
|
@ -135,12 +135,12 @@ export class NotesController {
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@MarkdownBody() text: string,
|
@MarkdownBody() text: string,
|
||||||
): Promise<NoteDto> {
|
): Promise<NoteDto> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.mayWrite(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Updating note denied!');
|
|
||||||
}
|
|
||||||
this.logger.debug('Got raw markdown:\n' + text, 'updateNote');
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.mayWrite(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Updating note denied!');
|
||||||
|
}
|
||||||
|
this.logger.debug('Got raw markdown:\n' + text, 'updateNote');
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text),
|
await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text),
|
||||||
);
|
);
|
||||||
|
@ -159,11 +159,11 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.mayRead(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
|
}
|
||||||
return await this.noteService.getNoteContent(noteIdOrAlias);
|
return await this.noteService.getNoteContent(noteIdOrAlias);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -179,11 +179,11 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
): Promise<NoteMetadataDto> {
|
): Promise<NoteMetadataDto> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.mayRead(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
|
}
|
||||||
return this.noteService.toNoteMetadataDto(
|
return this.noteService.toNoteMetadataDto(
|
||||||
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias),
|
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias),
|
||||||
);
|
);
|
||||||
|
@ -202,11 +202,11 @@ export class NotesController {
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@Body() updateDto: NotePermissionsUpdateDto,
|
@Body() updateDto: NotePermissionsUpdateDto,
|
||||||
): Promise<NotePermissionsDto> {
|
): Promise<NotePermissionsDto> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.isOwner(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Updating note denied!');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.isOwner(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Updating note denied!');
|
||||||
|
}
|
||||||
return this.noteService.toNotePermissionsDto(
|
return this.noteService.toNotePermissionsDto(
|
||||||
await this.noteService.updateNotePermissions(noteIdOrAlias, updateDto),
|
await this.noteService.updateNotePermissions(noteIdOrAlias, updateDto),
|
||||||
);
|
);
|
||||||
|
@ -224,11 +224,11 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
): Promise<RevisionMetadataDto[]> {
|
): Promise<RevisionMetadataDto[]> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.mayRead(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
|
}
|
||||||
const revisions = await this.revisionsService.getAllRevisions(
|
const revisions = await this.revisionsService.getAllRevisions(
|
||||||
noteIdOrAlias,
|
noteIdOrAlias,
|
||||||
);
|
);
|
||||||
|
@ -252,11 +252,11 @@ export class NotesController {
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@Param('revisionId') revisionId: number,
|
@Param('revisionId') revisionId: number,
|
||||||
): Promise<RevisionDto> {
|
): Promise<RevisionDto> {
|
||||||
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
|
||||||
if (!this.permissionsService.mayRead(req.user, note)) {
|
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const note = await this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||||
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
|
}
|
||||||
return this.revisionsService.toRevisionDto(
|
return this.revisionsService.toRevisionDto(
|
||||||
await this.revisionsService.getRevision(noteIdOrAlias, revisionId),
|
await this.revisionsService.getRevision(noteIdOrAlias, revisionId),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue