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 Related Rules Grouping #604

Merged
merged 6 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion app/controllers/rules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def related_rules
rules = Rule.where(version: srg_id).where.not(id: @rule.id).eager_load(:disa_rule_descriptions, :checks, :component)
stig_rules = StigRule.where(srg_id: srg_id).eager_load(:disa_rule_descriptions, :checks, :stig)
rules = rules.filter { |r| r.component.all_users.include?(current_user) } unless current_user.admin?
parents = (stig_rules.map(&:stig) + rules.map(&:component)).uniq
parents = (stig_rules.map(&:stig).as_json + rules.map(&:component).as_json(methods: %i[project])).uniq

render json: { rules: stig_rules + rules, parents: parents }.to_json
end
Expand Down
13 changes: 7 additions & 6 deletions app/javascript/components/rules/RelatedRulesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export default {
});
} else {
const comp_rules = this.relatedRules.filter((r) => r.component_id == parent.id);
parent.name = `${parent.name} - Ver ${parent.version}, Rel ${parent.release}`;
parent.name = `${parent.project.name} / ${parent.name} - Ver ${parent.version}, Rel ${parent.release}`;
comp_rules.forEach((r) => {
r.parent = parent.name;
r.name = `${parent.prefix}-${r.rule_id}//${r.version}`;
Expand Down Expand Up @@ -422,12 +422,13 @@ export default {
},
lookupSearchWordInRules: function (rules) {
const words = this.keywordList.map((w) => w.toLowerCase());
const checkWord = (text) => words.some((w) => text.includes(w));
const checkWord = (text) => words.some((w) => (text ? text.includes(w) : ""));
const convertLower = (text) => (text ? text.toLowerCase() : "");
return rules.filter((r) => {
const title = r.title.toLowerCase();
const discussion = r.disa_rule_descriptions_attributes[0].vuln_discussion.toLowerCase();
const check = r.checks_attributes[0].content.toLowerCase();
const fix = r.fixtext.toLowerCase();
const title = convertLower(r.title);
const discussion = convertLower(r.disa_rule_descriptions_attributes[0].vuln_discussion);
const check = convertLower(r.checks_attributes[0].content);
const fix = convertLower(r.fixtext);
const includeCheck = this.fields.includes("Check");
const includeFix = this.fields.includes("Fix");
const includeDiscussion = this.fields.includes("Vulnerability Discussion");
Expand Down
Loading