From baa0bfce5317ee2a9d8081aea629df632c0ce752 Mon Sep 17 00:00:00 2001 From: Thomas Quandt Date: Wed, 31 Mar 2021 16:39:16 +0200 Subject: [PATCH] Userendpoints hide system endpoints (#4876) Signed-off-by: Thomas Quandt --- src/jetstream/cnsi.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/jetstream/cnsi.go b/src/jetstream/cnsi.go index d0304f8cd6..9c89551ff7 100644 --- a/src/jetstream/cnsi.go +++ b/src/jetstream/cnsi.go @@ -301,7 +301,35 @@ func (p *portalProxy) buildCNSIList(c echo.Context) ([]*interfaces.CNSIRecord, e } if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.AdminOnly { - return p.ListAdminEndpoints(userID.(string)) + // remove existing system endpoint if user endpoint already exists and sessionuser not admin + unfilteredList, err := p.ListAdminEndpoints(userID.(string)) + if err != nil { + return unfilteredList, err + } + + filteredList := []*interfaces.CNSIRecord{} + + for _, endpoint := range unfilteredList { + duplicateSystemEndpoint := false + duplicateEndpointIndex := -1 + + for i := 0; i < len(filteredList); i++ { + if filteredList[i].APIEndpoint.String() == endpoint.APIEndpoint.String() { + duplicateSystemEndpoint = len(filteredList[i].Creator) != 0 + duplicateEndpointIndex = i + } + } + + if duplicateEndpointIndex != -1 && !u.Admin { + if duplicateSystemEndpoint { + filteredList[duplicateEndpointIndex] = endpoint + } + } else { + filteredList = append(filteredList, endpoint) + } + } + + return filteredList, err } } return p.ListAdminEndpoints("")