Newer
Older
/**
* @file Fonctions qui implémentent les requetes relatives aux groupes
* @author ofacklam
* @memberof GraphQL
*/
import { Group, SimpleGroup, MetaGroup } from "../resolvers/groups";
import { Request } from "../resolvers/requests";
import { User } from "../resolvers/users";
import knex from "../../../db/knex_router"
import { GroupCollection, GroupSet, Tools } from "./tools";
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { createSubgroupArgs, editGroupArgs } from "../typeDefs/queries";
export class GroupModel {
/**
* @memberof GraphQL
* @class GroupModel
* @summary Requetes relatives aux groupes.
* @classdesc Cette classe contient les méthodes implémentant les requetes relatives aux groupes.
* @arg {string} contextUser - L'identifiant de l'utilisateur du 'context'
*/
constructor(contextUser: string) {
this.contextUser = contextUser;
}
protected contextUser: string;
/**
* @memberof GraphQL.GroupModel#
* @function getGroup
* @summary Fonction qui renvoie un groupe donné.
* @arg {string} gid - Identifiant demandé.
* @return {Promise(Group)} Renvoie le groupe dont l'identifiant est 'gid'
* @async
* @rights connectedOrOnplatal
*/
async getGroup(gid: string): Promise<Group> {
let data = await knex.select('type').from('groups').where('gid', gid);
if(data.length > 0) {
let type = data[0].type;
switch(type) {
case 'simple':
return new SimpleGroup(gid);
case 'meta':
return new MetaGroup(gid);
default:
return null;
}
}
return null;
}
/**
* @memberof GraphQL.GroupModel#
* @function getSimpleGroup
* @summary Fonction qui renvoie un groupe simple donné.
* @arg {string} gid - Identifiant demandé.
* @return {Promise(SimpleGroup)} Renvoie le groupe dont l'identifiant est 'gid'
* @async
* @rights connectedOrOnplatal
*/
async getSimpleGroup(gid: string): Promise<SimpleGroup> {
return SimpleGroup.tryCreate(gid);
}
/**
* @memberof GraphQL.GroupModel#
* @function getMetaGroup
* @summary Fonction qui renvoie un méta-groupe donné.
* @arg {string} gid - Identifiant demandé.
* @return {Promise(MetaGroup)} Renvoie le groupe dont l'identifiant est 'gid'
* @async
* @rights connectedOrOnplatal
*/
async getMetaGroup(gid: string): Promise<MetaGroup> {
return MetaGroup.tryCreate(gid);
}
/**
* @memberof GraphQL.GroupModel#
* @function getAllGroupsByCollection
* @summary Fonction qui renvoie tous les groupes donnés en argument.
* @arg {GroupCollection} groups - Collection d'identifiants, supposés valides.
* @return {Group[]} Renvoie le tableau de groupes correspondant
* @rights connectedOrOnplatal
*/
getAllGroupsByCollection(groups: GroupCollection): Group[] {
let res: Group[]
for(let s of groups.simpleGroups) {
res.push(new SimpleGroup(s));
}
for(let m of groups.metaGroups) {
res.push(new MetaGroup(m));
}
return res;
}
/**
* @memberof GraphQL.GroupModel#
* @function getAllGroupsBySet
* @summary Fonction qui renvoie tous les groupes donnés en argument.
* @arg {GroupSet} groups - Ensemble d'identifiants, supposés valides.
* @return {Promise(Group[])} Renvoie le tableau de groupes correspondant
* @async
* @rights connectedOrOnplatal
*/
async getAllGroupsBySet(groups: GroupSet): Promise<Group[]> {
let res: Group[]
for(let g of groups) {
res.push(await this.getGroup(g));
}
return res;
}
/**
* @memberof GraphQL.GroupModel#
* @function getAllSimpleGroups
* @summary Fonction qui renvoie tous les groupes simples donnés en argument.
* @arg {GroupSet} groups - Ensemble d'identifiants, supposés valides.
* @return {SimpleGroup[]} Renvoie le tableau de groupes correspondant
getAllSimpleGroups(groups: GroupSet): SimpleGroup[] {
let res: SimpleGroup[]
for (let g of groups) {
res.push(new SimpleGroup(g));
}
return res;
}
/**
* @memberof GraphQL.GroupModel#
* @function likeGroup
* @summary Fonction pour devenir sympathisant
* @arg {string} gid - Identifiant du groupe.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights viewer du groupe
*/
async likeGroup(gid: string): Promise<boolean> {
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function unlikeGroup
* @summary Fonction pour devenir non-sympathisant
* @arg {string} gid - Identifiant du groupe.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights viewer du groupe
*/
async unlikeGroup(gid: string): Promise<boolean> {
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function userLeaveGroup
* @summary Fonction pour quitter un groupe
* @arg {string} gid - Identifiant du groupe.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights member du groupe
*/
async userLeaveGroup(gid: string): Promise<boolean> {
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function writePostsSummary
* @summary Fonction pour écrire le résumé des posts.
* @arg {string} gid - Identifiant du groupe.
* @arg {string} content - Contenu du résumé.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights speaker du groupe
*/
async writePostsSummary(gid: string, content: string): Promise<boolean> {
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function createSubgroup
* @summary Fonction pour créer un sous-groupe
* @arg {createSubgroupArgs} args - Les arguments pour la création.
* @return {Promise(Group)} Renvoie le groupe créé.
* @async
* @rights admin du groupe
*/
async createSubgroup(args: createSubgroupArgs): Promise<Group> {
throw "Not implemented";
// TODO : finish
/*if (typeof args.fromGroup != 'string')
throw "Illegal argument : parent_uid must be a non null string";
if (typeof args.subName != 'string')
throw "Illegal argument : name must be a non null string";
let rasGID = await getAvailableGID(args.subGid);
// TODO : appeller une fonction de LDAPUser pour y créer un groupe.
await knex('simple_groups').insert({
uid: rasGID,
parent_uid: args.parent_uid,
createdAt: knex.fn.now(),
updatedAt: this.createdAt,
name: args.name,
website: args.website,
description: args.description,
school: args.school,
type: "simple"
});
return getGroup(rasGID);*/
}
/**
* @memberof GraphQL.GroupModel#
* @function getAvailableGID
* @summary Attribue un GID qui n'a pas encore été utilisé à un groupe
* @desc Escape le string initialGID si necessaire (ramené à de l'ASCII sans espace), puis si le gid est deja pris rajoute un n a la fin et reteste
* @arg {string} initialGID - Le gid initial du groupe, qu'il faut tester pour l'unicité.
* @return {Promise(string)} Renvoie le gid unique pour ce groupe.
* @rights authentified
* remarque : n'importe qui peut tester si un groupe existe en demandant a créer un groupe avec ce nom la et en regardant si
* son GID a été modifié. Je ne vois pas comment contourner ce problème, c'est donc une faille permanente (mineure) de sigma.
* // ofacklam -> savoir qu'un groupe existe est autorisé pour toute personne connectée ou on-platal et il faut etre connecté pour
* // utiliser cette fonction-ci donc il n'y a pas de probleme.
*/
async getAvailableGID(initialGID: string): Promise<string> {
let rasGID = Tools.escapeID(initialGID);
const res = knex.from('groups').where('gid', rasGID)
if (res.length == 0) {
return (rasGID);
} else {
return (this.getAvailableGID(rasGID + 'n'));
}
}
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/**
* @memberof GraphQL.GroupModel#
* @function makeAdmin
* @summary Fonction pour rendre un membre admin
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur.
* @return {Promise(User)} Renvoie l'utilisateur promu.
* @async
* @rights admin du groupe
*/
async makeAdmin(gid: string, uid: string): Promise<User> {
//TODO : vérifier que l'utilisateur est bien déja membre !!
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function unmakeAdmin
* @summary Fonction pour rendre un membre non-admin
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur.
* @return {Promise(User)} Renvoie l'utilisateur dé-promu.
* @async
* @rights admin du groupe
*/
async unmakeAdmin(gid: string, uid: string): Promise<User> {
//TODO : vérifier que l'utilisateur est bien déja membre !!
//TODO : relacher les droits admin (des groupes enfants) pris en étant admin.
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function makeSpeaker
* @summary Fonction pour rendre un membre speaker
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur.
* @return {Promise(User)} Renvoie l'utilisateur promu.
* @async
* @rights admin du groupe
*/
async makeSpeaker(gid: string, uid: string): Promise<User> {
//TODO : vérifier que l'utilisateur est bien déja membre !!
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function unmakeSpeaker
* @summary Fonction pour rendre un membre non-speaker
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur.
* @return {Promise(User)} Renvoie l'utilisateur dé-promu.
* @async
* @rights admin du groupe
*/
async unmakeSpeaker(gid: string, uid: string): Promise<User> {
//TODO : vérifier que l'utilisateur est bien déja membre !!
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function editGroup
* @summary Fonction pour modifier un groupe.
* @arg {editGroupArgs} args - Les arguments de la modification.
* @return {Promise(Group)} Renvoie le groupe modifié.
* @async
* @rights admin du groupe
*/
async editGroup(args: editGroupArgs): Promise<Group> {
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function removeUser
* @summary Fonction pour enlever un membre du groupe.
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur.
* @return {Promise(User)} Renvoie l'utilisateur.
* @async
* @rights admin du groupe
*/
async removeUser(gid: string, uid: string): Promise<User> {
throw "Not implemented";
}
/**
* @memberof GraphQL.GroupModel#
* @function takeAdminRights
* @summary Fonction pour prendre les droits admin du groupe.
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur qui prend les droits.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights supervisor du groupe
*/
async takeAdminRights(gid: string, uid: string): Promise<boolean> {
throw "Not implemented";
/*await knex('taken_rights').insert({
user_uid: user.uid,
group_uid: groupUID,
justification: justification
});
return true;*/
}
/**
* @memberof GraphQL.GroupModel#
* @function releaseAdminRights
* @summary Fonction pour relacher les droits admin du groupe.
* @arg {string} gid - Identifiant du groupe.
* @arg {string} uid - Identifiant de l'utilisateur qui relache les droits.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights supervisor du groupe
*/
async releaseAdminRights(gid: string, uid: string): Promise<boolean> {
//TODO : relacher récursivement
throw "Not implemented";
/*return knex('taken_rights').del().where('user_uid', user.uid).where('group_uid', groupUID);*/