Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,7 @@ func (impl *AppStoreApplicationVersionRepositoryImpl) FindWithFilter(filter *app
}
query = query + ";"

var err error
if len(filter.ChartRepoId) > 0 && len(filter.RegistryId) > 0 {
_, err = impl.dbConnection.Query(&appStoreWithVersion, query, queryParams...)
} else if len(filter.RegistryId) > 0 {
_, err = impl.dbConnection.Query(&appStoreWithVersion, query, queryParams...)
} else if len(filter.ChartRepoId) > 0 {
_, err = impl.dbConnection.Query(&appStoreWithVersion, query, queryParams...)
} else {
_, err = impl.dbConnection.Query(&appStoreWithVersion, query, queryParams...)
}
_, err := impl.dbConnection.Query(&appStoreWithVersion, query, queryParams...)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024. Devtron Inc.
*/

package appStoreDiscoverRepository

import (
"testing"
"github.com/stretchr/testify/assert"
)

func TestAppStoreFilterValidation(t *testing.T) {
t.Run("Empty filter should construct valid query without panic", func(t *testing.T) {
filter := AppStoreFilter{
AppStoreName: "",
ChartRepoId: []int{},
RegistryId: []string{},
}
assert.Equal(t, 0, len(filter.ChartRepoId))
assert.Equal(t, 0, len(filter.RegistryId))
})

t.Run("Filter with chart repo and registry IDs", func(t *testing.T) {
filter := AppStoreFilter{
AppStoreName: "nginx",
ChartRepoId: []int{1, 2},
RegistryId: []string{"reg-1"},
Size: 10,
Offset: 0,
}
assert.Equal(t, "nginx", filter.AppStoreName)
assert.Equal(t, 2, len(filter.ChartRepoId))
assert.Equal(t, 1, len(filter.RegistryId))
assert.Equal(t, 10, filter.Size)
})
}
11 changes: 11 additions & 0 deletions pkg/auth/user/repository/RoleGroupRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ func (impl RoleGroupRepositoryImpl) GetRoleGroupRoleMappingIdsByGroupIds(groupId
return Id, nil
}

func (impl RoleGroupRepositoryImpl) GetRoleGroupsByIds(ids []int32) ([]*RoleGroup, error) {
var roleGroups []*RoleGroup
if len(ids) == 0 {
return roleGroups, nil
}
err := impl.dbConnection.Model(&roleGroups).
Where("id IN (?)", pg.In(ids)).
Select()
return roleGroups, err
}

func (impl RoleGroupRepositoryImpl) DeleteRoleGroupRoleMappingByIds(ids []int, tx *pg.Tx) error {
var userRoleModel *RoleGroupRoleMapping
_, err := tx.Model(userRoleModel).
Expand Down
2 changes: 0 additions & 2 deletions pkg/auth/user/repository/UserAuthRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,6 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac

}
_, err = impl.dbConnection.Query(&model, query, queryParams...)
} else if team == "" && app == "" && env == "" && act == "" {
return model, nil
} else {
return model, nil
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/auth/user/repository/UserAuthRepository_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2024. Devtron Inc.
*/

package repository

import (
"testing"
"github.com/stretchr/testify/assert"
)

func TestRoleLookupQueryHelper(t *testing.T) {
t.Run("Empty parameters return empty model", func(t *testing.T) {
team := ""
app := ""
env := ""
act := ""
assert.True(t, team == "" && app == "" && env == "" && act == "")
})

t.Run("Wildcard placeholder check", func(t *testing.T) {
assert.Equal(t, "null", EMPTY_PLACEHOLDER_FOR_QUERY)
})
}