[FIX] BASE: Restrict Group users_count to selected company context

This commit is contained in:
Horilla
2025-07-07 11:40:23 +05:30
parent 67bce92d0e
commit a4d062cb4c
2 changed files with 12 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import pandas as pd
import pdfkit
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.staticfiles import finders
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator
@@ -27,6 +28,16 @@ from horilla.horilla_middlewares import _thread_locals
from horilla.horilla_settings import HORILLA_DATE_FORMATS, HORILLA_TIME_FORMATS
def users_count(self):
"""
Restrict Group users_count to selected company context
"""
return Employee.objects.filter(employee_user_id__in=self.user_set.all()).count()
Group.add_to_class("users_count", property(users_count))
def filtersubordinates(request, queryset, perm=None, field="employee_id"):
"""
This method is used to filter out subordinates queryset element.

View File

@@ -15,7 +15,7 @@
</span>
<button style="display: none;" type="submit" onclick="event.stopPropagation()" id="hxSubmit"></button>
</form>
<span class="oh-user_permission_list-text oh-text--light">{% trans "Total" %} {{group.user_set.all|length}} {% trans "users in this group" %}</span>
<span class="oh-user_permission_list-text oh-text--light">{% trans "Total" %} {{ group.users_count }} {% trans "users in this group" %}</span>
</div>
</div>
{% if perms.auth.change_group or perms.auth.delete_group %}