Skip to content
Snippets Groups Projects
Commit e56df0d6 authored by Anatole ROMON's avatar Anatole ROMON
Browse files

travail sur les membres

parent d291a0e0
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,13 @@ exports.seed = function(knex, Promise) { ...@@ -21,6 +21,13 @@ exports.seed = function(knex, Promise) {
school: 'polytechnique', school: 'polytechnique',
parentuid: 'kes', parentuid: 'kes',
type : 'simple' type : 'simple'
},{
name: 'Faërix',
uid: 'faerix',
website: 'faerix.net',
school: 'polytechnique',
parentuid: 'kes',
type : 'simple'
},{ },{
name: 'Bôbar', name: 'Bôbar',
uid: 'bob', uid: 'bob',
......
...@@ -264,8 +264,9 @@ export async function getAllVisibleGroups(user){ ...@@ -264,8 +264,9 @@ export async function getAllVisibleGroups(user){
* @return {Promise(Boolean)} Boolean indiquant si l'utilisateur est membre du groupe. * @return {Promise(Boolean)} Boolean indiquant si l'utilisateur est membre du groupe.
* @rights user * @rights user
*/ */
export const isMember = (user, groupUID) => { export async function isMember(user, groupUID){
return listerGroupes(user, user.uid).then(group_ids => group_ids && group_ids.indexOf(groupUID) != -1); let member_list = await getGroupMemberUsers(user, groupUID);
return member_list && member_list.indexOf(groupUID) != -1;
}; };
/** /**
...@@ -462,8 +463,7 @@ export const getMetaGroupAdminMembers = (user, metaGroupUID) => { ...@@ -462,8 +463,7 @@ export const getMetaGroupAdminMembers = (user, metaGroupUID) => {
}; };
/** /**
* @function getMetaGroupMembers * @summary Renvoie un callback qui génère tous les membres d'un meta-groupe.
* @summary Renvoie tous les membres d'un meta-groupe.
* @param {Object} user - Utilisateur effectuant la requête. * @param {Object} user - Utilisateur effectuant la requête.
* @param {String} metaGroupUID - Identifiant unique du groupe. * @param {String} metaGroupUID - Identifiant unique du groupe.
* @return {Promise(callback)} a callback to build a query for the members of a group * @return {Promise(callback)} a callback to build a query for the members of a group
...@@ -478,4 +478,56 @@ export async function getMetaGroupMembersCallback(user, metaGroupUID){ ...@@ -478,4 +478,56 @@ export async function getMetaGroupMembersCallback(user, metaGroupUID){
.innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid') .innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid')
.where('meta_group_membership.union_uid', '=', metaGroupUID); .where('meta_group_membership.union_uid', '=', metaGroupUID);
}; };
}; };
\ No newline at end of file
/**
* @summary Renvoie un callback qui génère tous les membres admin d'un meta-groupe.
* @param {Object} user - Utilisateur effectuant la requête.
* @param {String} metaGroupUID - Identifiant unique du groupe.
* @return {Promise(callback)} a callback to build a query for the admin members of a group
* @author akka vodol
* @rights member(metaGroupUID)
*/
export async function getMetaGroupAdminMembersCallback(user, metaGroupUID){
return function(query_builder){
return query_builder.distinct().select().from('groups')
.innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid')
.where('meta_group_membership.union_uid', '=', metaGroupUID)
.where('meta_group_membership.status', '=', 'admin');
};
};
/**
* @summary Renvoie les membres d'un groupe quelquonque.
* @param {Object} user - Utilisateur effectuant la requête.
* @param {String} metaGroupUID - Identifiant unique du groupe.
* @return {Promise(List)} Une liste des uid de tous les membres du groupe
* @author akka vodol
* @rights member(metaGroupUID)
*/
export async function getGroupMemberUsers(user, GroupUID){
switch( await getGroupType(user, GroupUID) ){
case "simple":
return listerMembres(user, GroupUID);
case "meta":
return getMetaGroupMemberUsers(user, GroupUID);
default:
return undefined;
}
};
/**
* @summary Renvoie les membres d'un meta groupe.
* @param {Object} user - Utilisateur effectuant la requête.
* @param {String} metaGroupUID - Identifiant unique du groupe.
* @return {Promise(List)} Une liste des uid de tous les membres du groupe
* @author akka vodol
* @rights member(metaGroupUID)
*/
export async function getMetaGroupMemberUsers(user, metaGroupUID){
let member_group_list = await getMetaGroupMembersCallback(user, metaGroupUID).then(cb => cb(knex));
let members = [];
for(memberGroup of await member_group_list){
members = members.concat(getGroupMemberUsers(user, metaGroupUID));
}
};
...@@ -23,8 +23,12 @@ export const resolvers = { ...@@ -23,8 +23,12 @@ export const resolvers = {
throw "You do not have admin rights over this group"; throw "You do not have admin rights over this group";
}, },
asMember: function (obj, args, context){ asMember: async function (obj, args, context){
return {groupUID : args.groupUID}; if(await connectors.isMember(context.user, args.groupUID)
|| connectors.hasAdminRights(context.user, args.groupUID))
return {groupUID : args.groupUID};
else
throw "You do not have member rights over this group";
}, },
accessGroups: (obj, args, context) => { accessGroups: (obj, args, context) => {
......
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