Skip to content

Commit baa0bfc

Browse files
thquadrichard-cox
authored andcommitted
Userendpoints hide system endpoints (#4876)
Signed-off-by: Thomas Quandt <[email protected]>
1 parent b26ccb0 commit baa0bfc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/jetstream/cnsi.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,35 @@ func (p *portalProxy) buildCNSIList(c echo.Context) ([]*interfaces.CNSIRecord, e
301301
}
302302

303303
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.AdminOnly {
304-
return p.ListAdminEndpoints(userID.(string))
304+
// remove existing system endpoint if user endpoint already exists and sessionuser not admin
305+
unfilteredList, err := p.ListAdminEndpoints(userID.(string))
306+
if err != nil {
307+
return unfilteredList, err
308+
}
309+
310+
filteredList := []*interfaces.CNSIRecord{}
311+
312+
for _, endpoint := range unfilteredList {
313+
duplicateSystemEndpoint := false
314+
duplicateEndpointIndex := -1
315+
316+
for i := 0; i < len(filteredList); i++ {
317+
if filteredList[i].APIEndpoint.String() == endpoint.APIEndpoint.String() {
318+
duplicateSystemEndpoint = len(filteredList[i].Creator) != 0
319+
duplicateEndpointIndex = i
320+
}
321+
}
322+
323+
if duplicateEndpointIndex != -1 && !u.Admin {
324+
if duplicateSystemEndpoint {
325+
filteredList[duplicateEndpointIndex] = endpoint
326+
}
327+
} else {
328+
filteredList = append(filteredList, endpoint)
329+
}
330+
}
331+
332+
return filteredList, err
305333
}
306334
}
307335
return p.ListAdminEndpoints("")

0 commit comments

Comments
 (0)