From f380d82b550ed59c4b35a88ff1cb4c1332429f90 Mon Sep 17 00:00:00 2001 From: BaiJiangJie <32935519+BaiJiangJie@users.noreply.github.com> Date: Tue, 27 Nov 2018 10:21:47 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E5=B0=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#2100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Update] 不修改admin用户的用户来源 * [Bugfix] 修复Default组织下用户列表会显示所有用户,并查看详情会报错 * [Update] 关闭telnet资产测试可连接性 * [Update] 只有ssh协议资产可测试连接性 --- apps/assets/templates/assets/asset_detail.html | 2 +- apps/authentication/signals_handlers.py | 11 +++++++++-- apps/users/api/user.py | 2 +- apps/users/signals_handler.py | 7 ------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/assets/templates/assets/asset_detail.html b/apps/assets/templates/assets/asset_detail.html index 378de8b98..51e5adaf2 100644 --- a/apps/assets/templates/assets/asset_detail.html +++ b/apps/assets/templates/assets/asset_detail.html @@ -159,7 +159,7 @@ - {% if asset.is_unixlike %} + {% if asset.protocol == 'ssh' %} {% trans 'Refresh hardware' %}: diff --git a/apps/authentication/signals_handlers.py b/apps/authentication/signals_handlers.py index 7cf240386..d45ea1dfa 100644 --- a/apps/authentication/signals_handlers.py +++ b/apps/authentication/signals_handlers.py @@ -1,7 +1,8 @@ from django.http.request import QueryDict -from django.contrib.auth.signals import user_logged_out -from django.dispatch import receiver from django.conf import settings +from django.dispatch import receiver +from django.contrib.auth.signals import user_logged_out +from django_auth_ldap.backend import populate_user from .openid import client from .signals import post_create_openid_user @@ -31,3 +32,9 @@ def on_post_create_openid_user(sender, user=None, **kwargs): user.source = user.SOURCE_OPENID user.save() + +@receiver(populate_user) +def on_ldap_create_user(sender, user, ldap_user, **kwargs): + if user and user.name != 'admin': + user.source = user.SOURCE_LDAP + user.save() diff --git a/apps/users/api/user.py b/apps/users/api/user.py index b343dca78..c01f5b1d3 100644 --- a/apps/users/api/user.py +++ b/apps/users/api/user.py @@ -39,7 +39,7 @@ class UserViewSet(IDInFilterMixin, BulkModelViewSet): def get_queryset(self): queryset = super().get_queryset() - if current_org.is_real(): + if current_org.is_real() or current_org.is_default(): org_users = current_org.get_org_users() queryset = queryset.filter(id__in=org_users) return queryset diff --git a/apps/users/signals_handler.py b/apps/users/signals_handler.py index 7473434d0..1bc3ef430 100644 --- a/apps/users/signals_handler.py +++ b/apps/users/signals_handler.py @@ -2,7 +2,6 @@ # from django.dispatch import receiver -from django_auth_ldap.backend import populate_user # from django.db.models.signals import post_save from common.utils import get_logger @@ -30,9 +29,3 @@ def on_user_create(sender, user=None, **kwargs): if user.email: send_user_created_mail(user) - -@receiver(populate_user) -def on_ldap_create_user(sender, user, ldap_user, **kwargs): - if user: - user.source = user.SOURCE_LDAP - user.save()