diff --git a/src/graphql/schema.js b/src/graphql/schema.js index a2c99eed08bc90fc6f666a65046548725a3eac71..b9488a9d75229dbf30b471616e0a88e21e6fed89 100644 --- a/src/graphql/schema.js +++ b/src/graphql/schema.js @@ -71,8 +71,20 @@ const typeDefs = ` * @arg {String} uid - L'uid du groupe dont on veut les administrateurs. * @return {Promise} Retour de requête knex. Promise qui renvera une liste de tous les utilisateurs ayant droit d'admin sur le groupe */ -const getUsersWithAdminRights = (user, groupuid) => { - return listAdmins(user, groupuid); +const getUsersWithAdminRights = (user, groupUID) => { + return listAdmins(user, groupUID).then(adminList => { + if(typeof adminList == "undefined") + return undefined; + else + return knex('groups').select('parentuid').where('uid', groupUID).then(reqResult => { + if(reqResult[0].parentuid) + return getUsersWithAdminRights(user, reqResult[0].parentuid).then(parentAdmins => { + return adminList.concat(parentAdmins); + }); + else + return adminList + }); + }); }; /** @@ -82,8 +94,8 @@ const getUsersWithAdminRights = (user, groupuid) => { * @return {Promise} Retour de requête knex. Liste de tous les groupes que l'utilisateur a le droit de voire. */ const hasAdminRights = (user, groupuid) => { - return getUsersWithAdminRights(user, groupuid).then(res => { - return (typeof res != "undefined" && res.indexOf(user.uid) != -1); + return getUsersWithAdminRights(user, groupuid).then(adminList => { + return (typeof adminList != "undefined" && adminList.indexOf(user.uid) != -1); }); }