From 95ffba7ebaf5c753d863830aca5116c75498b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me> Date: Wed, 28 Jun 2023 22:25:27 +0200 Subject: [PATCH] EnonceCreate => Add template access check --- .../commander/enonce/EnonceCreateCommand.ts | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/NodeApp/src/commander/enonce/EnonceCreateCommand.ts b/NodeApp/src/commander/enonce/EnonceCreateCommand.ts index 75a5a9c..e285665 100644 --- a/NodeApp/src/commander/enonce/EnonceCreateCommand.ts +++ b/NodeApp/src/commander/enonce/EnonceCreateCommand.ts @@ -1,10 +1,11 @@ -import CommanderCommand from '../CommanderCommand'; -import GitlabUser from '../../models/GitlabUser'; -import chalk from 'chalk'; -import ora from 'ora'; -import GitlabManager from '../../managers/GitlabManager'; -import Config from '../../config/Config'; -import SessionManager from '../../managers/SessionManager'; +import CommanderCommand from '../CommanderCommand'; +import chalk from 'chalk'; +import ora from 'ora'; +import GitlabManager from '../../managers/GitlabManager'; +import SessionManager from '../../managers/SessionManager'; +import GitlabUser from '../../shared/types/Gitlab/GitlabUser'; +import DojoBackendManager from '../../managers/DojoBackendManager'; +import Toolbox from '../../shared/Toolbox'; class EnonceCreateCommand extends CommanderCommand { @@ -28,6 +29,7 @@ class EnonceCreateCommand extends CommanderCommand { .requiredOption('-n, --name <name>', 'name of the enonce.') .option('-i, --members_id <ids...>', 'list of members ids (teaching staff) to add to the repository.') .option('-m, --members_username <usernames...>', 'list of members username (teaching staff) to add to the repository.') + .option('-t, --template <string>', 'id or url of the template (http(s) and ssh urls are possible).') .action(this.commandAction.bind(this)); } @@ -101,7 +103,20 @@ class EnonceCreateCommand extends CommanderCommand { if ( !members ) { return; } + + if ( options.template ) { + let templateIdOrNamespace: string = options.template; + + if ( Number.isNaN(Number(templateIdOrNamespace)) ) { + templateIdOrNamespace = encodeURIComponent(Toolbox.urlToPath(templateIdOrNamespace)); + } + + if ( !await DojoBackendManager.checkTemplateAccess(templateIdOrNamespace) ) { + return; + } + } } + } } -- GitLab