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

Correct code format

parent 83e811a7
No related branches found
No related tags found
No related merge requests found
Showing
with 150 additions and 67 deletions
......@@ -54,7 +54,11 @@ class Session {
} catch {}
return {
timestamp: (new Date()).toISOString(), code: code, description: descriptionOverride ? descriptionOverride : reasonPhrase, sessionToken: Session.getToken(profileJson), data: data
timestamp : (new Date()).toISOString(),
code : code,
description : descriptionOverride ? descriptionOverride : reasonPhrase,
sessionToken: Session.getToken(profileJson),
data : data
};
}
......
......@@ -40,7 +40,8 @@ class API implements WorkerTask {
run() {
this.server = this.backend.listen(Config.api.port, '0.0.0.0', () => {
const {
port, address
port,
address
} = this.server!.address() as AddressInfo;
logger.info(`Server started on http://${ address }:${ port }`);
});
......
......@@ -46,8 +46,11 @@ class DojoValidators {
});
readonly templateUrlValidator = this.toValidatorSchemaOptions({
bail: true, errorMessage: 'Template doesn\'t exist or you don\'t have access to it', options: (value, {
req, path
bail : true,
errorMessage: 'Template doesn\'t exist or you don\'t have access to it',
options : (value, {
req,
path
}) => {
return new Promise((resolve, reject) => {
const template = this.getParamValue(req, path);
......@@ -63,7 +66,8 @@ class DojoValidators {
readonly templateUrlSanitizer = this.toValidatorSchemaOptions({
options: (value, {
req, path
req,
path
}) => {
try {
const template = this.getParamValue(req, path);
......
......@@ -12,13 +12,16 @@ export default Prisma.defineExtension(client => {
isTeachingStaff: {
needs: {
role: true
}, compute(user) {
},
compute(user) {
return Config.permissions.teachingStaff.includes(user.role!);
}
}, gitlabProfile: {
},
gitlabProfile : {
needs: {
gitlabId: true
}, compute(user) {
},
compute(user) {
return new LazyVal<GitlabUser | undefined>(() => {
return GitlabManager.getUserById(user.gitlabId);
});
......
......@@ -19,7 +19,8 @@ class EnonceManager {
return await db.enonce.findUnique({
where : {
name: name
}, include: include
},
include: include
}) as unknown as Enonce ?? undefined;
}
......
......@@ -8,7 +8,8 @@ class ExerciceManager {
return await db.exercice.findUnique({
where : {
id: id
}, include: include
},
include: include
}) as unknown as Exercice ?? undefined;
}
}
......
......@@ -50,7 +50,14 @@ class GitlabManager {
async createRepository(name: string, description: string, visibility: string, initializeWithReadme: boolean, namespace: number, sharedRunnersEnabled: boolean, wikiEnabled: boolean, import_url: string): Promise<GitlabRepository> {
const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_CREATE), {
name: name, description: description, import_url: import_url, initialize_with_readme: initializeWithReadme, namespace_id: namespace, shared_runners_enabled: sharedRunnersEnabled, visibility: visibility, wiki_enabled: wikiEnabled
name : name,
description : description,
import_url : import_url,
initialize_with_readme: initializeWithReadme,
namespace_id : namespace,
shared_runners_enabled: sharedRunnersEnabled,
visibility : visibility,
wiki_enabled : wikiEnabled
});
return response.data;
......@@ -58,7 +65,11 @@ class GitlabManager {
async forkRepository(forkId: number, name: string, path: string, description: string, visibility: string, namespace: number): Promise<GitlabRepository> {
const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_FORK).replace('{{id}}', String(forkId)), {
name: name, path: path, description: description, namespace_id: namespace, visibility: visibility
name : name,
path : path,
description : description,
namespace_id: namespace,
visibility : visibility
});
return response.data;
......@@ -76,7 +87,8 @@ class GitlabManager {
async addRepositoryMember(repoId: number, userId: number, accessLevel: GitlabAccessLevel): Promise<GitlabMember> {
const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_MEMBER_ADD).replace('{{id}}', String(repoId)), {
user_id: userId, access_level: accessLevel
user_id : userId,
access_level: accessLevel
});
return response.data;
......@@ -84,7 +96,11 @@ class GitlabManager {
async addRepositoryVariable(repoId: number, key: string, value: string, isProtected: boolean, isMasked: boolean): Promise<GitlabMember> {
const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_VARIABLES_ADD).replace('{{id}}', String(repoId)), {
key: key, variable_type: 'env_var', value: value, protected: isProtected, masked: isMasked
key : key,
variable_type: 'env_var',
value : value,
protected : isProtected,
masked : isMasked
});
return response.data;
......@@ -105,7 +121,8 @@ class GitlabManager {
// Check if the user and dojo are members (with at least reporter access) of the project
const members = await this.getRepositoryMembers(idOrNamespace);
const isUsersAtLeastReporter = {
user: false, dojo: false
user: false,
dojo: false
};
members.forEach(member => {
if ( member.access_level >= GitlabAccessLevel.REPORTER ) {
......@@ -122,7 +139,11 @@ class GitlabManager {
async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> {
const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_BRANCHES_PROTECT).replace('{{id}}', String(repoId)), {
name: branchName, allow_force_push: allowForcePush, merge_access_level: allowedToMerge.valueOf(), push_access_level: allowedToPush.valueOf(), unprotect_access_level: allowedToUnprotect.valueOf()
name : branchName,
allow_force_push : allowForcePush,
merge_access_level : allowedToMerge.valueOf(),
push_access_level : allowedToPush.valueOf(),
unprotect_access_level: allowedToUnprotect.valueOf()
});
return response.data;
......@@ -131,7 +152,10 @@ class GitlabManager {
async getRepositoryTree(repoId: number, recursive: boolean = true, branch: string = 'main'): Promise<Array<GitlabTreeFile>> {
let address: string | undefined = this.getApiUrl(GitlabRoutes.REPOSITORY_TREE).replace('{{id}}', String(repoId));
let params: any = {
pagination: 'keyset', recursive: recursive, per_page: 100, ref: branch
pagination: 'keyset',
recursive : recursive,
per_page : 100,
ref : branch
};
let results: Array<GitlabTreeFile> = [];
......
......@@ -9,7 +9,8 @@ class UserManager {
return await db.user.findUnique({
where : {
mail: mail
}, include: include
},
include: include
}) as unknown as User ?? undefined;
}
......@@ -17,7 +18,8 @@ class UserManager {
return await db.user.findUnique({
where : {
id: id
}, include: include
},
include: include
}) as unknown as User ?? undefined;
}
......@@ -25,7 +27,8 @@ class UserManager {
return await db.user.findUnique({
where : {
gitlabId: gitlabId
}, include: include
},
include: include
}) as unknown as User ?? (returnIdIfUndefined ? gitlabId : undefined);
}
......@@ -35,7 +38,8 @@ class UserManager {
if ( typeof user === 'number' && createIfNotExist ) {
user = (await db.user.create({
data: {
firstname: gitlabUser.name, gitlabId: gitlabUser.id
firstname: gitlabUser.name,
gitlabId : gitlabUser.id
}
})).id;
}
......
......@@ -27,18 +27,22 @@ class ParamsCallbackManager {
initBoundParams(req: express.Request) {
if ( !req.boundParams ) {
req.boundParams = {
enonce: undefined, exercice: undefined
enonce : undefined,
exercice: undefined
};
}
}
register(backend: Express) {
this.listenParam('enonceNameOrUrl', backend, (EnonceManager.get as GetFunction).bind(EnonceManager), [ {
exercices: true, staff: true
exercices: true,
staff : true
} ], 'enonce');
this.listenParam('exerciceId', backend, (ExerciceManager.get as GetFunction).bind(ExerciceManager), [ {
enonce: true, members: true, results: true
enonce : true,
members: true,
results: true
} ], 'exercice');
}
}
......
......@@ -25,11 +25,18 @@ import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibil
class EnonceRoutes implements RoutesManager {
private readonly enonceValidator: ExpressValidator.Schema = {
name : {
trim: true, notEmpty: true
}, members : {
trim: true, notEmpty: true, customSanitizer: DojoValidators.jsonSanitizer
}, template: {
trim: true, custom: DojoValidators.templateUrlValidator, customSanitizer: DojoValidators.templateUrlSanitizer
trim : true,
notEmpty: true
},
members : {
trim : true,
notEmpty : true,
customSanitizer: DojoValidators.jsonSanitizer
},
template: {
trim : true,
custom : DojoValidators.templateUrlValidator,
customSanitizer: DojoValidators.templateUrlSanitizer
}
};
......@@ -102,12 +109,20 @@ class EnonceRoutes implements RoutesManager {
const enonce: Enonce = await db.enonce.create({
data: {
name: repository.name, gitlabId: repository.id, gitlabLink: repository.web_url, gitlabCreationInfo: repository as unknown as Prisma.JsonObject, gitlabLastInfo: repository as unknown as Prisma.JsonObject, gitlabLastInfoDate: new Date(), staff: {
name : repository.name,
gitlabId : repository.id,
gitlabLink : repository.web_url,
gitlabCreationInfo: repository as unknown as Prisma.JsonObject,
gitlabLastInfo : repository as unknown as Prisma.JsonObject,
gitlabLastInfoDate: new Date(),
staff : {
connectOrCreate: [ ...params.members.map(gitlabUser => {
return {
create: {
gitlabId: gitlabUser.id, firstname: gitlabUser.name
}, where: {
gitlabId : gitlabUser.id,
firstname: gitlabUser.name
},
where : {
gitlabId: gitlabUser.id
}
};
......@@ -135,7 +150,8 @@ class EnonceRoutes implements RoutesManager {
await db.enonce.update({
where: {
name: req.boundParams.enonce!.name
}, data: {
},
data : {
published: publish
}
});
......
......@@ -29,7 +29,9 @@ import hjson from 'hjson';
class ExerciceRoutes implements RoutesManager {
private readonly exerciceValidator: ExpressValidator.Schema = {
members: {
trim: true, notEmpty: true, customSanitizer: DojoValidators.jsonSanitizer
trim : true,
notEmpty : true,
customSanitizer: DojoValidators.jsonSanitizer
}
};
......@@ -97,12 +99,23 @@ class ExerciceRoutes implements RoutesManager {
const exercice: Exercice = await db.exercice.create({
data: {
id: exerciceId, enonceName: enonce.name, name: repository.name, secret: secret, gitlabId: repository.id, gitlabLink: repository.web_url, gitlabCreationInfo: repository as unknown as Prisma.JsonObject, gitlabLastInfo: repository as unknown as Prisma.JsonObject, gitlabLastInfoDate: new Date(), members: {
id : exerciceId,
enonceName : enonce.name,
name : repository.name,
secret : secret,
gitlabId : repository.id,
gitlabLink : repository.web_url,
gitlabCreationInfo: repository as unknown as Prisma.JsonObject,
gitlabLastInfo : repository as unknown as Prisma.JsonObject,
gitlabLastInfoDate: new Date(),
members : {
connectOrCreate: [ ...params.members.map(gitlabUser => {
return {
create: {
gitlabId: gitlabUser.id, firstname: gitlabUser.name
}, where: {
gitlabId : gitlabUser.id,
firstname: gitlabUser.name
},
where : {
gitlabId: gitlabUser.id
}
};
......@@ -152,7 +165,9 @@ class ExerciceRoutes implements RoutesManager {
}));
return req.session.sendResponse(res, StatusCodes.OK, {
enonce: (req.boundParams.exercice as Exercice).enonce, enonceFile: dojoEnonceFile, immutable: immutableFiles
enonce : (req.boundParams.exercice as Exercice).enonce,
enonceFile: dojoEnonceFile,
immutable : immutableFiles
});
}
}
......
......@@ -13,9 +13,12 @@ import { User } from '../types/DatabaseTypes';
class SessionRoutes implements RoutesManager {
private readonly loginValidator: ExpressValidator.Schema = {
user : {
trim: true, notEmpty: true
}, password: {
trim: true, notEmpty: true
trim : true,
notEmpty: true
},
password: {
trim : true,
notEmpty: true
}
};
......
......@@ -8,12 +8,15 @@ const userBase = Prisma.validator<Prisma.UserArgs>()({
});
const enonceBase = Prisma.validator<Prisma.EnonceArgs>()({
include: {
exercices: true, staff: true
exercices: true,
staff : true
}
});
const exerciceBase = Prisma.validator<Prisma.ExerciceArgs>()({
include: {
enonce: true, members: true, results: true
enonce : true,
members: true,
results: true
}
});
const resultBase = Prisma.validator<Prisma.ResultArgs>()({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment