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

du code

parent 55f425f4
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
*/ */
import knex from '../../db/knex_router'; import knex from '../../db/knex_router';
import { rens, idTOL, listGroups, listMembers } from '../ldap/ldap_data'; import { rens, idTOL, listGroups, listMembers, listAdmins } from '../ldap/ldap_data';
import { makeExecutableSchema } from 'graphql-tools'; import { makeExecutableSchema } from 'graphql-tools';
import { request } from 'https'; import { request } from 'https';
import { assertBinaryExpression } from 'babel-types';
const typeDefs = ` const typeDefs = `
type Query { type Query {
...@@ -34,11 +35,12 @@ const typeDefs = ` ...@@ -34,11 +35,12 @@ const typeDefs = `
type Mutation { type Mutation {
createGroup( createGroup(
uid: ID, uid: ID = null,
name: String, name: String,
website: String website: String,
description: String description: String,
school: String school: String,
parentuid : String
): Group ): Group
} }
...@@ -81,9 +83,39 @@ const getGroupIfVisible = (user, uid) => { ...@@ -81,9 +83,39 @@ const getGroupIfVisible = (user, uid) => {
}); });
}; };
/**
* @summary Renvoie tous les utilisateurs ayant des droits d'administrateur sur un groupe.
* @desc Les utilisateurs qui ont un droit d'administrateur sur un groupe sont ses administrateurs et les utilisateurs ayant droit d'admin sur son parent
* @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 = (uid) => {
return listAdmins(uid);
};
/**
* @summary Attribue un UID qui n'a pas encore été utilisé à un groupe
* @desc RASifie le string initialUID si necessaire (ramené à de l'ASCCI sans espace), puis si l'uid est deja pris rajoute un n a la fin et reteste
* @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 getAvailableGroupUID = (initialUID) => {
let rasUID = initialUID;
}
const createGroupIfLegal = (user, args) => { const createGroupIfLegal = (user, args) => {
if(typeof args.parentuid != String)
throw "Illegal argument : parentuid must be a string";
let admins = getUsersWithAdminRights(args.parentuid)
if(typeof admins == undefined)
throw "invalid argument : no group with id " + args.parentuid;
return admins.then( admin_list => {
if(admin_list.indexOf(user.id) == -1)
throw "illegal request : you must have admin rights over a group to create a subgroup of that group";
});
} };
const resolvers = { const resolvers = {
Query: { Query: {
......
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