Skip to content

Commit

Permalink
Merge pull request #2533 from TencentBlueKing/develop
Browse files Browse the repository at this point in the history
feat: add managment group list api subject_template_count field (#2532)
  • Loading branch information
zhu327 authored Feb 23, 2024
2 parents 50faf76 + ce5f7c6 commit 43fed31
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions saas/backend/api/management/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
specific language governing permissions and limitations under the License.
"""
from django.conf import settings
from django.db.models import QuerySet
from django.utils.translation import gettext as _
from rest_framework import serializers

Expand All @@ -18,6 +19,7 @@
from backend.apps.role.serializers import GradeMangerBaseInfoSLZ, RoleScopeSubjectSLZ
from backend.apps.subject_template.models import SubjectTemplate
from backend.biz.role import RoleCheckBiz
from backend.biz.subject_template import SubjectTemplateBiz
from backend.service.constants import GroupMemberType
from backend.service.models import Subject

Expand Down Expand Up @@ -277,19 +279,38 @@ def validate(self, data):


class ManagementGroupSLZ(serializers.ModelSerializer):
subject_template_count = serializers.SerializerMethodField()

class Meta:
model = Group
fields = (
"id",
"name",
"user_count",
"department_count",
"subject_template_count",
"description",
"creator",
"created_time",
"readonly",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.subject_template_count_dict = None
if isinstance(self.instance, (QuerySet, list)) and self.instance:
group_ids = [int(group.id) for group in self.instance]
# 人员模版数量
self.subject_template_count_dict = SubjectTemplateBiz().get_group_template_count_dict(group_ids)
elif isinstance(self.instance, Group):
# 人员模版数量
self.subject_template_count_dict = SubjectTemplateBiz().get_group_template_count_dict([self.instance.id])

def get_subject_template_count(self, obj):
if not self.subject_template_count_dict:
return 0
return self.subject_template_count_dict.get(obj.id, 0)


class ManagementQueryGroupSLZ(serializers.Serializer):
inherit = serializers.BooleanField(label="是否继承子集管理员的用户组", required=False, default=True)
Expand Down

0 comments on commit 43fed31

Please sign in to comment.