mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 06:34:39 -04:00
refactor: use "extractNoteFromRequest" in permission guard
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
ab5aebc9c4
commit
b1dc383a7a
1 changed files with 8 additions and 6 deletions
|
@ -6,7 +6,7 @@
|
||||||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
|
|
||||||
import { getNote } from '../api/utils/get-note.interceptor';
|
import { extractNoteFromRequest } from '../api/utils/extract-note-from-request';
|
||||||
import { CompleteRequest } from '../api/utils/request.type';
|
import { CompleteRequest } from '../api/utils/request.type';
|
||||||
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../logger/console-logger.service';
|
||||||
import { NotesService } from '../notes/notes.service';
|
import { NotesService } from '../notes/notes.service';
|
||||||
|
@ -48,12 +48,14 @@ export class PermissionsGuard implements CanActivate {
|
||||||
if (permissions[0] === Permission.CREATE) {
|
if (permissions[0] === Permission.CREATE) {
|
||||||
return this.permissionsService.mayCreate(user);
|
return this.permissionsService.mayCreate(user);
|
||||||
}
|
}
|
||||||
// Get the note from the parameter noteIdOrAlias or the http header hedgedoc-note
|
|
||||||
// Attention: This gets the note an additional time if used in conjunction with GetNoteInterceptor or NoteHeaderInterceptor
|
// Attention: This gets the note an additional time if used in conjunction with GetNoteInterceptor or NoteHeaderInterceptor
|
||||||
let noteIdOrAlias = request.params['noteIdOrAlias'];
|
const note = await extractNoteFromRequest(request, this.noteService);
|
||||||
if (noteIdOrAlias === undefined)
|
if (note === undefined) {
|
||||||
noteIdOrAlias = request.headers['hedgedoc-note'] as string;
|
this.logger.error(
|
||||||
const note = await getNote(this.noteService, noteIdOrAlias);
|
'Could not find noteIdOrAlias metadata. This should never happen. If you see this, please open an issue at https://github.com/hedgedoc/hedgedoc/issues',
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return await this.permissionsService.checkPermissionOnNote(
|
return await this.permissionsService.checkPermissionOnNote(
|
||||||
permissions[0],
|
permissions[0],
|
||||||
user,
|
user,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue