Show More
@@ -490,18 +490,22 b' class UserGroupModel(BaseModel):' | |||
|
490 | 490 | |
|
491 | 491 | def enforce_groups(self, user, groups, extern_type=None): |
|
492 | 492 | user = self._get_user(user) |
|
493 | log.debug('Enforcing groups %s on user %s', groups, user) | |
|
494 | 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 | 497 | # calculate from what groups user should be removed |
|
500 | # externals that are not in groups | |
|
501 | for gr in externals: | |
|
502 | if gr.users_group_name not in groups: | |
|
503 | log.debug('Removing user %s from user group %s', user, gr) | |
|
504 |
|
|
|
498 | # external_groups that are not in groups | |
|
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: | |
|
503 | log.debug('Removing user %s from user group %s. ' | |
|
504 | 'Group sync managed by: %s', user, gr, managed) | |
|
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 | 510 | # now we calculate in which groups user should be == groups params |
|
507 | 511 | owner = User.get_first_super_admin().username |
@@ -513,8 +517,10 b' class UserGroupModel(BaseModel):' | |||
|
513 | 517 | existing_group = UserGroupModel().create( |
|
514 | 518 | gr, desc, owner, group_data={'extern_type': extern_type}) |
|
515 | 519 | |
|
516 |
# we can only add users to |
|
|
517 | managed = 'extern_type' in existing_group.group_data | |
|
520 | # we can only add users to groups which have set sync flag via | |
|
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 | 524 | if managed: |
|
519 | 525 | log.debug('Adding user %s to user group %s', user, gr) |
|
520 | 526 | UserGroupModel().add_user_to_group(existing_group, user) |
General Comments 0
You need to be logged in to leave comments.
Login now