mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
refactor: rename "Permissions" decorator to "RequirePermission"
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
4c384cc8de
commit
6b73016583
5 changed files with 40 additions and 39 deletions
|
@ -23,10 +23,10 @@ import { MediaUploadDto } from '../../../media/media-upload.dto';
|
|||
import { MediaService } from '../../../media/media.service';
|
||||
import { MulterFile } from '../../../media/multer-file.interface';
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { Permissions } from '../../../permissions/permissions.decorator';
|
||||
import { Permission } from '../../../permissions/permissions.enum';
|
||||
import { PermissionsGuard } from '../../../permissions/permissions.guard';
|
||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||
import { RequirePermission } from '../../../permissions/require-permission.decorator';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { NoteHeaderInterceptor } from '../../utils/note-header.interceptor';
|
||||
import { OpenApi } from '../../utils/openapi.decorator';
|
||||
|
@ -66,7 +66,7 @@ export class MediaController {
|
|||
@UseGuards(PermissionsGuard)
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@UseInterceptors(NoteHeaderInterceptor)
|
||||
@Permissions(Permission.WRITE)
|
||||
@RequirePermission(Permission.WRITE)
|
||||
@OpenApi(
|
||||
{
|
||||
code: 201,
|
||||
|
|
|
@ -30,10 +30,10 @@ import { NoteDto } from '../../../notes/note.dto';
|
|||
import { Note } from '../../../notes/note.entity';
|
||||
import { NoteMediaDeletionDto } from '../../../notes/note.media-deletion.dto';
|
||||
import { NotesService } from '../../../notes/notes.service';
|
||||
import { Permissions } from '../../../permissions/permissions.decorator';
|
||||
import { Permission } from '../../../permissions/permissions.enum';
|
||||
import { PermissionsGuard } from '../../../permissions/permissions.guard';
|
||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||
import { RequirePermission } from '../../../permissions/require-permission.decorator';
|
||||
import { RevisionMetadataDto } from '../../../revisions/revision-metadata.dto';
|
||||
import { RevisionDto } from '../../../revisions/revision.dto';
|
||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||
|
@ -65,7 +65,7 @@ export class NotesController {
|
|||
|
||||
@Get(':noteIdOrAlias')
|
||||
@OpenApi(200)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async getNote(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
|
@ -77,7 +77,7 @@ export class NotesController {
|
|||
|
||||
@Get(':noteIdOrAlias/media')
|
||||
@OpenApi(200)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async getNotesMedia(@RequestNote() note: Note): Promise<MediaUploadDto[]> {
|
||||
const media = await this.mediaService.listUploadsByNote(note);
|
||||
|
@ -88,7 +88,7 @@ export class NotesController {
|
|||
|
||||
@Post()
|
||||
@OpenApi(201, 413)
|
||||
@Permissions(Permission.CREATE)
|
||||
@RequirePermission(Permission.CREATE)
|
||||
async createNote(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
@MarkdownBody() text: string,
|
||||
|
@ -101,7 +101,7 @@ export class NotesController {
|
|||
|
||||
@Post(':noteAlias')
|
||||
@OpenApi(201, 400, 404, 409, 413)
|
||||
@Permissions(Permission.CREATE)
|
||||
@RequirePermission(Permission.CREATE)
|
||||
async createNamedNote(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
@Param('noteAlias') noteAlias: string,
|
||||
|
@ -115,7 +115,7 @@ export class NotesController {
|
|||
|
||||
@Delete(':noteIdOrAlias')
|
||||
@OpenApi(204, 404, 500)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async deleteNote(
|
||||
@RequestUser() user: User,
|
||||
|
@ -137,7 +137,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/metadata')
|
||||
async getNoteMetadata(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
|
@ -148,7 +148,7 @@ export class NotesController {
|
|||
|
||||
@Get(':noteIdOrAlias/revisions')
|
||||
@OpenApi(200, 404)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async getNoteRevisions(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
|
@ -164,7 +164,7 @@ export class NotesController {
|
|||
|
||||
@Delete(':noteIdOrAlias/revisions')
|
||||
@OpenApi(204, 404)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async purgeNoteRevisions(
|
||||
@RequestUser() user: User,
|
||||
|
@ -184,7 +184,7 @@ export class NotesController {
|
|||
|
||||
@Get(':noteIdOrAlias/revisions/:revisionId')
|
||||
@OpenApi(200, 404)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
async getNoteRevision(
|
||||
@RequestUser({ guestsAllowed: true }) user: User | null,
|
||||
|
@ -199,7 +199,7 @@ export class NotesController {
|
|||
@Put(':noteIdOrAlias/metadata/permissions/users/:userName')
|
||||
@OpenApi(200, 403, 404)
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
async setUserPermission(
|
||||
@RequestUser() user: User,
|
||||
@RequestNote() note: Note,
|
||||
|
@ -216,7 +216,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Delete(':noteIdOrAlias/metadata/permissions/users/:userName')
|
||||
async removeUserPermission(
|
||||
@RequestUser() user: User,
|
||||
|
@ -241,7 +241,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions/groups/:groupName')
|
||||
async setGroupPermission(
|
||||
@RequestUser() user: User,
|
||||
|
@ -259,7 +259,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Delete(':noteIdOrAlias/metadata/permissions/groups/:groupName')
|
||||
async removeGroupPermission(
|
||||
|
@ -276,7 +276,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions/owner')
|
||||
async changeOwner(
|
||||
@RequestUser() user: User,
|
||||
|
|
|
@ -29,10 +29,10 @@ import { MediaUploadDto } from '../../../media/media-upload.dto';
|
|||
import { MediaService } from '../../../media/media.service';
|
||||
import { MulterFile } from '../../../media/multer-file.interface';
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { Permissions } from '../../../permissions/permissions.decorator';
|
||||
import { Permission } from '../../../permissions/permissions.enum';
|
||||
import { PermissionsGuard } from '../../../permissions/permissions.guard';
|
||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||
import { RequirePermission } from '../../../permissions/require-permission.decorator';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { NoteHeaderInterceptor } from '../../utils/note-header.interceptor';
|
||||
import { OpenApi } from '../../utils/openapi.decorator';
|
||||
|
@ -84,7 +84,7 @@ export class MediaController {
|
|||
@UseGuards(PermissionsGuard)
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@UseInterceptors(NoteHeaderInterceptor)
|
||||
@Permissions(Permission.WRITE)
|
||||
@RequirePermission(Permission.WRITE)
|
||||
async uploadMedia(
|
||||
@RequestUser() user: User,
|
||||
@UploadedFile() file: MulterFile,
|
||||
|
|
|
@ -33,10 +33,10 @@ import { NoteDto } from '../../../notes/note.dto';
|
|||
import { Note } from '../../../notes/note.entity';
|
||||
import { NoteMediaDeletionDto } from '../../../notes/note.media-deletion.dto';
|
||||
import { NotesService } from '../../../notes/notes.service';
|
||||
import { Permissions } from '../../../permissions/permissions.decorator';
|
||||
import { Permission } from '../../../permissions/permissions.enum';
|
||||
import { PermissionsGuard } from '../../../permissions/permissions.guard';
|
||||
import { PermissionsService } from '../../../permissions/permissions.service';
|
||||
import { RequirePermission } from '../../../permissions/require-permission.decorator';
|
||||
import { RevisionMetadataDto } from '../../../revisions/revision-metadata.dto';
|
||||
import { RevisionDto } from '../../../revisions/revision.dto';
|
||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||
|
@ -67,7 +67,7 @@ export class NotesController {
|
|||
this.logger.setContext(NotesController.name);
|
||||
}
|
||||
|
||||
@Permissions(Permission.CREATE)
|
||||
@RequirePermission(Permission.CREATE)
|
||||
@Post()
|
||||
@OpenApi(201, 403, 409, 413)
|
||||
async createNote(
|
||||
|
@ -81,7 +81,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ export class NotesController {
|
|||
return await this.noteService.toNoteDto(note);
|
||||
}
|
||||
|
||||
@Permissions(Permission.CREATE)
|
||||
@RequirePermission(Permission.CREATE)
|
||||
@Post(':noteAlias')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Delete(':noteIdOrAlias')
|
||||
@OpenApi(204, 403, 404, 500)
|
||||
async deleteNote(
|
||||
|
@ -148,7 +148,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.WRITE)
|
||||
@RequirePermission(Permission.WRITE)
|
||||
@Put(':noteIdOrAlias')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -171,7 +171,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/content')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -190,7 +190,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/metadata')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -209,7 +209,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -231,7 +231,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/metadata/permissions')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions/users/:userName')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -277,7 +277,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Delete(':noteIdOrAlias/metadata/permissions/users/:userName')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -311,7 +311,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions/groups/:groupName')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -338,7 +338,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Delete(':noteIdOrAlias/metadata/permissions/groups/:groupName')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -363,7 +363,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.OWNER)
|
||||
@RequirePermission(Permission.OWNER)
|
||||
@Put(':noteIdOrAlias/metadata/permissions/owner')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -386,7 +386,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/revisions')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -411,7 +411,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/revisions/:revisionId')
|
||||
@OpenApi(
|
||||
{
|
||||
|
@ -433,7 +433,7 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@UseInterceptors(GetNoteInterceptor)
|
||||
@Permissions(Permission.READ)
|
||||
@RequirePermission(Permission.READ)
|
||||
@Get(':noteIdOrAlias/media')
|
||||
@OpenApi({
|
||||
code: 200,
|
||||
|
|
|
@ -13,5 +13,6 @@ import { Permission } from './permissions.enum';
|
|||
* @constructor
|
||||
*/
|
||||
// eslint-disable-next-line func-style,@typescript-eslint/naming-convention
|
||||
export const Permissions = (...permissions: Permission[]): CustomDecorator =>
|
||||
SetMetadata('permissions', permissions);
|
||||
export const RequirePermission = (
|
||||
...permissions: Permission[]
|
||||
): CustomDecorator => SetMetadata('permissions', permissions);
|
Loading…
Reference in a new issue