Skip to content
Snippets Groups Projects
Commit f399496d authored by michael.minelli's avatar michael.minelli
Browse files

Merge branch 'sonar' into v4.1.0

parents 3979c895 00085bce
No related branches found
No related tags found
No related merge requests found
Pipeline #32316 passed
import CommanderCommand from '../../../../CommanderCommand.js';
import ora from 'ora';
import DojoBackendManager from '../../../../../managers/DojoBackendManager.js';
import SessionManager from '../../../../../managers/SessionManager.js';
import Assignment from '../../../../../sharedByClients/models/Assignment.js';
import TextStyle from '../../../../../types/TextStyle.js';
import GlobalHelper from '../../../../../helpers/GlobalHelper.js';
abstract class AssignmentCorrectionLinkUpdateCommand extends CommanderCommand {
......@@ -32,23 +32,10 @@ abstract class AssignmentCorrectionLinkUpdateCommand extends CommanderCommand {
// Check access
{
console.log(TextStyle.BLOCK('Please wait while we check access...'));
const assignmentGetSpinner: ora.Ora = ora('Checking if assignment exists').start();
assignment = await DojoBackendManager.getAssignment(options.assignment);
assignment = await GlobalHelper.checkAssignmentCorrectionAccess(options.assignment);
if ( !assignment ) {
assignmentGetSpinner.fail(`The assignment doesn't exists`);
return;
}
assignmentGetSpinner.succeed(`The assignment exists`);
const assignmentAccessSpinner: ora.Ora = ora('Checking assignment access').start();
if ( assignment.staff.find(staff => staff.id === SessionManager.profile?.id) === undefined ) {
assignmentAccessSpinner.fail(`You are not in the staff of the assignment`);
return;
}
assignmentAccessSpinner.succeed(`You are in the staff of the assignment`);
const assignmentPublishedSpinner: ora.Ora = ora('Checking assignment').start();
......
import Assignment from '../../../../../sharedByClients/models/Assignment.js';
import ora from 'ora';
import TextStyle from '../../../../../types/TextStyle.js';
import DojoBackendManager from '../../../../../managers/DojoBackendManager.js';
import SessionManager from '../../../../../managers/SessionManager.js';
import CommanderCommand from '../../../../CommanderCommand.js';
import GlobalHelper from '../../../../../helpers/GlobalHelper.js';
class AssignmentCorrectionLinkCommand extends CommanderCommand {
......@@ -22,23 +21,10 @@ class AssignmentCorrectionLinkCommand extends CommanderCommand {
// Check access
{
console.log(TextStyle.BLOCK('Please wait while we check access...'));
const assignmentGetSpinner: ora.Ora = ora('Checking if assignment exists').start();
assignment = await DojoBackendManager.getAssignment(options.assignment);
assignment = await GlobalHelper.checkAssignmentCorrectionAccess(options.assignment);
if ( !assignment ) {
assignmentGetSpinner.fail(`The assignment doesn't exists`);
return;
}
assignmentGetSpinner.succeed(`The assignment exists`);
const assignmentAccessSpinner: ora.Ora = ora('Checking assignment access').start();
if ( assignment.staff.find(staff => staff.id === SessionManager.profile?.id) === undefined ) {
assignmentAccessSpinner.fail(`You are not in the staff of the assignment`);
return;
}
assignmentAccessSpinner.succeed(`You are in the staff of the assignment`);
}
// Link the exercise
......
......@@ -42,7 +42,7 @@ class ExerciseCorrectionCommand extends CommanderCommand {
const authors = correction.name.replace(correction.assignmentName, '').split('-')[2].trim();
return {
name : (correction.correctionDescription && correction.correctionDescription != '' ? `${ correction.correctionDescription } (${ authors })` : authors),
name : (correction.correctionDescription && correction.correctionDescription !== '' ? `${ correction.correctionDescription } (${ authors })` : authors),
value: correction.correctionCommit?.web_url?.replace('/commit/', '/tree/') ?? ''
};
});
......
......@@ -72,7 +72,7 @@ class ExerciseCreateCommand extends CommanderCommand {
}).start().info();
};
oraInfo(`${ TextStyle.WARNING('You already created ' + this.assignment.myExercises.length + ' exercises for this assignment:') }`, 4);
oraInfo(TextStyle.WARNING(`You already created ${ this.assignment.myExercises.length } exercises for this assignment:`), 4);
for ( const exercise of this.assignment.myExercises ) {
oraInfo(`${ TextStyle.LIST_ITEM_NAME('Exercice Id:') } ${ exercise.id }`, 8);
......
import { Command, Option } from 'commander';
import Config from '../config/Config.js';
import SessionManager from '../managers/SessionManager.js';
import TextStyle from '../types/TextStyle.js';
import ora from 'ora';
import DojoBackendManager from '../managers/DojoBackendManager.js';
import Assignment from '../sharedByClients/models/Assignment.js';
class GlobalHelper {
......@@ -20,6 +24,29 @@ class GlobalHelper {
return SessionManager.gitlabCredentials.accessToken ?? '';
};
public async checkAssignmentCorrectionAccess(assignmentName: string): Promise<Assignment | undefined> {
console.log(TextStyle.BLOCK('Please wait while we check access...'));
const assignmentGetSpinner: ora.Ora = ora('Checking if assignment exists').start();
const assignment = await DojoBackendManager.getAssignment(assignmentName);
if ( !assignment ) {
assignmentGetSpinner.fail(`The assignment doesn't exists`);
return undefined;
}
assignmentGetSpinner.succeed(`The assignment exists`);
const assignmentAccessSpinner: ora.Ora = ora('Checking assignment access').start();
if ( assignment.staff.find(staff => staff.id === SessionManager.profile?.id) === undefined ) {
assignmentAccessSpinner.fail(`You are not in the staff of the assignment`);
return undefined;
}
assignmentAccessSpinner.succeed(`You are in the staff of the assignment`);
return assignment;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment