Commit 2391ce2d authored by jym503558564's avatar jym503558564

[Update] 修改小问题

parent 18d4d663
......@@ -119,7 +119,7 @@ class OperateLogListView(PermissionsMixin, DatetimeSearchMixin, ListView):
def get_context_data(self, **kwargs):
context = {
'user_list': current_org.get_org_users_and_auditors(),
'user_list': current_org.get_org_members(),
'actions': self.actions_dict,
'resource_type_list': get_resource_type_list(),
'date_from': self.date_from,
......@@ -142,7 +142,7 @@ class PasswordChangeLogList(PermissionsMixin, DatetimeSearchMixin, ListView):
permission_classes = [IsOrgAdmin | IsAuditor]
def get_queryset(self):
users = current_org.get_org_users_and_auditors()
users = current_org.get_org_members()
self.queryset = super().get_queryset().filter(
user__in=[user.__str__() for user in users]
)
......@@ -159,7 +159,7 @@ class PasswordChangeLogList(PermissionsMixin, DatetimeSearchMixin, ListView):
def get_context_data(self, **kwargs):
context = {
'user_list': current_org.get_org_users_and_auditors(),
'user_list': current_org.get_org_members(),
'date_from': self.date_from,
'date_to': self.date_to,
'user': self.user,
......@@ -180,7 +180,7 @@ class LoginLogListView(PermissionsMixin, DatetimeSearchMixin, ListView):
@staticmethod
def get_org_users():
users = current_org.get_org_users_and_auditors().values_list('username', flat=True)
users = current_org.get_org_members().values_list('username', flat=True)
return users
def get_queryset(self):
......@@ -234,7 +234,7 @@ class CommandExecutionListView(UserCommandExecutionListView):
return queryset
def get_user_list(self):
users = current_org.get_org_users_exclude_auditors()
users = current_org.get_org_members_exclude_anditors()
return users
def get_context_data(self, **kwargs):
......
......@@ -45,7 +45,7 @@ class IndexView(PermissionsMixin, TemplateView):
@staticmethod
def get_user_count():
return current_org.get_org_users_and_auditors().count()
return current_org.get_org_members().count()
@staticmethod
def get_asset_count():
......@@ -100,7 +100,7 @@ class IndexView(PermissionsMixin, TemplateView):
return self.session_month.values('user').distinct().count()
def get_month_inactive_user_total(self):
count = current_org.get_org_users_and_auditors().count() - self.get_month_active_user_total()
count = current_org.get_org_members().count() - self.get_month_active_user_total()
if count < 0:
count = 0
return count
......@@ -116,7 +116,7 @@ class IndexView(PermissionsMixin, TemplateView):
@staticmethod
def get_user_disabled_total():
return current_org.get_org_users_and_auditors().filter(is_active=False).count()
return current_org.get_org_members().filter(is_active=False).count()
@staticmethod
def get_asset_disabled_total():
......
......@@ -67,35 +67,20 @@ class Organization(models.Model):
org = cls.default() if default else None
return org
def get_org_users(self, include_app=False):
from users.models import User
if self.is_real():
users = self.users.all()
else:
users = User.objects.all()
if not include_app:
users = users.exclude(role=User.ROLE_APP)
return users
def get_org_users_and_auditors(self, include_app=False):
from users.models import User
# def get_org_users(self, include_app=False):
# from users.models import User
# if self.is_real():
# users = self.users.all()
# else:
# users = User.objects.all()
# if not include_app:
# users = users.exclude(role=User.ROLE_APP)
# return users
def get_org_users(self):
if self.is_real():
users = self.users.all() | self.auditors.all()
else:
users = User.objects.all()
if not include_app:
users = users.exclude(role=User.ROLE_APP)
return users
def get_org_users_exclude_auditors(self, include_app=False):
from users.models import User
if self.is_real():
users = self.users.all()
else:
users = User.objects.exclude(role=User.ROLE_AUDITOR)
if not include_app:
users = users.exclude(role=User.ROLE_APP)
return users
return self.users.all()
return []
def get_org_admins(self):
if self.is_real():
......@@ -107,6 +92,26 @@ class Organization(models.Model):
return self.auditors.all()
return []
def get_org_members(self, include_app=False):
from users.models import User
if self.is_real():
members = self.users.all() | self.auditors.all()
else:
members = User.objects.all()
if not include_app:
members = members.exclude(role=User.ROLE_APP)
return members
def get_org_members_exclude_auditors(self, include_app=False):
from users.models import User
if self.is_real():
members_exclude_auditors = self.users.all()
else:
members_exclude_auditors = User.objects.exclude(role=User.ROLE_AUDITOR)
if not include_app:
members_exclude_auditors = members_exclude_auditors.exclude(role=User.ROLE_APP)
return members_exclude_auditors
def can_admin_by(self, user):
if user.is_superuser:
return True
......
......@@ -39,7 +39,7 @@ class AssetPermissionForm(OrgModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
users_field = self.fields.get('users')
users_field.queryset = current_org.get_org_users_exclude_auditors()
users_field.queryset = current_org.get_org_members_exclude_anditors()
nodes_field = self.fields['nodes']
nodes_field.choices = ((n.id, n.full_value) for n in Node.get_queryset())
......
......@@ -19,7 +19,7 @@ class RemoteAppPermissionCreateUpdateForm(OrgModelForm):
super().__init__(*args, **kwargs)
users_field = self.fields.get('users')
if hasattr(users_field, 'queryset'):
users_field.queryset = current_org.get_org_users_exclude_auditors()
users_field.queryset = current_org.get_org_members_exclude_anditors()
class Meta:
model = RemoteAppPermission
......
......@@ -135,7 +135,7 @@ class AssetPermissionUserView(PermissionsMixin,
context = {
'app': _('Perms'),
'action': _('Asset permission user list'),
'users_remain': current_org.get_org_users_exclude_auditors().exclude(
'users_remain': current_org.get_org_members_exclude_anditors().exclude(
assetpermission=self.object
),
'user_groups_remain': UserGroup.objects.exclude(
......
......@@ -107,7 +107,7 @@ class RemoteAppPermissionUserView(PermissionsMixin,
context = {
'app': _('Perms'),
'action': _('RemoteApp permission user list'),
'users_remain': current_org.get_org_users_exclude_auditors().exclude(
'users_remain': current_org.get_org_members_exclude_anditors().exclude(
remoteapppermission=self.object
),
'user_groups_remain': UserGroup.objects.exclude(
......
......@@ -60,7 +60,7 @@ class UserViewSet(IDInCacheFilterMixin, BulkModelViewSet):
self.send_created_signal(users)
def get_queryset(self):
queryset = current_org.get_org_users_and_auditors().prefetch_related('groups')
queryset = current_org.get_org_members().prefetch_related('groups')
return queryset
def get_permissions(self):
......
......@@ -335,7 +335,7 @@ class UserGroupForm(OrgModelForm):
return
users_field = self.fields.get('users')
if hasattr(users_field, 'queryset'):
users_field.queryset = current_org.get_org_users_exclude_auditors()
users_field.queryset = current_org.get_org_members_exclude_auditors()
def save(self, commit=True):
group = super().save(commit=commit)
......
......@@ -76,7 +76,7 @@ class UserGroupDetailView(PermissionsMixin, DetailView):
permission_classes = [IsOrgAdmin]
def get_context_data(self, **kwargs):
users = current_org.get_org_users_exclude_auditors().exclude(id__in=self.object.users.all())
users = current_org.get_org_members_exclude_anditors().exclude(id__in=self.object.users.all())
context = {
'app': _('Users'),
'action': _('User group detail'),
......
......@@ -195,7 +195,7 @@ class UserDetailView(PermissionsMixin, DetailView):
def get_queryset(self):
queryset = super().get_queryset()
org_users = current_org.get_org_users_and_auditors().values_list('id', flat=True)
org_users = current_org.get_org_members().values_list('id', flat=True)
queryset = queryset.filter(id__in=org_users)
return queryset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment