1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Check if a user exists before adding him to a conversation

This commit is contained in:
Pierre HUBERT 2020-06-15 11:04:03 +02:00
parent 45955cf524
commit 096f2da6a4
2 changed files with 18 additions and 2 deletions

View File

@ -98,8 +98,7 @@ export class ConversationsController {
// Update members list
if(h.hasPostParameter("members")) {
const members = h.postNumbersSet("members");
const members = await h.postUsersIDSet("members");
const canEveryoneAddMembers = await ConversationsHelper.CanEveryoneAddMembers(convID);
if(!isUserModerator && !canEveryoneAddMembers)

View File

@ -179,6 +179,23 @@ export abstract class BaseRequestsHandler implements AbstractUserConnectionConta
return new Set(this.postNumbersList(name, minEntries));
}
/**
* Get a list of users included in the POST request
*
* @param name The name of the POST field
* @param minEntries Minimum number of entries to specify
*/
public async postUsersIDSet(name: string, minEntries : number = 1) : Promise<Set<number>> {
const list = this.postNumbersSet(name, minEntries);
// Check the users of the list really exist
for(const userID of list)
if(!await UserHelper.Exists(userID))
this.error(404, "User " + userID + " not found!");
return list;
}
/**
* Attempt to decode JSON included in a POST request
*