mizozobu 6 лет назад
Родитель
Сommit
b5f7bac86f

+ 18 - 7
src/client/js/components/Admin/UserGroup/UserGroupCreateForm.jsx

@@ -38,15 +38,26 @@ class UserGroupCreateForm extends React.Component {
         name: this.state.name,
       });
 
-      if (res.ok) {
-        const { userGroup, userGroupRelation } = res;
-        this.props.onCreate(userGroup, userGroupRelation);
-        this.setState({ name: '' });
-        apiSuccessHandler(`Created a user group "${this.xss.process(userGroup.name)}"`);
-      }
-      else {
+      if (!res.ok) {
         throw new Error(`Unable to create a group "${this.xss.process(this.state.name)}"`);
       }
+
+      const userGroup = res.userGroup;
+      const userGroupId = userGroup._id;
+
+      const res2 = await this.props.crowi.apiGet(`/v3/user-groups/${userGroupId}/users`);
+
+      if (!res2.ok) {
+        throw new Error(`Unable to fetch users for the new group "${this.xss.process(userGroup.name)}"`);
+      }
+
+      const users = res2.users;
+
+      this.props.onCreate(userGroup, users);
+
+      this.setState({ name: '' });
+
+      apiSuccessHandler(`Created a user group "${this.xss.process(userGroup.name)}"`);
     }
     catch (err) {
       apiErrorHandler(err);

+ 3 - 3
src/client/js/components/Admin/UserGroup/UserGroupPage.jsx

@@ -43,14 +43,14 @@ class UserGroupPage extends React.Component {
     });
   }
 
-  addUserGroup(newUserGroup, newUserGroupRelation) {
+  addUserGroup(userGroup, users) {
     this.setState((prevState) => {
       const userGroupRelations = Object.assign(prevState.userGroupRelations, {
-        [newUserGroup._id]: newUserGroupRelation,
+        [userGroup._id]: users,
       });
 
       return {
-        userGroups: [...prevState.userGroups, newUserGroup],
+        userGroups: [...prevState.userGroups, userGroup],
         userGroupRelations,
       };
     });

+ 3 - 9
src/server/routes/apiv3/user-group.js

@@ -31,15 +31,9 @@ module.exports = (crowi) => {
     const { name } = req.body;
     try {
       const userGroupName = crowi.xss.process(name);
-      const newUserGroup = await UserGroup.createGroupByName(userGroupName);
-      const userGroupRelations = await UserGroupRelation.findAllRelationForUserGroup(newUserGroup);
+      const userGroup = await UserGroup.createGroupByName(userGroupName);
 
-      const data = {
-        userGroup: newUserGroup,
-        userGroupRelation: userGroupRelations,
-      };
-
-      return res.json(ApiResponse.success(data));
+      return res.json(ApiResponse.success({ userGroup }));
     }
     catch (err) {
       const msg = 'Error occurred in creating a user group';
@@ -85,7 +79,7 @@ module.exports = (crowi) => {
       return res.json(ApiResponse.success({ users }));
     }
     catch (err) {
-      const msg = `Error occurred in fetching user group relations for group: ${id}`;
+      const msg = `Error occurred in fetching users for group: ${id}`;
       logger.error(msg, err);
       return res.json(ApiResponse.error(msg));
     }