fix: 修改创建用户时如果没有在任何组织内默认添加到default组织

pull/6319/head
Bai 3 years ago committed by Jiangjie.Bai
parent 40eb7c79bb
commit 62eb131f59

@ -15,6 +15,7 @@ from orgs.hands import set_current_org, Node, get_current_org
from perms.models import (AssetPermission, ApplicationPermission)
from users.models import UserGroup, User
from common.const.signals import PRE_REMOVE, POST_REMOVE
from common.decorator import on_transaction_commit
from common.signals import django_ready
from common.utils import get_logger
from common.utils.connection import RedisPubSub
@ -167,3 +168,13 @@ def on_org_user_changed(action, instance, reverse, pk_set, **kwargs):
leaved_users = set(pk_set) - set(org.members.filter(id__in=user_pk_set).values_list('id', flat=True))
_clear_users_from_org(org, leaved_users)
@receiver(post_save, sender=User)
@on_transaction_commit
def on_user_created_set_default_org(sender, instance, created, **kwargs):
if not created:
return
if instance.orgs.count() > 0:
return
Organization.default().members.add(instance)

@ -365,17 +365,12 @@ class LDAPImportUtil(object):
def perform_import(self, users):
logger.info('Start perform import ldap users, count: {}'.format(len(users)))
errors = []
instances = []
for user in users:
try:
obj, created = self.update_or_create(user)
if created:
instances.append(obj)
self.update_or_create(user)
except Exception as e:
errors.append({user['username']: str(e)})
logger.error(e)
# 默认添加用户到 Default 组织
Organization.default().members.add(*instances)
logger.info('End perform import ldap users')
return errors

@ -0,0 +1,9 @@
#!/bin/bash
#
python ../apps/manage.py shell << EOF
from users.models import User
from orgs.models import Organization
unorgs_users = [user for user in User.objects.all() if user.orgs.count() == 0]
Organization.default().members.add(*unorgs_users)
EOF
Loading…
Cancel
Save