From 82a45233062b230e41f2013eeca071e411258269 Mon Sep 17 00:00:00 2001 From: Toshimitsu Takahashi Date: Sat, 26 Oct 2024 23:47:27 +0900 Subject: [PATCH] Refactoring PR344 --- src/js/lib/target_profiles.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/lib/target_profiles.js b/src/js/lib/target_profiles.js index b0fdb40..068f5d4 100644 --- a/src/js/lib/target_profiles.js +++ b/src/js/lib/target_profiles.js @@ -28,7 +28,7 @@ async function retrieveTargetProfilesFromDB(ctx) { const complexTargetItems = await dbTable.query(`${matchedComplexSrc.name};`); let targets = complexTargetItems.map(it => convertComplexTarget(it, matchedComplexSrc)); if (filterByTargetRole) { - targets = targets.filter(it => targetRoleNameMatches(it, filterByTargetRole)); + targets = targets.filter(it => isRoleNameLeafMatch(it, filterByTargetRole)); } results.push(...targets) } @@ -72,7 +72,7 @@ async function retrieveTargetProfilesFromLztext(ctx) { if (matchedComplexSrc) { let targets = matchedComplexSrc.targets; if (filterByTargetRole) { - targets = targets.filter(it => targetRoleNameMatches(it, filterByTargetRole)); + targets = targets.filter(it => isRoleNameLeafMatch(it, filterByTargetRole)); } results.push(...targets) } @@ -80,6 +80,6 @@ async function retrieveTargetProfilesFromLztext(ctx) { return results; } -function targetRoleNameMatches(it, filterByTargetRole) { - return it.role_name === filterByTargetRole || it.role_name.substring(it.role_name.lastIndexOf('/') + 1) === filterByTargetRole; +function isRoleNameLeafMatch(item, targetLeaf) { + return item.role_name.split('/').pop() === targetLeaf; }