##// END OF EJS Templates
user-groups: fix potential problem with group sync of external plugins....
marcink -
r2193:20e24a44 stable
parent child Browse files
Show More
@@ -490,18 +490,22 b' class UserGroupModel(BaseModel):'
490
490
491 def enforce_groups(self, user, groups, extern_type=None):
491 def enforce_groups(self, user, groups, extern_type=None):
492 user = self._get_user(user)
492 user = self._get_user(user)
493 log.debug('Enforcing groups %s on user %s', groups, user)
494 current_groups = user.group_member
493 current_groups = user.group_member
495 # find the external created groups
496 externals = [x.users_group for x in current_groups
497 if 'extern_type' in x.users_group.group_data]
498
494
495 # find the external created groups, i.e automatically created
496 log.debug('Enforcing user group set `%s` on user %s', groups, user)
499 # calculate from what groups user should be removed
497 # calculate from what groups user should be removed
500 # externals that are not in groups
498 # external_groups that are not in groups
501 for gr in externals:
499 for gr in [x.users_group for x in current_groups]:
500 managed = gr.group_data.get('extern_type')
501 if managed:
502 if gr.users_group_name not in groups:
502 if gr.users_group_name not in groups:
503 log.debug('Removing user %s from user group %s', user, gr)
503 log.debug('Removing user %s from user group %s. '
504 'Group sync managed by: %s', user, gr, managed)
504 self.remove_user_from_group(gr, user)
505 self.remove_user_from_group(gr, user)
506 else:
507 log.debug('Skipping removal from group %s since it is '
508 'not set to be automatically synchronized' % gr)
505
509
506 # now we calculate in which groups user should be == groups params
510 # now we calculate in which groups user should be == groups params
507 owner = User.get_first_super_admin().username
511 owner = User.get_first_super_admin().username
@@ -513,8 +517,10 b' class UserGroupModel(BaseModel):'
513 existing_group = UserGroupModel().create(
517 existing_group = UserGroupModel().create(
514 gr, desc, owner, group_data={'extern_type': extern_type})
518 gr, desc, owner, group_data={'extern_type': extern_type})
515
519
516 # we can only add users to special groups created via plugins
520 # we can only add users to groups which have set sync flag via
517 managed = 'extern_type' in existing_group.group_data
521 # extern_type attribute.
522 # This is either set and created via plugins, or manually
523 managed = existing_group.group_data.get('extern_type')
518 if managed:
524 if managed:
519 log.debug('Adding user %s to user group %s', user, gr)
525 log.debug('Adding user %s to user group %s', user, gr)
520 UserGroupModel().add_user_to_group(existing_group, user)
526 UserGroupModel().add_user_to_group(existing_group, user)
General Comments 0
You need to be logged in to leave comments. Login now