Show More
@@ -504,18 +504,22 b' class UserGroupModel(BaseModel):' | |||||
504 |
|
504 | |||
505 | def enforce_groups(self, user, groups, extern_type=None): |
|
505 | def enforce_groups(self, user, groups, extern_type=None): | |
506 | user = self._get_user(user) |
|
506 | user = self._get_user(user) | |
507 | log.debug('Enforcing groups %s on user %s', groups, user) |
|
|||
508 | current_groups = user.group_member |
|
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 | # calculate from what groups user should be removed |
|
511 | # calculate from what groups user should be removed | |
514 | # externals that are not in groups |
|
512 | # external_groups that are not in groups | |
515 | for gr in externals: |
|
513 | for gr in [x.users_group for x in current_groups]: | |
516 | if gr.users_group_name not in groups: |
|
514 | managed = gr.group_data.get('extern_type') | |
517 | log.debug('Removing user %s from user group %s', user, gr) |
|
515 | if managed: | |
518 |
|
|
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 | # now we calculate in which groups user should be == groups params |
|
524 | # now we calculate in which groups user should be == groups params | |
521 | owner = User.get_first_super_admin().username |
|
525 | owner = User.get_first_super_admin().username | |
@@ -527,8 +531,10 b' class UserGroupModel(BaseModel):' | |||||
527 | existing_group = UserGroupModel().create( |
|
531 | existing_group = UserGroupModel().create( | |
528 | gr, desc, owner, group_data={'extern_type': extern_type}) |
|
532 | gr, desc, owner, group_data={'extern_type': extern_type}) | |
529 |
|
533 | |||
530 |
# we can only add users to |
|
534 | # we can only add users to groups which have set sync flag via | |
531 | managed = 'extern_type' in existing_group.group_data |
|
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 | if managed: |
|
538 | if managed: | |
533 | log.debug('Adding user %s to user group %s', user, gr) |
|
539 | log.debug('Adding user %s to user group %s', user, gr) | |
534 | UserGroupModel().add_user_to_group(existing_group, user) |
|
540 | UserGroupModel().add_user_to_group(existing_group, user) |
General Comments 0
You need to be logged in to leave comments.
Login now