Loading
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
- import the security categories and attributes graphql query and use it to get
securityCategoriesfor the group usinggroupFullPath - pass
securityCategoriestogetAttributeCategoryTokensto convert them to tokens - add the tokens from
2.to the array oftokenspassed to the filtered-search component - (optional) use
getAttributeHeaderTokento add a section header - use
ATTRIBUTE_TOKEN_PREFIXin the@onFilterfunction 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
- designs:
- issue: Frontend: Filter inventory by security attributes (#550497 - closed)
- backend issue: Add attributes related filters support (#578046 - closed)
- attributes epic: Security Attributes/Context Filtering (&18010)
- inventory filtering epic: Phase 2: Group-level Security Inventory (MVC) (&16640)
Screenshots or screen recordings
Screen_Recording_2025-11-11_at_14.22.31
expand for older screenshots/recordings
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)
- have a GitLab Ultimate license
- go to a group where you're an owner or maintainer =>
Secure=>Security configuration - set up some categories and attributes to test with
- go to
Secure=>Security inventory - using the filtered search bar at the top of the page, you should see the categories you created as options under a
Security attributessection header - selecting a category should allow you to select an operator (is, is one of, or is none of)
- selecting an operator should allow you to select attribute(s) in that category to filter by
- 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