|
|
@ -186,13 +186,15 @@ class CommandFilterRule(OrgModelMixin):
|
|
|
|
return ticket
|
|
|
|
return ticket
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def get_queryset(cls, user_id=None, user_group_id=None, system_user_id=None, asset_id=None, application_id=None):
|
|
|
|
def get_queryset(cls, user_id=None, user_group_id=None, system_user_id=None,
|
|
|
|
|
|
|
|
asset_id=None, application_id=None, org_id=None):
|
|
|
|
user_groups = []
|
|
|
|
user_groups = []
|
|
|
|
user = get_object_or_none(User, pk=user_id)
|
|
|
|
user = get_object_or_none(User, pk=user_id)
|
|
|
|
if user:
|
|
|
|
if user:
|
|
|
|
user_groups.extend(list(user.groups.all()))
|
|
|
|
user_groups.extend(list(user.groups.all()))
|
|
|
|
user_group = get_object_or_none(UserGroup, pk=user_group_id)
|
|
|
|
user_group = get_object_or_none(UserGroup, pk=user_group_id)
|
|
|
|
if user_group:
|
|
|
|
if user_group:
|
|
|
|
|
|
|
|
org_id = user_group.org_id
|
|
|
|
user_groups.append(user_group)
|
|
|
|
user_groups.append(user_group)
|
|
|
|
system_user = get_object_or_none(SystemUser, pk=system_user_id)
|
|
|
|
system_user = get_object_or_none(SystemUser, pk=system_user_id)
|
|
|
|
asset = get_object_or_none(Asset, pk=asset_id)
|
|
|
|
asset = get_object_or_none(Asset, pk=asset_id)
|
|
|
@ -203,13 +205,18 @@ class CommandFilterRule(OrgModelMixin):
|
|
|
|
if user_groups:
|
|
|
|
if user_groups:
|
|
|
|
q |= Q(user_groups__in=set(user_groups))
|
|
|
|
q |= Q(user_groups__in=set(user_groups))
|
|
|
|
if system_user:
|
|
|
|
if system_user:
|
|
|
|
|
|
|
|
org_id = system_user.org_id
|
|
|
|
q |= Q(system_users=system_user)
|
|
|
|
q |= Q(system_users=system_user)
|
|
|
|
if asset:
|
|
|
|
if asset:
|
|
|
|
|
|
|
|
org_id = asset.org_id
|
|
|
|
q |= Q(assets=asset)
|
|
|
|
q |= Q(assets=asset)
|
|
|
|
if application:
|
|
|
|
if application:
|
|
|
|
|
|
|
|
org_id = application.org_id
|
|
|
|
q |= Q(applications=application)
|
|
|
|
q |= Q(applications=application)
|
|
|
|
if q:
|
|
|
|
if q:
|
|
|
|
cmd_filters = CommandFilter.objects.filter(q).filter(is_active=True)
|
|
|
|
cmd_filters = CommandFilter.objects.filter(q).filter(is_active=True)
|
|
|
|
|
|
|
|
if org_id:
|
|
|
|
|
|
|
|
cmd_filters = cmd_filters.filter(org_id=org_id)
|
|
|
|
rule_ids = cmd_filters.values_list('rules', flat=True)
|
|
|
|
rule_ids = cmd_filters.values_list('rules', flat=True)
|
|
|
|
rules = cls.objects.filter(id__in=rule_ids)
|
|
|
|
rules = cls.objects.filter(id__in=rule_ids)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|