Просмотр исходного кода

Merge branch 'imprv/user-group-create-update-parent' into imprv/user-group-delete

Taichi Masuyama 4 лет назад
Родитель
Сommit
b06b730f59

+ 6 - 2
packages/app/src/server/models/user-group-relation.js

@@ -272,8 +272,12 @@ class UserGroupRelation {
       });
   }
 
-  static async findWithUserByGroupIds(groupIds = null) {
-    return this.find(Array.isArray(groupIds) ? { relatedGroup: { $in: groupIds } } : {})
+  static async findWithUserByGroupIds(groupIds) {
+    if (!Array.isArray(groupIds)) {
+      throw Error('groupIds must be an array');
+    }
+
+    return this.find({ relatedGroup: { $in: groupIds } })
       .populate('relatedUser');
   }
 

+ 2 - 2
packages/app/src/server/models/user-group.js

@@ -79,8 +79,8 @@ class UserGroup {
   }
 
   static async findChildUserGroupsByParentIds(parentIds, includeGrandChildren = false) {
-    if (parentIds == null) {
-      throw Error('parentIds must not be null.');
+    if (!Array.isArray(parentIds)) {
+      throw Error('parentIds must be an array.');
     }
 
     const childUserGroups = await this.find({ parent: { $in: parentIds } });

+ 1 - 1
packages/app/src/server/routes/apiv3/user-group-relation.js

@@ -25,7 +25,7 @@ module.exports = (crowi) => {
   const { UserGroupRelation } = crowi.models;
 
   validator.list = [
-    query('groupIds', 'groupIds must be an array').optional().isArray(),
+    query('groupIds', 'groupIds is required and must be an array').isArray(),
     query('childGroupIds', 'childGroupIds must be an array').optional().isArray(),
   ];
 

+ 1 - 1
packages/app/src/server/routes/apiv3/user-group.js

@@ -66,7 +66,7 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: a result of `UserGroup.find`
    */
-  router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => {
+  router.get('/', loginRequiredStrictly, adminRequired, async(req, res) => { // TODO 85062: userGroups with no parent
     const { query } = req;
 
     // TODO 85062: improve sort