Show More
@@ -504,18 +504,22 b' class UserGroupModel(BaseModel):' | |||
|
504 | 504 | |
|
505 | 505 | def enforce_groups(self, user, groups, extern_type=None): |
|
506 | 506 | user = self._get_user(user) |
|
507 | log.debug('Enforcing groups %s on user %s', groups, user) | |
|
508 | 507 | current_groups = user.group_member |
|
509 | # find the external created groups | |
|
510 | externals = [x.users_group for x in current_groups | |
|
511 | if 'extern_type' in x.users_group.group_data] | |
|
512 | 508 | |
|
509 | # find the external created groups, i.e automatically created | |
|
510 | log.debug('Enforcing user group set `%s` on user %s', groups, user) | |
|
513 | 511 | # calculate from what groups user should be removed |
|
514 | # externals that are not in groups | |
|
515 | for gr in externals: | |
|
516 | if gr.users_group_name not in groups: | |
|
517 | log.debug('Removing user %s from user group %s', user, gr) | |
|
518 |
|
|
|
512 | # external_groups that are not in groups | |
|
513 | for gr in [x.users_group for x in current_groups]: | |
|
514 | managed = gr.group_data.get('extern_type') | |
|
515 | if managed: | |
|
516 | if gr.users_group_name not in groups: | |
|
517 | log.debug('Removing user %s from user group %s. ' | |
|
518 | 'Group sync managed by: %s', user, gr, managed) | |
|
519 | self.remove_user_from_group(gr, user) | |
|
520 | else: | |
|
521 | log.debug('Skipping removal from group %s since it is ' | |
|
522 | 'not set to be automatically synchronized' % gr) | |
|
519 | 523 | |
|
520 | 524 | # now we calculate in which groups user should be == groups params |
|
521 | 525 | owner = User.get_first_super_admin().username |
@@ -527,8 +531,10 b' class UserGroupModel(BaseModel):' | |||
|
527 | 531 | existing_group = UserGroupModel().create( |
|
528 | 532 | gr, desc, owner, group_data={'extern_type': extern_type}) |
|
529 | 533 | |
|
530 |
# we can only add users to |
|
|
531 | managed = 'extern_type' in existing_group.group_data | |
|
534 | # we can only add users to groups which have set sync flag via | |
|
535 | # extern_type attribute. | |
|
536 | # This is either set and created via plugins, or manually | |
|
537 | managed = existing_group.group_data.get('extern_type') | |
|
532 | 538 | if managed: |
|
533 | 539 | log.debug('Adding user %s to user group %s', user, gr) |
|
534 | 540 | UserGroupModel().add_user_to_group(existing_group, user) |
General Comments 0
You need to be logged in to leave comments.
Login now