diff --git a/NodeApp/src/commander/enonce/EnonceCreateCommand.ts b/NodeApp/src/commander/enonce/EnonceCreateCommand.ts index 75a5a9cfe9ead2a3eed8e254067c8f554d44d63d..e2856659b2b5b3f264ed860be498532fad63fb6b 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; + } + } } + } }