Merge pull request #11118 from jumpserver/pr@dev@perf_filter_and_default_group

perf: 添加到默认组织中
pull/11128/head
老广 2023-07-28 16:52:00 +08:00 committed by GitHub
commit 83917cb440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -13,7 +13,7 @@ class AccountFilterSet(BaseFilterSet):
hostname = drf_filters.CharFilter(field_name='name', lookup_expr='exact')
username = drf_filters.CharFilter(field_name="username", lookup_expr='exact')
address = drf_filters.CharFilter(field_name="asset__address", lookup_expr='exact')
asset = drf_filters.CharFilter(field_name="asset_id", lookup_expr='exact')
asset_id = drf_filters.CharFilter(field_name="asset", lookup_expr='exact')
assets = drf_filters.CharFilter(field_name='asset_id', lookup_expr='exact')
nodes = drf_filters.CharFilter(method='filter_nodes')
node_id = drf_filters.CharFilter(method='filter_nodes')
@ -45,7 +45,7 @@ class AccountFilterSet(BaseFilterSet):
class Meta:
model = Account
fields = ['id', 'asset_id', 'source_id', 'secret_type']
fields = ['id', 'asset', 'source_id', 'secret_type']
class GatheredAccountFilterSet(BaseFilterSet):

View File

@ -103,8 +103,12 @@ def on_user_created_set_default_org(sender, instance, created, **kwargs):
return
if instance.orgs.count() > 0:
return
with tmp_to_org(Organization.default()):
Organization.default().add_member(instance)
default_org = Organization.default()
with tmp_to_org(default_org):
default_org.add_member(instance)
default_group = UserGroup.objects.filter(name='Default').first()
if default_group:
default_group.users.add(instance)
def _remove_user_resource(model, users, org, user_field_name='users'):