Skip to content

Commit

Permalink
Merge pull request #201 from mantiumai/AlexN/clone-policy-bug
Browse files Browse the repository at this point in the history
fix MultiQueryRule policy clone bug
  • Loading branch information
alex-nork authored Sep 7, 2023
2 parents f332ac9 + 678d935 commit fb55f89
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
50 changes: 26 additions & 24 deletions chirps/policy/templates/policy/dashboard_policy_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,32 @@ <h5>MultiQuery Rules</h5>
</thead>
<tbody>
{% for rule in rules %}
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.success_outcome}}">
{{rule.name|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.task_description}}">
{{rule.task_description|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.success_outcome}}">
{{rule.success_outcome|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.success_outcome}}">
{{rule.severity|truncatechars:50}}
</span>
</td>
<tr>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.name}}">
{{rule.name|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.task_description}}">
{{rule.task_description|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.success_outcome}}">
{{rule.success_outcome|truncatechars:50}}
</span>
</td>
<td>
<span class="d-inline-block" tabindex="0" data-toggle="tooltip"
title="{{rule.severity}}">
{{rule.severity|truncatechars:50}}
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
Expand Down
27 changes: 19 additions & 8 deletions chirps/policy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,25 @@ def clone(request, policy_id):

# Clone the rules
for rule in policy.current_version.rules.all():
save_rule(
rule.rule_type,
name=rule.name,
query_string=rule.query_string,
regex_test=rule.regex_test,
severity=rule.severity,
policy=policy_version,
)
if rule.rule_type == 'regex':
save_rule(
rule.rule_type,
name=rule.name,
query_string=rule.query_string,
regex_test=rule.regex_test,
severity=rule.severity,
policy=policy_version,
)
elif rule.rule_type == 'multiquery':
save_rule(
rule.rule_type,
name=rule.name,
task_description=rule.task_description,
success_outcome=rule.success_outcome,
attack_count=rule.attack_count,
severity=rule.severity,
policy=policy_version,
)

# Redirect to the edit page for the new policy
return redirect('policy_edit', policy_id=cloned_policy.id)
Expand Down

0 comments on commit fb55f89

Please sign in to comment.