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

je passe l'objet user au code LDAP a présent

parent cb9c5319
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ const typeDefs = `
*/
const getAllVisibleGroups = (user) => {
return listGroups(user.id).then(group_ids => {
return listGroups(user.uid, user).then(group_ids => {
var membered_groups = qb => qb.select().from('groups').whereIn('uid', group_ids.concat(['kes']));
/* membered_groups est un callback qui reçoit un argument qb représentant un objet de requête (un truc qui s'utilise comme knex())
* et effectue dessus la requête pour obtenir une table de tous les groupes dont user est membre
......@@ -91,7 +91,7 @@ const getGroupIfVisible = (user, uid) => {
* @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);
return listAdmins(uid, user);
};
/**
......@@ -101,9 +101,15 @@ const getUsersWithAdminRights = (uid) => {
* @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;
rasUID.replace(' ', '_');
rasUID.replace(/\W/g, '');
let rasUID = initialUID.replace(' ', '_').replace(/\W/g, '');
return knex.from('groups').where('uid', rasUID).then(res =>{
if(res.length == 0){
return(rasUID);
}else{
return(getAvailableGroupUID(rasUID + 'n'));
}
});
return rasUID;
};
const createGroupIfLegal = (user, args) => {
......@@ -115,9 +121,10 @@ const createGroupIfLegal = (user, args) => {
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";
return(getAvailableGroupUID(args.uid).then(res => {
}));
});
};
const resolvers = {
......@@ -152,7 +159,10 @@ const resolvers = {
Mutation: {
createGroup: (obj, args, context) => {
return createGroupIfLegal(context.user, args);
getAvailableGroupUID("subaïsse").then(res => console.log(res));
getAvailableGroupUID("br").then(res => console.log(res));
return null;
//return createGroupIfLegal(context.user, args);
}
}
};
......
......@@ -35,17 +35,22 @@ server.use(morgan('dev'));
server.use('/graphql', bodyParser.json(), cors(),
graphqlExpress(req => {
let uid;
let password;
try {
uid = "anatole.romon";
uid = "louis.vanneau";
password = "mythe"
//uid = req.session.id;
//password = req.session.password;
} catch (err) {
uid = "1";
uid = "louis.vanneau";
password = "mythe"
}
return {
schema : schema,
context : {user : {id : uid}}
context : {user : {uid : uid, password : password}}
};
}));
......
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