class OrgResourceStatisticsCache(OrgRelatedCache): users_amount = IntegerField() groups_amount = IntegerField(queryset=UserGroup.objects) assets_amount = IntegerField() nodes_amount = IntegerField(queryset=Node.objects) admin_users_amount = IntegerField() system_users_amount = IntegerField() domains_amount = IntegerField(queryset=Domain.objects) gateways_amount = IntegerField(queryset=Gateway.objects) applications_amount = IntegerField(queryset=Application.objects) asset_perms_amount = IntegerField(queryset=AssetPermission.objects) app_perms_amount = IntegerField(queryset=ApplicationPermission.objects) total_count_online_users = IntegerField() total_count_online_sessions = IntegerField() def __init__(self, org): super().__init__() self.org = org def get_key_suffix(self): return f'<org:{self.org.id}>' def get_current_org(self): return self.org def compute_admin_users_amount(self): return SystemUser.objects.filter(type=SystemUser.Type.admin).count() def compute_system_users_amount(self): return SystemUser.objects.filter(type=SystemUser.Type.common).count() def compute_users_amount(self): users = User.objects.exclude(role='App') if not self.org.is_root(): users = users.filter(m2m_org_members__org_id=self.org.id) users_amount = users.values('id').distinct().count() return users_amount def compute_assets_amount(self): if self.org.is_root(): return Asset.objects.all().count() node = Node.org_root() return node.assets_amount def compute_total_count_online_users(self): return Session.objects.filter( is_finished=False).values_list('user_id').distinct().count() def compute_total_count_online_sessions(self): return Session.objects.filter(is_finished=False).count()
class OrgResourceStatisticsCache(OrgRelatedCache): users_amount = IntegerField() groups_amount = IntegerField(queryset=UserGroup.objects) assets_amount = IntegerField() nodes_amount = IntegerField(queryset=Node.objects) admin_users_amount = IntegerField(queryset=AdminUser.objects) system_users_amount = IntegerField(queryset=SystemUser.objects) domains_amount = IntegerField(queryset=Domain.objects) gateways_amount = IntegerField(queryset=Gateway.objects) applications_amount = IntegerField(queryset=Application.objects) asset_perms_amount = IntegerField(queryset=AssetPermission.objects) app_perms_amount = IntegerField(queryset=ApplicationPermission.objects) total_count_online_users = IntegerField() total_count_online_sessions = IntegerField() def __init__(self, org): super().__init__() self.org = org def get_key_suffix(self): return f'<org:{self.org.id}>' def get_current_org(self): return self.org def compute_users_amount(self): if self.org.is_root(): users_amount = User.objects.all().count() else: users_amount = OrganizationMember.objects.values('user_id').filter( org_id=self.org.id).distinct().count() return users_amount def compute_assets_amount(self): if self.org.is_root(): return Asset.objects.all().count() node = Node.org_root() return node.assets_amount def compute_total_count_online_users(self): return len( set( Session.objects.filter(is_finished=False).values_list( 'user_id', flat=True))) def compute_total_count_online_sessions(self): return Session.objects.filter(is_finished=False).count()