diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 5b71d66..983f492 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -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) diff --git a/src/entities/BaseRequestsHandler.ts b/src/entities/BaseRequestsHandler.ts index 1eeb8ce..467294a 100644 --- a/src/entities/BaseRequestsHandler.ts +++ b/src/entities/BaseRequestsHandler.ts @@ -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> { + 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 *