feat: [CDE-481]: for the plugin, only show self gitspaces (#2997)

* feat: [CDE-481]: for the plugin, only show self gitspaces
* feat: [CDE-481]: for the plugin, only show self gitspaces
This commit is contained in:
Ansuman Satapathy 2024-11-14 03:52:22 +00:00 committed by Harness
parent a63e2ca2a0
commit d9d00e9e06
2 changed files with 12 additions and 9 deletions

View File

@ -31,15 +31,8 @@ const spaceIsDeleted = "Failed to find space: resource not found"
func (c *Controller) ListAllGitspaces( // nolint:gocognit
ctx context.Context,
session *auth.Session,
filter *types.GitspaceFilter,
) ([]*types.GitspaceConfig, error) {
deleted := false
markedForDeletion := false
filter := &types.GitspaceFilter{
GitspaceInstanceFilter: types.GitspaceInstanceFilter{UserIdentifier: session.Principal.UID},
Deleted: &deleted,
MarkedForDeletion: &markedForDeletion,
}
var result []*types.GitspaceConfig
err := c.tx.WithTx(ctx, func(ctx context.Context) (err error) {
allGitspaceConfigs, err := c.gitspaceConfigStore.ListWithLatestInstance(ctx, filter)

View File

@ -20,13 +20,23 @@ import (
"github.com/harness/gitness/app/api/controller/gitspace"
"github.com/harness/gitness/app/api/render"
"github.com/harness/gitness/app/api/request"
"github.com/harness/gitness/types"
"github.com/harness/gitness/types/enum"
)
func HandleListAllGitspaces(gitspaceCtrl *gitspace.Controller) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
session, _ := request.AuthSessionFrom(ctx)
gitspaces, err := gitspaceCtrl.ListAllGitspaces(ctx, session)
deleted := false
markedForDeletion := false
filter := &types.GitspaceFilter{
GitspaceInstanceFilter: types.GitspaceInstanceFilter{UserIdentifier: session.Principal.UID},
Deleted: &deleted,
MarkedForDeletion: &markedForDeletion,
}
filter.Owner = enum.GitspaceOwnerSelf
gitspaces, err := gitspaceCtrl.ListAllGitspaces(ctx, session, filter)
if err != nil {
render.TranslatedUserError(ctx, w, err)
return