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 { ...@@ -151,6 +151,21 @@ export class GroupModel {
return res; 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# * @memberof GraphQL.GroupModel#
* @function likeGroup * @function likeGroup
......
...@@ -75,6 +75,24 @@ export class MessageModel { ...@@ -75,6 +75,24 @@ export class MessageModel {
return Question.tryCreate(mid); 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# * @memberof GraphQL.MessageModel#
* @function getAnswer * @function getAnswer
...@@ -88,6 +106,25 @@ export class MessageModel { ...@@ -88,6 +106,25 @@ export class MessageModel {
return Answer.tryCreate(mid); 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# * @memberof GraphQL.MessageModel#
* @function getAllMessages * @function getAllMessages
......
...@@ -119,6 +119,21 @@ export class Tools { ...@@ -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 * @memberof GraphQL
* @summary Fonction qui renvoit tous les groupes (simples ou méta) dont le user est membre. * @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'; ...@@ -11,6 +11,8 @@ import { Context } from '../typeDefs/queries';
import { ApolloError, AuthenticationError } from 'apollo-server-core'; import { ApolloError, AuthenticationError } from 'apollo-server-core';
import { Request, UserJoinGroup, GroupJoinMetagroup, GroupCoauthorEvent } from './requests'; import { Request, UserJoinGroup, GroupJoinMetagroup, GroupCoauthorEvent } from './requests';
import { GroupSet } from '../models/tools'; import { GroupSet } from '../models/tools';
import { is } from 'bluebird';
import { userData } from '../../ldap/export/user';
export abstract class Group { export abstract class Group {
...@@ -190,7 +192,7 @@ export abstract class Group { ...@@ -190,7 +192,7 @@ export abstract class Group {
*/ */
async questions(args, context: Context, info): Promise<Question[]> { async questions(args, context: Context, info): Promise<Question[]> {
if (context.models.auth.isViewer(this.gid)) { 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); // let result = await knex('questions').select().whereIn('id', received_messages);
// for(let entry of result){ // for(let entry of result){
...@@ -211,7 +213,7 @@ export abstract class Group { ...@@ -211,7 +213,7 @@ export abstract class Group {
*/ */
async answers(args, context: Context, info): Promise<Answer[]> { async answers(args, context: Context, info): Promise<Answer[]> {
if (context.models.auth.isViewer(this.gid)) { 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 received_messages = await selectors.recievedMessages(user, groupUID);
// let result = await knex('answers').select().whereIn('id', received_messages); // let result = await knex('answers').select().whereIn('id', received_messages);
...@@ -552,14 +554,28 @@ export class SimpleGroup extends Group { ...@@ -552,14 +554,28 @@ export class SimpleGroup extends Group {
*/ */
async admins(args, context: Context, info): Promise<User[]> { async admins(args, context: Context, info): Promise<User[]> {
if(context.models.auth.isViewer(this.gid)) { if(context.models.auth.isViewer(this.gid)) {
await this.fetchData(); let list_admins =await this.auxAdmins();
return this.m_admins.map(uid => { return list_admins.map(uid => {
return new User(uid); return new User(uid);
}); });
} }
throw new AuthenticationError("Not a viewer"); 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# * @memberof GraphQL.SimpleGroup#
* @function likers * @function likers
...@@ -747,7 +763,16 @@ export class MetaGroup extends Group { ...@@ -747,7 +763,16 @@ export class MetaGroup extends Group {
*/ */
async admins(args, context: Context, info): Promise<User[]> { async admins(args, context: Context, info): Promise<User[]> {
if (context.models.auth.isViewer(this.gid)) { 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"); throw new AuthenticationError("Not a viewer");
} }
...@@ -762,7 +787,12 @@ export class MetaGroup extends Group { ...@@ -762,7 +787,12 @@ export class MetaGroup extends Group {
*/ */
async members(args, context: Context, info): Promise<SimpleGroup[]> { async members(args, context: Context, info): Promise<SimpleGroup[]> {
if (context.models.auth.isViewer(this.gid)) { 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') /*let member_group_list = await knex.distinct().select().from('groups')
.innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid') .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