Skip to content
Snippets Groups Projects
Commit 2c29ab39 authored by Guilhem ROY's avatar Guilhem ROY
Browse files

Merge 1

parents 7324a7f8 acd7e6f8
No related branches found
No related tags found
No related merge requests found
......@@ -151,6 +151,21 @@ export class GroupModel {
return res;
}
/**
* @memberof GraphQL.GroupModel#
* @function getAllSimpleGroupsFromMeta
* @summary Fonction qui renvoie tous les groupes simples du groupe meta.
* @arg {string} gid - identifiant du groupe en question.
* @return {GroupSet} Renvoie le tableau de groupes correspondant
* @rights connectedOrOnplatal
*/
getAllSimpleGroupsFromMeta(gid: string): Promise<GroupSet> {
let arg=new GroupSet();
arg.add(gid);
let res=Tools.simpleGroupsOfGroups(arg);
return res;
}
/**
* @memberof GraphQL.GroupModel#
* @function likeGroup
......
......@@ -75,6 +75,24 @@ export class MessageModel {
return Question.tryCreate(mid);
}
/**
* @memberof GraphQL.Group#
* @function questions
* @summary Renvoie les questions adressées a ce groupe
* @arg {string} gid
* @return {Promise(Question[])}
* @rights viewer
* @async
*/
async getAllQuestionsReceived(gid: string): Promise<Question[]> {
throw "Not implemented"
// let result = await knex('questions').select().whereIn('id', received_messages);
// for(let entry of result){
// entry.type = "Question";
// }
// return result;
}
/**
* @memberof GraphQL.MessageModel#
* @function getAnswer
......@@ -88,6 +106,25 @@ export class MessageModel {
return Answer.tryCreate(mid);
}
/**
* @memberof GraphQL.Group#
* @function answers
* @summary Renvoie les réponses de ce groupe
* @arg {string} gid
* @return {Promise(Answer[])}
* @rights viewer
* @async
*/
async getAllAnswersSent(gid: string): Promise<Answer[]> {
throw "Not implemented"
// let received_messages = await selectors.recievedMessages(user, groupUID);
// let result = await knex('answers').select().whereIn('id', received_messages);
// for(let entry of result){
// entry.type = "Answer";
// }
// return result;
}
/**
* @memberof GraphQL.MessageModel#
* @function getAllMessages
......
......@@ -119,6 +119,21 @@ export class Tools {
}));
}
/**
* @memberof GraphQL
* @summary Fonction qui renvoit tous les simple-groupes dont ces groupes sont membres.
* @arg {GroupSet} groups - Un ensemble de gid des groupes a considérer.
* @return {Promise(GroupSet)} Renvoie un GroupSet contenant le nom des simple-groupes.
* @static
* @async
*/
static async simpleGroupsOfGroups(groups: GroupSet): Promise<GroupSet> {
let simples = await knex.select('simple_group_gid').from('metagroup_memberships').whereIn('meta_group_gid', [...groups]);
return new GroupSet(simples.map( elt => {
return elt.simple_group_gid;
}));
}
/**
* @memberof GraphQL
* @summary Fonction qui renvoit tous les groupes (simples ou méta) dont le user est membre.
......
......@@ -11,6 +11,8 @@ import { Context } from '../typeDefs/queries';
import { ApolloError, AuthenticationError } from 'apollo-server-core';
import { Request, UserJoinGroup, GroupJoinMetagroup, GroupCoauthorEvent } from './requests';
import { GroupSet } from '../models/tools';
import { is } from 'bluebird';
import { userData } from '../../ldap/export/user';
export abstract class Group {
......@@ -190,7 +192,7 @@ export abstract class Group {
*/
async questions(args, context: Context, info): Promise<Question[]> {
if (context.models.auth.isViewer(this.gid)) {
throw "Not implemented"
return context.models.message.getAllQuestionsReceived(this.gid);
// let result = await knex('questions').select().whereIn('id', received_messages);
// for(let entry of result){
......@@ -211,7 +213,7 @@ export abstract class Group {
*/
async answers(args, context: Context, info): Promise<Answer[]> {
if (context.models.auth.isViewer(this.gid)) {
throw "Not implemented"
return context.models.message.getAllAnswersSent(this.gid);
// let received_messages = await selectors.recievedMessages(user, groupUID);
// let result = await knex('answers').select().whereIn('id', received_messages);
......@@ -552,14 +554,28 @@ export class SimpleGroup extends Group {
*/
async admins(args, context: Context, info): Promise<User[]> {
if(context.models.auth.isViewer(this.gid)) {
await this.fetchData();
return this.m_admins.map(uid => {
let list_admins =await this.auxAdmins();
return list_admins.map(uid => {
return new User(uid);
});
}
throw new AuthenticationError("Not a viewer");
}
/**
* @memberof GraphQL.SimpleGroup#
* @function auxAdmins
* @summary Renvoie la liste des admins en String
* @return {Promise(String[])}
* @async
*/
async auxAdmins(): Promise<string[]> {
await this.fetchData();
return this.m_admins;
}
/**
* @memberof GraphQL.SimpleGroup#
* @function likers
......@@ -747,7 +763,16 @@ export class MetaGroup extends Group {
*/
async admins(args, context: Context, info): Promise<User[]> {
if (context.models.auth.isViewer(this.gid)) {
throw "Not implemented";
let admins = new Set<string>();
let arg = await context.models.group.getAllSimpleGroupsFromMeta(this.gid);
for(let g of arg){
let sg=new SimpleGroup(g);
let sg_admins= await sg.auxAdmins();
for(let admin of sg_admins){
admins.add(admin);
}
}
return [...admins].map(uid => new User(uid));
}
throw new AuthenticationError("Not a viewer");
}
......@@ -762,7 +787,12 @@ export class MetaGroup extends Group {
*/
async members(args, context: Context, info): Promise<SimpleGroup[]> {
if (context.models.auth.isViewer(this.gid)) {
throw "Not implemented"
let arg = await context.models.group.getAllSimpleGroupsFromMeta(this.gid);
let res = new Array<SimpleGroup>();
for(let g of arg){
res.push(new SimpleGroup(g));
}
return res;
/*let member_group_list = await knex.distinct().select().from('groups')
.innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment