Skip to content

Commit

Permalink
Userendpoints hide system endpoints (#4876)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Quandt <[email protected]>
  • Loading branch information
thquad authored and richard-cox committed Apr 16, 2021
1 parent b26ccb0 commit baa0bfc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/jetstream/cnsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down

0 comments on commit baa0bfc

Please sign in to comment.