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

Transfert some types and models into a submodule

parent 86cef512
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,6 @@
[submodule "NodeApp/src/shared"]
path = NodeApp/src/shared
url = ../../shared/nodesharedcode.git
[submodule "NodeApp/src/sharedByClients"]
path = NodeApp/src/sharedByClients
url = ../../shared/nodeclientsharedcode.git
......@@ -4,14 +4,14 @@ import ora from 'ora';
import GitlabManager from '../../managers/GitlabManager';
import GitlabUser from '../../shared/types/Gitlab/GitlabUser';
import DojoBackendManager from '../../managers/DojoBackendManager';
import Enonce from '../../types/Enonce';
import Enonce from '../../sharedByClients/models/Enonce';
import Toolbox from '../../shared/helpers/Toolbox';
import AccessesHelper from '../../helpers/AccessesHelper';
class EnonceCreateCommand extends CommanderCommand {
protected commandName: string = 'create';
protected defineCommand() {
this.command
.description('create a new repository for an enonce')
......
import CommanderCommand from '../CommanderCommand';
import inquirer from 'inquirer';
import Enonce from '../../types/Enonce';
import Enonce from '../../sharedByClients/models/Enonce';
import chalk from 'chalk';
import SessionManager from '../../managers/SessionManager';
import ora from 'ora';
......
......@@ -2,10 +2,10 @@ import CommanderCommand from '../CommanderCommand';
import chalk from 'chalk';
import GitlabManager from '../../managers/GitlabManager';
import GitlabUser from '../../shared/types/Gitlab/GitlabUser';
import Enonce from '../../types/Enonce';
import Enonce from '../../sharedByClients/models/Enonce';
import ora from 'ora';
import DojoBackendManager from '../../managers/DojoBackendManager';
import Exercice from '../../types/Exercice';
import Exercice from '../../sharedByClients/models/Exercice';
import AccessesHelper from '../../helpers/AccessesHelper';
......
import axios, { AxiosError } from 'axios';
import Config from '../config/Config';
import ora from 'ora';
import ApiRoutes from '../types/ApiRoutes';
import ApiRoutes from '../sharedByClients/types/ApiRoutes';
import { StatusCodes } from 'http-status-codes';
import Enonce from '../types/Enonce';
import Enonce from '../sharedByClients/models/Enonce';
import GitlabUser from '../shared/types/Gitlab/GitlabUser';
import Exercice from '../types/Exercice';
import Exercice from '../sharedByClients/models/Exercice';
import DojoResponse from '../shared/types/DojoResponse';
......
import * as jwt from 'jsonwebtoken';
import User from '../models/User';
import User from '../sharedByClients/models/User';
import LocalConfig from '../config/LocalConfig';
import LocalConfigKeys from '../types/LocalConfigKeys';
import axios, { AxiosError } from 'axios';
import HttpManager from './HttpManager';
import ora from 'ora';
import Permissions from '../types/Permissions';
import ApiRoutes from '../types/ApiRoutes';
import ApiRoutes from '../sharedByClients/types/ApiRoutes';
import DojoBackendManager from './DojoBackendManager';
import { StatusCodes } from 'http-status-codes';
......@@ -14,7 +14,7 @@ import { StatusCodes } from 'http-status-codes';
class SessionManager {
private _token: string | null = null;
public profile: User = new User();
public profile: User | undefined = undefined;
get isLogged(): boolean {
return this._token !== null;
......@@ -31,10 +31,10 @@ class SessionManager {
const payload = jwt.decode(token);
if ( payload && typeof payload === 'object' && payload.profile ) {
this.profile = User.createFromJson(payload.profile);
this.profile = payload.profile as User;
}
} catch ( error ) {
this.profile = new User();
this.profile = undefined;
}
LocalConfig.updateConfig(LocalConfigKeys.API_TOKEN, token);
......@@ -43,7 +43,7 @@ class SessionManager {
async login(user: string, password: string) {
const spinner: ora.Ora = ora('Logging in').start();
try {
this.profile = new User();
this.profile = undefined;
const response = await axios.post(DojoBackendManager.getApiUrl(ApiRoutes.LOGIN), {
user : user,
......@@ -72,7 +72,7 @@ class SessionManager {
checkPermissions(verbose: boolean = true, indent: number = 8, checkPermissions: Array<string> | null = []): Permissions {
const hasPermission = (permissionPredicate: () => boolean, verboseText: string): boolean => {
let isAllowed: boolean = this.profile.id !== -1 && permissionPredicate();
let isAllowed: boolean = this.profile !== undefined && permissionPredicate();
if ( verbose ) {
const spinner: ora.Ora = ora({
......@@ -86,7 +86,7 @@ class SessionManager {
};
return {
teachingStaff: checkPermissions && (checkPermissions.length == 0 || checkPermissions.includes('teachingStaff')) ? hasPermission(() => this.profile.isTeachingStaff, 'Teaching staff permissions') : false,
teachingStaff: checkPermissions && (checkPermissions.length == 0 || checkPermissions.includes('teachingStaff')) ? hasPermission(() => this.profile?.isTeachingStaff ?? false, 'Teaching staff permissions') : false,
student : checkPermissions && (checkPermissions.length == 0 || checkPermissions.includes('student')) ? hasPermission(() => true, 'Student permissions') : false
};
}
......
type Constructor<T> = new (...args: any[]) => T;
abstract class Model extends Object {
static createFromJson<T extends Object>(this: Constructor<T>, obj: any): T {
const result = new this();
Object.getOwnPropertyNames(obj).forEach(property => {
if ( result.hasOwnProperty(property) ) {
(result as any)[property] = property.indexOf('Info') === -1 ? obj[property] : JSON.parse(obj[property]);
}
});
return result;
}
}
export default Model;
import Model from './Model';
class User extends Model {
id: number = -1;
firstName: string = '';
lastName: string = '';
mail: string = '';
gitlabId: number = -1;
role: string = '';
isTeachingStaff: boolean = false;
deleted: boolean = true;
constructor() {
super();
}
get fullName(): string {
return this.lastName.toUpperCase() + ' ' + this.firstName;
}
}
export default User;
Subproject commit 3cd4b0c0e18fb8e8f52062cf4b171c8c67d4baea
enum ApiRoutes {
LOGIN = '/login',
TEST_SESSION = '/test_session',
GITLAB_CHECK_TEMPLATE_ACCESS = '/gitlab/project/{{id}}/checkTemplateAccess',
ENONCE_GET = '/enonces/{{nameOrUrl}}',
ENONCE_CREATE = '/enonces',
ENONCE_PUBLISH = '/enonces/{{nameOrUrl}}/publish',
ENONCE_UNPUBLISH = '/enonces/{{nameOrUrl}}/unpublish',
EXERCICE_CREATE = '/enonces/{{nameOrUrl}}/exercices',
}
export default ApiRoutes;
\ No newline at end of file
import GitlabRepository from '../shared/types/Gitlab/GitlabRepository';
import User from '../models/User';
import Exercice from './Exercice';
interface Enonce {
name: string;
gitlabId: number;
gitlabLink: string;
gitlabCreationInfo: GitlabRepository;
gitlabLastInfo: GitlabRepository;
gitlabLastInfoDate: string;
published: boolean;
staff: Array<User>;
exercices: Array<Exercice>;
}
export default Enonce;
\ No newline at end of file
import GitlabRepository from '../shared/types/Gitlab/GitlabRepository';
interface Exercice {
id: string;
enonceName: string;
name: string;
gitlabId: number;
gitlabLink: string;
gitlabCreationInfo: GitlabRepository;
gitlabLastInfo: GitlabRepository;
gitlabLastInfoDate: string;
}
export default Exercice;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment