Add security attribute filters to inventory search bar

What does this MR do and why?

Add security attribute filters to search

Add security_attribute_inventory_filters feature flag
Query for categories and attributes in search bar
Map categories to tokens with attributes as options
Add a header token to show if any category matches
Push tokens into array if the feature flag is enabled

How to use these tokens in some other filtered search component

  1. import the security categories and attributes graphql query and use it to get securityCategories for the group using groupFullPath
  2. pass securityCategories to getAttributeCategoryTokens to convert them to tokens
  3. add the tokens from 2. to the array of tokens passed to the filtered-search component
  4. (optional) use getAttributeHeaderToken to add a section header
  5. use ATTRIBUTE_TOKEN_PREFIX in the @onFilter function to determine whether a filter is an attribute filter and apply your filtering logic
<script>
import FilteredSearch from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';
+ import getSecurityCategoriesAndAttributes from 'ee/security_configuration/graphql/group_security_categories_and_attributes.query.graphql';
+ import { ATTRIBUTE_TOKEN_PREFIX } from 'ee/security_configuration/security_attributes/components/shared/attribute_constants';
+ import {
+   getAttributeHeaderToken,
+   getAttributeCategoryTokens,
+ } from 'ee/security_configuration/security_attributes/components/shared/attribute_utils';

export default {
  name: 'SomeOtherFilteredSearch',
+ inject: ['groupFullPath'],
  data() {
    return {
+     securityCategories: [],
    }
  }
+ apollo: {
+   securityCategories: {
+     query: getSecurityCategoriesAndAttributes,
+     variables() {
+       return {
+         fullPath: this.groupFullPath,
+       };
+     },
+     update: (data) => data?.group?.securityCategories,
+   },
+ },
  computed: {
    tokens() {
      return [
        ...existingTokens,
+       getAttributeHeaderToken(
+         this.securityCategories,
+         s__('SecurityAttributes|Security attributes'),
+       ),
+       ...getAttributeCategoryTokens(this.securityCategories),
      ];
    }
  },
  methods: {
    onFilter(filters = []) {
+     if (filter.type.startsWith(ATTRIBUTE_TOKEN_PREFIX)) {
+       // do something with the attribute filter
+     }
    }
  },
};
</script>

<template>
  <filtered-search
    :tokens="tokens"
    @onFilter="onFilter"
  />
</template>

References

Screenshots or screen recordings

Screen_Recording_2025-11-11_at_14.22.31

expand for older screenshots/recordings

Screen_Recording_2025-11-04_at_14.10.24

Screen_Recording_2025-10-21_at_13.06.11

How to set up and validate locally

git checkout 550497-filter-inventory-by-security-attributes
echo "Feature.enable(:security_categories_and_attributes)" | gdk rails c    # backend services for attributes
echo "Feature.enable(:security_context_labels)" | gdk rails c               # frontend UI for attributes
echo "Feature.enable(:security_inventory_filtering)" | gdk rails c          # show filters in inventory (beyond plain text search)
echo "Feature.enable(:security_attribute_inventory_filters)" | gdk rails c  # show attributes filters in inventory (new flag in this MR)
  1. have a GitLab Ultimate license
  2. go to a group where you're an owner or maintainer => Secure => Security configuration
  3. set up some categories and attributes to test with
  4. go to Secure => Security inventory
  5. using the filtered search bar at the top of the page, you should see the categories you created as options under a Security attributes section header
  6. selecting a category should allow you to select an operator (is, is one of, or is none of)
  7. selecting an operator should allow you to select attribute(s) in that category to filter by
  8. selecting attributes and pressing enter (or clicking on the magnifying glass icon) should apply the selected attribute filter to the list of projects on the page

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Miranda Fluharty

Merge request reports

Loading
Loading