feat: [CODE-5485]: add ListScoped to usergroup controller (#5244)

* 2bc2ab fix: [CODE-5485]: use generic error message for missing spacePath

* 03bc0b fix: CODE-5485: move Harness-specific depth guard out of ListScoped

* 145ba1 fix: CODE-5485: reject repo paths in ListScoped; require depth <= 3

* 5470a7 feat: CODE-5485: add ListScoped to usergroup controller
This commit is contained in:
Abhinav Singh
2026-07-20 21:36:09 +00:00
committed by Harness
parent 64a772cdee
commit b71cd3b953
@@ -0,0 +1,52 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package usergroup
import (
"context"
"fmt"
"net/http"
"github.com/harness/gitness/app/api/usererror"
"github.com/harness/gitness/app/auth"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
// ListScoped returns usergroups visible at a specific space path.
// Unlike List, this is always active — no feature flag required.
func (c Controller) ListScoped(
ctx context.Context,
session *auth.Session,
filter *types.ListQueryFilter,
spacePath string,
) ([]*types.UserGroupInfo, error) {
if spacePath == "" {
return nil, usererror.Newf(http.StatusBadRequest, "spacePath is required")
}
space, err := getSpaceCheckAuth(
ctx, c.spaceFinder, c.authorizer, session, spacePath, enum.PermissionSpaceView,
)
if err != nil {
return nil, fmt.Errorf("failed to acquire access to space: %w", err)
}
userGroupInfos, err := c.userGroupService.List(ctx, filter, space)
if err != nil {
return nil, fmt.Errorf("failed to list user groups: %w", err)
}
return userGroupInfos, nil
}