Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hook rule goblal. #1292

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dongtai_protocol/views/hook_profilesv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def get_profiles(user=None, language_id=JAVA):
if isinstance(hook_type, IastStrategyModel):
hook_type = convert_strategy(hook_type)
strategies = hook_type.strategies.filter(
created_by__in=[1, user.id] if user else [1],
type__in=(1, 2, 3)
if not isinstance(hook_type, IastStrategyModel) else [4],
enable=const.HOOK_TYPE_ENABLE,
Expand Down
8 changes: 2 additions & 6 deletions dongtai_web/views/engine_hook_rule_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ def parse_args(self, request):
def post(self, request):
rule_id, rule_type, rule_value, rule_source, rule_target, inherit, is_track = self.parse_args(request)
strategy = HookStrategy.objects.filter(
id=rule_id, created_by=request.user.id).first()
id=rule_id).first()
if not strategy:
return R.failure(msg=_('No such hookstrategy.'))
if strategy.type == 4:
hook_type = IastStrategyModel.objects.filter(
id=rule_type,
user_id__in=[request.user.id, const.SYSTEM_USER_ID],
).first()
else:
hook_type = HookType.objects.filter(
id=rule_type,
created_by__in=(request.user.id,
const.SYSTEM_USER_ID)).first()
hook_type = HookType.objects.filter(id=rule_type, ).first()

if all((rule_id, rule_type, rule_value, rule_source, inherit, is_track,
strategy)) is False:
Expand Down
2 changes: 1 addition & 1 deletion dongtai_web/views/engine_hook_rule_type_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get(self, request):
if rule_id is None:
return R.failure(msg=_('Strategy does not exist'))

rule = HookStrategy.objects.filter(id=rule_id, created_by=request.user.id).first()
rule = HookStrategy.objects.filter(id=rule_id).first()
if rule:
rule_type = rule.type.first()
if rule_type:
Expand Down
2 changes: 1 addition & 1 deletion dongtai_web/views/engine_hook_rule_type_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get(self, request):
if rule_id is None:
return R.failure(msg=_('Strategy does not exist'))

rule = HookStrategy.objects.filter(id=rule_id, created_by=request.user.id).first()
rule = HookStrategy.objects.filter(id=rule_id).first()
if rule:
rule_type = rule.type.first()
if rule_type:
Expand Down
15 changes: 4 additions & 11 deletions dongtai_web/views/engine_hook_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,25 @@ def get(self, request):
if strategy_type:
rule_type_queryset = IastStrategyModel.objects.filter(
pk=strategy_type,
user_id__in=(user_id, const.SYSTEM_USER_ID),
)
else:
rule_type_queryset = IastStrategyModel.objects.filter(
user_id__in=(user_id, const.SYSTEM_USER_ID), )
rule_type_queryset = IastStrategyModel.objects.all()
else:
if strategy_type:
rule_type_queryset = HookType.objects.filter(
id=strategy_type,
created_by__in=(user_id, const.SYSTEM_USER_ID),
type=rule_type,
language_id=language_id)
else:
rule_type_queryset = HookType.objects.filter(
created_by__in=(user_id, const.SYSTEM_USER_ID),
type=rule_type,
language_id=language_id)
if rule_type == 4:
q = Q(strategy__in=rule_type_queryset) & Q(
created_by=user_id) & Q(
enable__in=(const.ENABLE, const.DISABLE)) & Q(
language_id=language_id)
q = Q(strategy__in=rule_type_queryset) & Q(enable__in=(
const.ENABLE, const.DISABLE)) & Q(language_id=language_id)
else:
q = Q(hooktype__in=rule_type_queryset) & Q(
created_by=user_id) & Q(enable__in=(const.ENABLE,
const.DISABLE))
enable__in=(const.ENABLE, const.DISABLE))
if keyword:
q = Q(value__icontains=keyword) & q
rule_queryset = HookStrategy.objects.filter(q)
Expand Down