diff --git a/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go b/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go index c68d67c1cf..51cb03b67d 100644 --- a/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go +++ b/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go @@ -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 } diff --git a/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository_test.go b/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository_test.go new file mode 100644 index 0000000000..225ad9d4d9 --- /dev/null +++ b/pkg/appStore/discover/repository/AppStoreApplicationVersionRepository_test.go @@ -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) + }) +} diff --git a/pkg/auth/user/repository/RoleGroupRepository.go b/pkg/auth/user/repository/RoleGroupRepository.go index dfeb380419..3763bff2cb 100644 --- a/pkg/auth/user/repository/RoleGroupRepository.go +++ b/pkg/auth/user/repository/RoleGroupRepository.go @@ -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). diff --git a/pkg/auth/user/repository/UserAuthRepository.go b/pkg/auth/user/repository/UserAuthRepository.go index ce8fe2940f..3a4b4926aa 100644 --- a/pkg/auth/user/repository/UserAuthRepository.go +++ b/pkg/auth/user/repository/UserAuthRepository.go @@ -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 } diff --git a/pkg/auth/user/repository/UserAuthRepository_test.go b/pkg/auth/user/repository/UserAuthRepository_test.go new file mode 100644 index 0000000000..1999ffcc2a --- /dev/null +++ b/pkg/auth/user/repository/UserAuthRepository_test.go @@ -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) + }) +}