mirror of https://github.com/harness/drone.git
feat: [CDE-522]: send total gitspaces without applying user filters in header (#3089)
* feat: [CDE-522]: formatting * feat: [CDE-522]: formatting * feat: [CDE-522]: send total gitspaces without applying user filters in header * feat: [CDE-522]: send total gitspaces without applying filter in headerpull/3597/head
parent
08d9d959cc
commit
c65f994af9
|
@ -29,14 +29,14 @@ func (c *Controller) ListGitspaces(
|
|||
session *auth.Session,
|
||||
spaceRef string,
|
||||
filter types.GitspaceFilter,
|
||||
) ([]*types.GitspaceConfig, int64, error) {
|
||||
) ([]*types.GitspaceConfig, int64, int64, error) {
|
||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to find space: %w", err)
|
||||
return nil, 0, 0, fmt.Errorf("failed to find space: %w", err)
|
||||
}
|
||||
err = apiauth.CheckGitspace(ctx, c.authorizer, session, space.Path, "", enum.PermissionGitspaceView)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to authorize gitspace: %w", err)
|
||||
return nil, 0, 0, fmt.Errorf("failed to authorize gitspace: %w", err)
|
||||
}
|
||||
|
||||
filter.UserIdentifier = session.Principal.UID
|
||||
|
|
|
@ -16,12 +16,15 @@ package space
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/harness/gitness/app/api/controller/space"
|
||||
"github.com/harness/gitness/app/api/render"
|
||||
"github.com/harness/gitness/app/api/request"
|
||||
)
|
||||
|
||||
const HeaderTotalWithoutFilter = "x-total-no-filter"
|
||||
|
||||
func HandleListGitspaces(spacesCtrl *space.Controller) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
@ -32,12 +35,13 @@ func HandleListGitspaces(spacesCtrl *space.Controller) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
filter := request.ParseGitspaceFilter(r)
|
||||
repos, totalCount, err := spacesCtrl.ListGitspaces(ctx, session, spaceRef, filter)
|
||||
repos, filterCount, totalCount, err := spacesCtrl.ListGitspaces(ctx, session, spaceRef, filter)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(ctx, w, err)
|
||||
return
|
||||
}
|
||||
render.Pagination(r, w, filter.QueryFilter.Page, filter.QueryFilter.Size, int(totalCount))
|
||||
w.Header().Set(HeaderTotalWithoutFilter, strconv.FormatInt(totalCount, 10))
|
||||
render.Pagination(r, w, filter.QueryFilter.Page, filter.QueryFilter.Size, int(filterCount))
|
||||
render.JSON(w, http.StatusOK, repos)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ func ExtractIDECustomizations(
|
|||
var args = make(map[string]interface{})
|
||||
if ideService.Type() == enum.IDETypeVSCodeWeb || ideService.Type() == enum.IDETypeVSCode {
|
||||
if devcontainerConfig.Customizations.ExtractVSCodeSpec() != nil {
|
||||
args[gitspaceTypes.VSCodeCustomization] = *devcontainerConfig.Customizations.ExtractVSCodeSpec()
|
||||
args[gitspaceTypes.VSCodeCustomizationArg] = *devcontainerConfig.Customizations.ExtractVSCodeSpec()
|
||||
}
|
||||
}
|
||||
return args
|
||||
|
|
|
@ -573,7 +573,7 @@ func (e *EmbeddedDockerOrchestrator) buildSetupSteps(
|
|||
) error {
|
||||
// Run IDE setup
|
||||
args := ExtractIDECustomizations(ideService, resolvedRepoDetails.DevcontainerConfig)
|
||||
args[gitspaceTypes.IDERepoName] = resolvedRepoDetails.RepoName
|
||||
args[gitspaceTypes.IDERepoNameArg] = resolvedRepoDetails.RepoName
|
||||
return SetupIDE(ctx, exec, ideService, args, gitspaceLogger)
|
||||
},
|
||||
StopOnFailure: true,
|
||||
|
|
|
@ -143,7 +143,7 @@ func (v *VSCode) handleVSCodeCustomization(
|
|||
gitspaceLogger gitspaceTypes.GitspaceLogger,
|
||||
payload *template.SetupSSHServerPayload,
|
||||
) error {
|
||||
customization, exists := args[gitspaceTypes.VSCodeCustomization]
|
||||
customization, exists := args[gitspaceTypes.VSCodeCustomizationArg]
|
||||
if !exists {
|
||||
return nil // No customization found, nothing to do
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ func (v *VSCode) handleRepoName(
|
|||
args map[string]interface{},
|
||||
payload *template.SetupSSHServerPayload,
|
||||
) error {
|
||||
repoName, exists := args[gitspaceTypes.IDERepoName]
|
||||
repoName, exists := args[gitspaceTypes.IDERepoNameArg]
|
||||
if !exists {
|
||||
return nil // No repo name found, nothing to do
|
||||
}
|
||||
|
|
|
@ -168,11 +168,11 @@ func updateRunPayloadFromArgs(
|
|||
payload *template.RunVSCodeWebPayload,
|
||||
_ gitspaceTypes.GitspaceLogger,
|
||||
) error {
|
||||
if proxyURI, exists := args[gitspaceTypes.VSCodeProxyURI]; exists {
|
||||
if proxyURI, exists := args[gitspaceTypes.VSCodeProxyURIArg]; exists {
|
||||
// Perform a type assertion to ensure proxyURI is a string
|
||||
proxyURIStr, ok := proxyURI.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s is not a string", gitspaceTypes.VSCodeProxyURI)
|
||||
return fmt.Errorf("%s is not a string", gitspaceTypes.VSCodeProxyURIArg)
|
||||
}
|
||||
payload.ProxyURI = proxyURIStr
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ func updateSetupPayloadFromArgs(
|
|||
payload *template.SetupVSCodeWebPayload,
|
||||
gitspaceLogger gitspaceTypes.GitspaceLogger,
|
||||
) error {
|
||||
if customization, exists := args[gitspaceTypes.VSCodeCustomization]; exists {
|
||||
if customization, exists := args[gitspaceTypes.VSCodeCustomizationArg]; exists {
|
||||
// Perform a type assertion to ensure customization is a VSCodeCustomizationSpecs
|
||||
vsCodeCustomizationSpecs, ok := customization.(types.VSCodeCustomizationSpecs)
|
||||
if !ok {
|
||||
|
|
|
@ -23,9 +23,9 @@ import (
|
|||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
const VSCodeCustomization = "vscode_customization"
|
||||
const VSCodeProxyURI = "VSCODE_PROXY_URI"
|
||||
const IDERepoName = "IDE_REPO_NAME"
|
||||
const VSCodeCustomizationArg = "vscode_customization"
|
||||
const VSCodeProxyURIArg = "VSCODE_PROXY_URI"
|
||||
const IDERepoNameArg = "IDE_REPO_NAME"
|
||||
|
||||
type GitspaceLogger interface {
|
||||
Info(msg string)
|
||||
|
|
|
@ -72,24 +72,36 @@ func (c *Service) ListGitspacesForSpace(
|
|||
ctx context.Context,
|
||||
space *types.Space,
|
||||
filter types.GitspaceFilter,
|
||||
) ([]*types.GitspaceConfig, int64, error) {
|
||||
) ([]*types.GitspaceConfig, int64, int64, error) {
|
||||
var gitspaceConfigs []*types.GitspaceConfig
|
||||
var count int64
|
||||
var filterCount, allGitspacesInSpaceCount int64
|
||||
err := c.tx.WithTx(ctx, func(ctx context.Context) (err error) {
|
||||
gitspaceConfigs, err = c.gitspaceConfigStore.ListWithLatestInstance(ctx, &filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list gitspace configs: %w", err)
|
||||
}
|
||||
|
||||
count, err = c.gitspaceConfigStore.Count(ctx, &filter)
|
||||
filterCount, err = c.gitspaceConfigStore.Count(ctx, &filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to count gitspaces in space: %w", err)
|
||||
return fmt.Errorf("failed to filterCount gitspaces in space: %w", err)
|
||||
}
|
||||
// Only filter from RBAC and Space is applied for this count, the user filter will be empty for admin users.
|
||||
allGitspacesInSpaceCount, err = c.gitspaceConfigStore.Count(ctx, &types.GitspaceFilter{
|
||||
Deleted: filter.Deleted,
|
||||
MarkedForDeletion: filter.MarkedForDeletion,
|
||||
GitspaceInstanceFilter: types.GitspaceInstanceFilter{
|
||||
UserIdentifier: filter.UserIdentifier,
|
||||
SpaceIDs: filter.SpaceIDs,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to count all gitspace configs in space: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, dbtx.TxDefaultReadOnly)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
for _, gitspaceConfig := range gitspaceConfigs {
|
||||
|
@ -101,7 +113,7 @@ func (c *Service) ListGitspacesForSpace(
|
|||
gitspaceConfig.BranchURL = c.GetBranchURL(ctx, gitspaceConfig)
|
||||
}
|
||||
|
||||
return gitspaceConfigs, count, nil
|
||||
return gitspaceConfigs, filterCount, allGitspacesInSpaceCount, nil
|
||||
}
|
||||
|
||||
func (c *Service) GetBranchURL(ctx context.Context, config *types.GitspaceConfig) string {
|
||||
|
|
Loading…
Reference in New Issue