@@ -26,14 +26,14 @@ import (
2626// - Public contact groups are visible to all users
2727// - Private contact groups are only visible to users who have an associated
2828// ContactGroupMembership
29- type ContactGroupVisibilityFilter struct {
29+ type ContactGroupVisibilityWithPrivateFilter struct {
3030 loopbackConfig * rest.Config
3131 clientGetter func () (dynamic.Interface , error )
3232}
3333
3434// NewContactGroupVisibilityFilter creates a new ContactGroupVisibilityFilter.
35- func NewContactGroupVisibilityFilter (loopbackConfig * rest.Config ) * ContactGroupVisibilityFilter {
36- return & ContactGroupVisibilityFilter {
35+ func NewContactGroupVisibilityWithPrivateFilter (loopbackConfig * rest.Config ) * ContactGroupVisibilityWithPrivateFilter {
36+ return & ContactGroupVisibilityWithPrivateFilter {
3737 loopbackConfig : loopbackConfig ,
3838 clientGetter : func () (dynamic.Interface , error ) {
3939 return dynamic .NewForConfig (loopbackConfig )
@@ -47,13 +47,13 @@ func NewContactGroupVisibilityFilter(loopbackConfig *rest.Config) *ContactGroupV
4747// Visibility rules:
4848// - Public groups: visible to everyone
4949// - Private groups: only visible if the user has a ContactGroupMembership associated with that group
50- func ContactGroupVisibilityDecorator (loopbackConfig * rest.Config ) func (http.Handler ) http.Handler {
51- filter := NewContactGroupVisibilityFilter (loopbackConfig )
50+ func ContactGroupVisibilityWithPrivateDecorator (loopbackConfig * rest.Config ) func (http.Handler ) http.Handler {
51+ filter := NewContactGroupVisibilityWithPrivateFilter (loopbackConfig )
5252 return filter .Wrap
5353}
5454
5555// Wrap wraps the provided handler with contact group visibility filtering.
56- func (f * ContactGroupVisibilityFilter ) Wrap (handler http.Handler ) http.Handler {
56+ func (f * ContactGroupVisibilityWithPrivateFilter ) Wrap (handler http.Handler ) http.Handler {
5757 return http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
5858 ctx := req .Context ()
5959 info , ok := request .RequestInfoFrom (ctx )
@@ -104,7 +104,7 @@ func (f *ContactGroupVisibilityFilter) Wrap(handler http.Handler) http.Handler {
104104
105105// filterContactGroups filters the list of contact groups based on visibility rules.
106106// Supports both ContactGroupList/List responses and Table responses (kubectl default).
107- func (f * ContactGroupVisibilityFilter ) filterContactGroups (ctx context.Context , userID string , body []byte ) ([]byte , error ) {
107+ func (f * ContactGroupVisibilityWithPrivateFilter ) filterContactGroups (ctx context.Context , userID string , body []byte ) ([]byte , error ) {
108108 // First, check the response kind to determine how to filter it.
109109 var typeMeta struct {
110110 Kind string `json:"kind"`
@@ -135,7 +135,7 @@ func (f *ContactGroupVisibilityFilter) filterContactGroups(ctx context.Context,
135135
136136// buildAccessibleGroupsSet returns the set of group keys (namespace/name) accessible to the user.
137137// Returns the map and a boolean indicating if the user has an associated Contact.
138- func (f * ContactGroupVisibilityFilter ) buildAccessibleGroupsSet (ctx context.Context , client dynamic.Interface , userID string ) (map [string ]bool , bool ) {
138+ func (f * ContactGroupVisibilityWithPrivateFilter ) buildAccessibleGroupsSet (ctx context.Context , client dynamic.Interface , userID string ) (map [string ]bool , bool ) {
139139 contactName , contactNamespace , err := f .findContactForUser (ctx , client , userID )
140140 if err != nil {
141141 // No contact found, user can only see public groups
@@ -152,7 +152,7 @@ func (f *ContactGroupVisibilityFilter) buildAccessibleGroupsSet(ctx context.Cont
152152}
153153
154154// filterListResponse filters a ContactGroupList or List response.
155- func (f * ContactGroupVisibilityFilter ) filterListResponse (body []byte , accessibleGroups map [string ]bool , hasContact bool ) ([]byte , error ) {
155+ func (f * ContactGroupVisibilityWithPrivateFilter ) filterListResponse (body []byte , accessibleGroups map [string ]bool , hasContact bool ) ([]byte , error ) {
156156 var contactGroupList notificationv1alpha1.ContactGroupList
157157 if err := json .Unmarshal (body , & contactGroupList ); err != nil {
158158 return nil , fmt .Errorf ("failed to unmarshal contact group list: %w" , err )
@@ -164,7 +164,7 @@ func (f *ContactGroupVisibilityFilter) filterListResponse(body []byte, accessibl
164164}
165165
166166// filterTableResponse filters a Table response (kubectl default format).
167- func (f * ContactGroupVisibilityFilter ) filterTableResponse (ctx context.Context , client dynamic.Interface , body []byte , accessibleGroups map [string ]bool , hasContact bool ) ([]byte , error ) {
167+ func (f * ContactGroupVisibilityWithPrivateFilter ) filterTableResponse (ctx context.Context , client dynamic.Interface , body []byte , accessibleGroups map [string ]bool , hasContact bool ) ([]byte , error ) {
168168 var table metav1.Table
169169 if err := json .Unmarshal (body , & table ); err != nil {
170170 return nil , fmt .Errorf ("failed to unmarshal table: %w" , err )
@@ -210,7 +210,7 @@ func (f *ContactGroupVisibilityFilter) filterTableResponse(ctx context.Context,
210210}
211211
212212// filterGroupItems filters a slice of ContactGroup items based on visibility rules.
213- func (f * ContactGroupVisibilityFilter ) filterGroupItems (groups []notificationv1alpha1.ContactGroup , accessibleGroups map [string ]bool , hasContact bool ) []notificationv1alpha1.ContactGroup {
213+ func (f * ContactGroupVisibilityWithPrivateFilter ) filterGroupItems (groups []notificationv1alpha1.ContactGroup , accessibleGroups map [string ]bool , hasContact bool ) []notificationv1alpha1.ContactGroup {
214214 filtered := make ([]notificationv1alpha1.ContactGroup , 0 , len (groups ))
215215 for _ , group := range groups {
216216 if f .isGroupVisible (group , accessibleGroups , hasContact ) {
@@ -221,7 +221,7 @@ func (f *ContactGroupVisibilityFilter) filterGroupItems(groups []notificationv1a
221221}
222222
223223// isGroupVisible determines if a contact group is visible to the user.
224- func (f * ContactGroupVisibilityFilter ) isGroupVisible (group notificationv1alpha1.ContactGroup , accessibleGroups map [string ]bool , hasContact bool ) bool {
224+ func (f * ContactGroupVisibilityWithPrivateFilter ) isGroupVisible (group notificationv1alpha1.ContactGroup , accessibleGroups map [string ]bool , hasContact bool ) bool {
225225 // Public groups are always visible
226226 if group .Spec .Visibility == notificationv1alpha1 .ContactGroupVisibilityPublic {
227227 return true
@@ -238,7 +238,7 @@ func (f *ContactGroupVisibilityFilter) isGroupVisible(group notificationv1alpha1
238238
239239// findContactForUser finds the Contact resource for the given user ID.
240240// Searches across all namespaces and returns the contact name, namespace, and any error.
241- func (f * ContactGroupVisibilityFilter ) findContactForUser (ctx context.Context , client dynamic.Interface , userID string ) (string , string , error ) {
241+ func (f * ContactGroupVisibilityWithPrivateFilter ) findContactForUser (ctx context.Context , client dynamic.Interface , userID string ) (string , string , error ) {
242242 // Query contacts across all namespaces
243243 contactGVR := notificationv1alpha1 .SchemeGroupVersion .WithResource ("contacts" )
244244
@@ -265,7 +265,7 @@ func (f *ContactGroupVisibilityFilter) findContactForUser(ctx context.Context, c
265265
266266// getAccessibleGroups returns the list of contact group keys (namespace/name) that the user has access to
267267// (through membership or removal records). Searches across all namespaces.
268- func (f * ContactGroupVisibilityFilter ) getAccessibleGroups (ctx context.Context , client dynamic.Interface , contactName , contactNamespace string ) (map [string ]bool , error ) {
268+ func (f * ContactGroupVisibilityWithPrivateFilter ) getAccessibleGroups (ctx context.Context , client dynamic.Interface , contactName , contactNamespace string ) (map [string ]bool , error ) {
269269 accessibleGroups := make (map [string ]bool )
270270
271271 // Get memberships for this contact across all namespaces
0 commit comments