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

Add validation of group filters - specifically managed #23392

Open
jrafanie opened this issue Mar 21, 2025 · 2 comments
Open

Add validation of group filters - specifically managed #23392

jrafanie opened this issue Mar 21, 2025 · 2 comments

Comments

@jrafanie
Copy link
Member

If a user tries to POST to API with:

http://localhost:3000/api/groups/31/

{
  "action" : "edit",
  "resource" : {
    "filters" : {
    	"managed" : [[ "/managed/cc/999" ]]			
	}
  }
}

We need to validate that managed filter will resolve to the correct category and entry.

I started on this:

diff --git a/app/models/entitlement.rb b/app/models/entitlement.rb
index ba4f5c9be9..4468148f16 100644
--- a/app/models/entitlement.rb
+++ b/app/models/entitlement.rb
@@ -73,6 +73,20 @@ class Entitlement < ApplicationRecord
     end
   end

+  def orphaned_managed_filters
+    return [] unless get_managed_filters.present?
+
+    self.filters["managed"].first.select do |filter|
+      self.class.orphaned_managed_filter(filter)
+    end
+  end
+
+  def self.orphaned_managed_filter(filter)
+    # returns namespace string, category object, and entry object
+    # if either category or entry is blank/nil, it's invalid
+    Classification.tag_name_to_objects(filter).any?(&:blank?)
+  end
+
@jrafanie jrafanie added the bug label Mar 21, 2025
@jrafanie jrafanie self-assigned this Mar 21, 2025
@jrafanie
Copy link
Member Author

jrafanie commented Mar 24, 2025

TODO: Investigate if renaming a tag used in a managed filter fails to update the filter with the new name.

EDIT: This should should resolve future problems caused by tag renames: #23393

@jrafanie
Copy link
Member Author

Note, belongsto filter validation exists in the UI here: ManageIQ/manageiq-ui-classic#5511. This should be normalized for usage in the API or UI and be extended to include managed filters.

jrafanie added a commit to jrafanie/manageiq that referenced this issue Mar 24, 2025
Previously, an managed filter on a group's entitlement would point
to an orphaned tag name if the original tag name is renamed.

Resolves an issue discussed in ManageIQ#23392
jrafanie added a commit to jrafanie/manageiq that referenced this issue Mar 24, 2025
Previously, an managed filter on a group's entitlement would point
to an orphaned tag name if the original tag name is renamed.

Resolves an issue discussed in ManageIQ#23392
@jrafanie jrafanie removed their assignment Mar 24, 2025
jrafanie added a commit to jrafanie/manageiq that referenced this issue Mar 24, 2025
Previously, an managed filter on a group's entitlement would point
to an orphaned tag name if the original tag name is renamed.

Resolves an issue discussed in ManageIQ#23392
jrafanie added a commit to jrafanie/manageiq that referenced this issue Mar 24, 2025
Previously, an managed filter on a group's entitlement would point
to an orphaned tag name if the original tag name is renamed.

Resolves an issue discussed in ManageIQ#23392
jrafanie added a commit to jrafanie/manageiq that referenced this issue Mar 25, 2025
Previously, an managed filter on a group's entitlement would point
to an orphaned tag name if the original tag name is renamed.

Resolves an issue discussed in ManageIQ#23392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant