Browse Source

check for duplicate users in groups

itizawa 6 years ago
parent
commit
7eb89ead90
1 changed files with 7 additions and 0 deletions
  1. 7 0
      src/server/routes/apiv3/user-group.js

+ 7 - 0
src/server/routes/apiv3/user-group.js

@@ -389,6 +389,13 @@ module.exports = (crowi) => {
         User.findUserByUsername(username),
       ]);
 
+      // check for duplicate users in groups
+      const isRelatedUserForGroup = await UserGroupRelation.isRelatedUserForGroup(userGroup, user);
+
+      if (isRelatedUserForGroup) {
+        throw new Error('The user is already joined');
+      }
+
       const userGroupRelation = await UserGroupRelation.createRelation(userGroup, user);
       await userGroupRelation.populate('relatedUser', User.USER_PUBLIC_FIELDS).execPopulate();