Commit 64f18ddb authored by Olivér FACKLAM's avatar Olivér FACKLAM

Merge branch 'mutations_priority_3' into 'master'

Mutations priority 3

See merge request !70
parents 17636ee9 b8c76fd4
Pipeline #5751 failed with stages
in 2 minutes and 2 seconds
......@@ -10,6 +10,8 @@ exports.up = function (knex, Promise) {
table.string('gid').notNullable()
.references('gid').inTable('groups')
.onDelete('CASCADE');
table.unique(['uid', 'gid']);
});
};
......
......@@ -187,6 +187,22 @@ export class AuthorizationModel {
}
return false;
}
async isMemberAnd(groups: GroupSet): Promise<boolean> {
//ensure uid is valid !!!!!!!!
if (this.isAuthenticated()) {
await this.m_loader.load();
let member = this.memberOf;
for (let gid of groups) {
if (!member.simpleGroups.has(gid) && !member.metaGroups.has(gid)) {
return false;
}
}
return true;
}
return false;
}
/**
* @memberof GraphQL.AuthorizationModel#
......
......@@ -264,15 +264,14 @@ export class GroupModel {
/**
* @memberof GraphQL.GroupModel#
* @function likeGroup
* @summary Fonction pour devenir sympathisant
* @summary Fonction pour devenir sympathisant.
* @arg {string} gid - Identifiant du groupe.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights viewer du groupe
* @rights viewer du groupe, connected
*/
async likeGroup(gid: string): Promise<boolean> {
// Pour l'instant, ce n'est pas a implémenter...
throw "Not implemented";
return LDAP_Group.addFollower(this.contextUser, gid);
}
/**
......@@ -282,11 +281,27 @@ export class GroupModel {
* @arg {string} gid - Identifiant du groupe.
* @return {Promise(boolean)} Renvoie true si modification réussie.
* @async
* @rights viewer du groupe
* @rights viewer du groupe, connected
*/
async unlikeGroup(gid: string): Promise<boolean> {
// Pour l'instant, ce n'est pas a implémenter...
throw "Not implemented";
return LDAP_Group.remFollower(this.contextUser, gid);
}
/**
* Les données doivent exister en SQL.
* @rights viewer du groupe, connected
*/
async dislikeGroup(gid: string): Promise<boolean> {
let res = await knex("user_dislike_group").insert({ uid: this.contextUser, gid: gid }, ["id"]);
return res.length > 0;
}
/**
* @rights viewer du groupe, connected
*/
async undislikeGroup(gid: string): Promise<boolean> {
let res = await knex("user_dislike_group").where("uid", this.contextUser).andWhere("gid", gid).del();
return res > 0;
}
/**
......@@ -326,31 +341,35 @@ export class GroupModel {
* @rights admin du groupe
*/
async createSubgroup(args: createSubgroupArgs): Promise<Group> {
throw "Not implemented";
//TODO : Vérifier que 'parent' est un groupe _simple_.
// Check that parent is a _simple_ group
let pgid = args.fromGroup;
let parent = await this.getSimpleGroup(pgid, true);
if(!parent)
throw new ApolloError("Parent doesn't exist");
// Create groupData
let data = new groupData();
// TODO : data.category
data.name = args.subName;
data.description = args.subDescription;
data.email = args.subMail;
data.site = args.subWebsite;
data.parents = [pgid];
// Call LDAP add function for group creation
if(! await LDAP_Group.create(data))
throw "Creation failed";
// TODO : finish
throw "Not implemented";
/*let group = await this.getSimpleGroup(subgid, true);
if(!group)
throw "Creation failed";
await knex('groups').insert({gid: subgid, type: "simple"});
await knex('simplegroups').insert({gid: subgid});
/*if (typeof args.fromGroup != 'string')
throw "Illegal argument : parent_uid must be a non null string";
if (typeof args.subName != 'string')
throw "Illegal argument : name must be a non null string";
let rasGID = await getAvailableGID(args.subGid);
// TODO : appeller une fonction de LDAPUser pour y créer un groupe.
await knex('simple_groups').insert({
uid: rasGID,
parent_uid: args.parent_uid,
createdAt: knex.fn.now(),
updatedAt: this.createdAt,
name: args.name,
website: args.website,
description: args.description,
school: args.school,
type: "simple"
});
return getGroup(rasGID);*/
return group;*/
}
/**
......
......@@ -484,77 +484,53 @@ export class MessageModel {
/**
* @memberof GraphQL.MessageModel#
* @function userParticipate
* @summary Fonction pour participer a un evenement.
* @arg {string} uid - Identifiant de l'utilisateur.
* @arg {number} mid - Identifiant de l'évenement.
* @summary Fonction pour participer a un evenement. Les données doivent exister en SQL.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient
*/
async userParticipate(uid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_users").insert({mid : mid, uid : uid}, ['id']);
return true;
}catch(e){
return false;
}
async userParticipate(uid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_users").insert({eid : eid, uid : uid}, ['id']);
return res.length > 0;
}
/**
* @memberof GraphQL.MessageModel#
* @function userUnparticipate
* @summary Fonction pour ne plus participer a un evenement.
* @arg {string} uid - Identifiant de l'utilisateur.
* @arg {number} mid - Identifiant de l'évenement.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient
*/
async userUnparticipate(uid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_users").where('mid' , mid).andWhere('uid',uid ).del();
return true;
}catch(e){
return false;
}
async userUnparticipate(uid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_users").where('eid', eid).andWhere('uid', uid).del();
return res > 0;
}
/**
* @memberof GraphQL.MessageModel#
* @function groupParticipate
* @summary Fonction pour participer a un evenement.
* @arg {string} gid - Identifiant du groupe.
* @arg {number} mid - Identifiant de l'évenement.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient pour l'event, speaker pour le groupe
*/
async groupParticipate(gid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_groups").insert({gid : gid, mid : mid}, ['id']);
return true;
}catch(e){
return false;
}
async groupParticipate(gid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_groups").insert({gid : gid, eid : eid}, ['id']);
return res.length > 0;
}
/**
* @memberof GraphQL.MessageModel#
* @function groupUnparticipate
* @summary Fonction pour ne plus participer a un evenement.
* @arg {string} gid - Identifiant du groupe.
* @arg {number} mid - Identifiant de l'évenement.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient pour l'event, speaker du groupe
*/
async groupUnparticipate(gid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_groups").where('mid' , mid).andWhere('gid',gid ).del();
return true;
}catch(e){
return false;
}
async groupUnparticipate(gid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_groups").where('eid', eid).andWhere('gid', gid).del();
return res > 0;
}
/**
......
This diff is collapsed.
......@@ -122,6 +122,8 @@ type Mutation {
# Viewer mutations
likeGroup(gid: ID!): Boolean # devenir sympathisant
unlikeGroup(gid: ID!): Boolean
dislikeGroup(gid: ID!): Boolean
undislikeGroup(gid: ID!): Boolean
userRequestJoinGroup(toGroup: ID!, comment: String): UserJoinGroup
......@@ -229,7 +231,6 @@ type Mutation {
# Admin mutations
createSubgroup(
fromGroup: ID!,
subGid: ID,
subName: String!,
subDescription: String,
subMail: String,
......
......@@ -42,7 +42,6 @@ interface editProfileArgs {
interface createSubgroupArgs {
fromGroup: string,
subGid: string,
subName: string,
subDescription: string,
subMail: string,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment