feat: list allowed groups when hovering over allowed group count (#1671)

This commit is contained in:
Kyle Mendell
2026-08-25 18:30:16 +02:00
committed by GitHub
parent 29a6fd6c29
commit d75523fed0
11 changed files with 153 additions and 60 deletions
@@ -118,7 +118,7 @@ func (oc *OidcController) getClientHandler(c *gin.Context) error {
// @Param pagination[limit] query int false "Number of items per page" default(20)
// @Param sort[column] query string false "Column to sort by"
// @Param sort[direction] query string false "Sort direction (asc or desc)" default("asc")
// @Success 200 {object} dto.Paginated[dto.OidcClientWithAllowedGroupsCountDto]
// @Success 200 {object} dto.Paginated[dto.OidcClientWithAllowedGroupsDto]
// @Failure default {object} dto.ErrorDto "Error"
// @Router /api/oidc/clients [get]
func (oc *OidcController) listClientsHandler(c *gin.Context) error {
@@ -131,22 +131,17 @@ func (oc *OidcController) listClientsHandler(c *gin.Context) error {
}
// Map the user groups to DTOs
var clientsDto = make([]dto.OidcClientWithAllowedGroupsCountDto, len(clients))
var clientsDto = make([]dto.OidcClientWithAllowedGroupsDto, len(clients))
for i, client := range clients {
var clientDto dto.OidcClientWithAllowedGroupsCountDto
var clientDto dto.OidcClientWithAllowedGroupsDto
if err := dto.MapStruct(client, &clientDto); err != nil {
return err
}
clientDto.HasDarkLogo = client.HasDarkLogo()
clientDto.AllowedUserGroupsCount, err = oc.oidcService.GetAllowedGroupsCountOfClient(c, client.ID)
if err != nil {
return err
}
clientsDto[i] = clientDto
}
c.JSON(http.StatusOK, dto.Paginated[dto.OidcClientWithAllowedGroupsCountDto]{
c.JSON(http.StatusOK, dto.Paginated[dto.OidcClientWithAllowedGroupsDto]{
Data: clientsDto,
Pagination: pagination,
})
+2 -2
View File
@@ -33,9 +33,9 @@ type OidcClientWithAllowedUserGroupsDto struct {
AllowedUserGroups []UserGroupMinimalDto `json:"allowedUserGroups"`
}
type OidcClientWithAllowedGroupsCountDto struct {
type OidcClientWithAllowedGroupsDto struct {
OidcClientDto
AllowedUserGroupsCount int64 `json:"allowedUserGroupsCount"`
AllowedUserGroups []UserGroupMinimalDto `json:"allowedUserGroups"`
}
type OidcClientUpdateDto struct {
+3 -18
View File
@@ -124,14 +124,15 @@ func (s *OidcService) ListClients(ctx context.Context, name string, listRequestO
query := s.db.
WithContext(ctx).
Preload("CreatedBy").
Preload("AllowedUserGroups").
Model(&model.OidcClient{})
if name != "" {
query = query.Where("name LIKE ?", "%"+name+"%")
}
// As allowedUserGroupsCount is not a column, we need to manually sort it
if listRequestOptions.Sort.Column == "allowedUserGroupsCount" && utils.IsValidSortDirection(listRequestOptions.Sort.Direction) {
// Sort the allowed user groups relation by its row count because it is not an OIDC client column
if listRequestOptions.Sort.Column == "allowedUserGroups" && utils.IsValidSortDirection(listRequestOptions.Sort.Direction) {
query = query.Select("oidc_clients.*, COUNT(oidc_clients_allowed_user_groups.oidc_client_id)").
Joins("LEFT JOIN oidc_clients_allowed_user_groups ON oidc_clients.id = oidc_clients_allowed_user_groups.oidc_client_id").
Group("oidc_clients.id").
@@ -629,22 +630,6 @@ func (s *OidcService) UpdateAllowedUserGroups(ctx context.Context, id string, in
return client, nil
}
func (s *OidcService) GetAllowedGroupsCountOfClient(ctx context.Context, id string) (int64, error) {
// We only perform select queries here, so we can rollback in all cases
tx := s.db.Begin()
defer func() {
tx.Rollback()
}()
client, err := s.getClientInternal(ctx, id, tx, false)
if err != nil {
return 0, err
}
count := tx.WithContext(ctx).Model(&client).Association("AllowedUserGroups").Count()
return count, nil
}
func (s *OidcService) ListAuthorizedClients(ctx context.Context, userID string, listRequestOptions utils.ListRequestOptions) ([]model.UserAuthorizedOidcClient, utils.PaginationResponse, error) {
tx := s.db.Begin()
defer func() {