feat: Add initial scope checks via decorators (#7737)

This commit is contained in:
Val
2023-11-28 11:41:34 +00:00
committed by GitHub
parent 753cbc1e96
commit a37f1cb0ba
22 changed files with 233 additions and 89 deletions

View File

@@ -6,7 +6,16 @@ import {
STARTER_TEMPLATE_NAME,
UNKNOWN_FAILURE_REASON,
} from '@/constants';
import { Authorized, Delete, Get, Middleware, Patch, Post, RestController } from '@/decorators';
import {
Authorized,
Delete,
Get,
Middleware,
Patch,
Post,
RestController,
RequireGlobalScope,
} from '@/decorators';
import { NodeRequest } from '@/requests';
import type { InstalledPackages } from '@db/entities/InstalledPackages';
import type { CommunityPackages } from '@/Interfaces';
@@ -34,7 +43,7 @@ export function isNpmError(error: unknown): error is { code: number; stdout: str
}
@Service()
@Authorized(['global', 'owner'])
@Authorized()
@RestController('/community-packages')
export class CommunityPackagesController {
constructor(
@@ -55,6 +64,7 @@ export class CommunityPackagesController {
}
@Post('/')
@RequireGlobalScope('communityPackage:install')
async installPackage(req: NodeRequest.Post) {
const { name } = req.body;
@@ -151,6 +161,7 @@ export class CommunityPackagesController {
}
@Get('/')
@RequireGlobalScope('communityPackage:list')
async getInstalledPackages() {
const installedPackages = await this.communityPackagesService.getAllInstalledPackages();
@@ -185,6 +196,7 @@ export class CommunityPackagesController {
}
@Delete('/')
@RequireGlobalScope('communityPackage:uninstall')
async uninstallPackage(req: NodeRequest.Delete) {
const { name } = req.query;
@@ -236,6 +248,7 @@ export class CommunityPackagesController {
}
@Patch('/')
@RequireGlobalScope('communityPackage:update')
async updatePackage(req: NodeRequest.Update) {
const { name } = req.body;