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

# Fix/Bugs of grouping users
* fix bugs of feature grouping-users.

Tatsuya Ise 8 лет назад
Родитель
Сommit
b3e1cfac08
3 измененных файлов с 10 добавлено и 10 удалено
  1. 5 7
      lib/models/page.js
  2. 1 1
      lib/models/user-group.js
  3. 4 2
      lib/routes/admin.js

+ 5 - 7
lib/models/page.js

@@ -786,9 +786,6 @@ module.exports = function(crowi) {
 
   pageSchema.statics.updateGrant = function (page, grant, userData, grantUserGroupId) {
     var Page = this;
-    var PageGroupRelation = crowi.model('PageGroupRelation');
-    var UserGroupRelation = crowi.model('UserGroupRelation');
-    var provGrant = page.grant;
 
     if (grant == GRANT_USER_GROUP && grantUserGroupId == null) {
       throw new Error('grant userGroupId is not specified');
@@ -817,24 +814,25 @@ module.exports = function(crowi) {
   };
 
   pageSchema.statics.updateGrantUserGroup = function (page, grant, grantUserGroupId, userData) {
+    var UserGroupRelation = crowi.model('UserGroupRelation');
+    var PageGroupRelation = crowi.model('PageGroupRelation');
 
     // グループの場合
     if (grant == GRANT_USER_GROUP) {
       debug('grant is usergroup', grantUserGroupId);
-      UserGroupRelation.findByGroupIdAndUser(grantUserGroupId, userData)
+      return UserGroupRelation.findByGroupIdAndUser(grantUserGroupId, userData)
       .then((relation) => {
         if (relation == null) {
-          reject(new Error('no relations were exist for group and user.'));
+          return reject(new Error('no relations were exist for group and user.'));
         }
         return PageGroupRelation.findOrCreateRelationForPageAndGroup(page, relation.relatedGroup);
-
       })
       .catch((err) => {
         return reject(new Error('No UserGroup is exists. userGroupId : ', grantUserGroupId));
       });
     }
     else {
-      PageGroupRelation.removeAllByPage(page);
+      return PageGroupRelation.removeAllByPage(page);
     }
 
   };

+ 1 - 1
lib/models/user-group.js

@@ -115,7 +115,7 @@ class UserGroup {
   // グループ生成(名前が要る)
   static createGroupByName(name) {
 
-    return this.create(name);
+    return this.create({name: name});
   }
 
   /*

+ 4 - 2
lib/routes/admin.js

@@ -653,7 +653,7 @@ module.exports = function(crowi, app) {
       }
     })
     .then(() => {
-      return res.redirect('/admin/user-group-detail/' + userGroupData.name);
+      return res.redirect('/admin/user-group-detail/' + name);
     });
   };
 
@@ -794,8 +794,10 @@ module.exports = function(crowi, app) {
       User.findUserByUsername(userName),
     ])
     .then((resolves) => {
+      userGroup = resolves[0];
+      user = resolves[1];
       // Relation を作成
-      UserGroupRelation.createRelation(resolves[0], resolves[1])
+      UserGroupRelation.createRelation(userGroup, user)
     })
     .then((result) => {
       return res.redirect('/admin/user-group-detail/' + userGroup.name);