Remove platform tenancy from SXCHNGE customer BFF (#34)
This commit is contained in:
1 parent
7062672a87
commit
981e84a4b4
244 files changed
+651
-17130
No files matched your search
@@ -1,78 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/repository/builder"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// AccountBoundFilter provides factory methods for creating account-bound filters
|
||||
type AccountBoundFilter struct{}
|
||||
|
||||
// NewAccountBoundFilter creates a new AccountBoundFilter instance
|
||||
func NewAccountBoundFilter() *AccountBoundFilter {
|
||||
return &AccountBoundFilter{}
|
||||
}
|
||||
|
||||
// WithoutOrg creates a filter for account-bound objects without organization filter
|
||||
// This filter finds objects where:
|
||||
// - accountRef matches the provided accountRef, OR
|
||||
// - accountRef is nil/null, OR
|
||||
// - accountRef field doesn't exist
|
||||
func (f *AccountBoundFilter) WithoutOrg(accountRef bson.ObjectID) builder.Query {
|
||||
return Query().Or(
|
||||
AccountFilter(accountRef),
|
||||
Filter(model.AccountRefField, nil),
|
||||
Exists(AccountField(), false),
|
||||
)
|
||||
}
|
||||
|
||||
// WithOrg creates a filter for account-bound objects with organization filter
|
||||
// This filter finds objects where:
|
||||
// - accountRef matches the provided accountRef, OR
|
||||
// - accountRef is nil/null, OR
|
||||
// - accountRef field doesn't exist
|
||||
// AND combines with organization filter
|
||||
func (f *AccountBoundFilter) WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query {
|
||||
return Query().And(
|
||||
OrgFilter(organizationRef),
|
||||
f.WithoutOrg(accountRef),
|
||||
)
|
||||
}
|
||||
|
||||
// WithQuery creates a filter for account-bound objects with additional query and organization filter
|
||||
func (f *AccountBoundFilter) WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
accountQuery := f.WithOrg(accountRef, organizationRef)
|
||||
return additionalQuery.And(accountQuery)
|
||||
}
|
||||
|
||||
// WithQueryNoOrg creates a filter for account-bound objects with additional query but no org filter
|
||||
func (f *AccountBoundFilter) WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
accountQuery := f.WithoutOrg(accountRef)
|
||||
return additionalQuery.And(accountQuery)
|
||||
}
|
||||
|
||||
// Global instance for convenience
|
||||
var DefaultAccountBoundFilter = NewAccountBoundFilter()
|
||||
|
||||
// Convenience functions that use the global factory instance
|
||||
|
||||
// WithOrg is a convenience function that uses the default factory
|
||||
func WithOrg(accountRef, organizationRef bson.ObjectID) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithOrg(accountRef, organizationRef)
|
||||
}
|
||||
|
||||
// WithoutOrg is a convenience function that uses the default factory
|
||||
func WithoutOrg(accountRef bson.ObjectID) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithoutOrg(accountRef)
|
||||
}
|
||||
|
||||
// WithQuery is a convenience function that uses the default factory
|
||||
func WithQuery(accountRef, organizationRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithQuery(accountRef, organizationRef, additionalQuery)
|
||||
}
|
||||
|
||||
// WithQueryNoOrg is a convenience function that uses the default factory
|
||||
func WithQueryNoOrg(accountRef bson.ObjectID, additionalQuery builder.Query) builder.Query {
|
||||
return DefaultAccountBoundFilter.WithQueryNoOrg(accountRef, additionalQuery)
|
||||
}
|
||||
@@ -68,22 +68,6 @@ func IsArchivedFilter(isArchived bool) builder.Query {
|
||||
return Query().Filter(IsArchivedField(), isArchived)
|
||||
}
|
||||
|
||||
func OrgField() builder.Field {
|
||||
return Field(storable.OrganizationRefField)
|
||||
}
|
||||
|
||||
func OrgFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(OrgField(), ref)
|
||||
}
|
||||
|
||||
func ProjectField() builder.Field {
|
||||
return Field("projectRef")
|
||||
}
|
||||
|
||||
func ProjectFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(ProjectField(), ref)
|
||||
}
|
||||
|
||||
func AccountField() builder.Field {
|
||||
return Field(model.AccountRefField)
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func TestAccountBoundFilter_WithOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
query := factory.WithOrg(accountRef, orgRef)
|
||||
|
||||
// Test that the query is not nil
|
||||
assert.NotNil(t, query)
|
||||
}
|
||||
|
||||
func TestAccountBoundFilter_WithoutOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := bson.NewObjectID()
|
||||
|
||||
query := factory.WithoutOrg(accountRef)
|
||||
|
||||
// Test that the query is not nil
|
||||
assert.NotNil(t, query)
|
||||
}
|
||||
|
||||
func TestAccountBoundFilter_WithQuery(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
query := factory.WithQuery(accountRef, orgRef, additionalQuery)
|
||||
|
||||
// Test that the query is not nil
|
||||
assert.NotNil(t, query)
|
||||
}
|
||||
|
||||
func TestAccountBoundFilter_WithQueryNoOrg(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
query := factory.WithQueryNoOrg(accountRef, additionalQuery)
|
||||
|
||||
// Test that the query is not nil
|
||||
assert.NotNil(t, query)
|
||||
}
|
||||
|
||||
func TestDefaultAccountBoundFilter(t *testing.T) {
|
||||
// Test that the default factory is not nil
|
||||
assert.NotNil(t, DefaultAccountBoundFilter)
|
||||
|
||||
// Test that it's the correct type
|
||||
assert.IsType(t, &AccountBoundFilter{}, DefaultAccountBoundFilter)
|
||||
}
|
||||
|
||||
func TestConvenienceFunctions(t *testing.T) {
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
additionalQuery := Query().Filter(Field("status"), "active")
|
||||
|
||||
// Test convenience functions
|
||||
query1 := WithOrg(accountRef, orgRef)
|
||||
assert.NotNil(t, query1)
|
||||
|
||||
query2 := WithoutOrg(accountRef)
|
||||
assert.NotNil(t, query2)
|
||||
|
||||
query3 := WithQuery(accountRef, orgRef, additionalQuery)
|
||||
assert.NotNil(t, query3)
|
||||
|
||||
query4 := WithQueryNoOrg(accountRef, additionalQuery)
|
||||
assert.NotNil(t, query4)
|
||||
}
|
||||
|
||||
func TestFilterFactoryConsistency(t *testing.T) {
|
||||
factory := NewAccountBoundFilter()
|
||||
accountRef := bson.NewObjectID()
|
||||
orgRef := bson.NewObjectID()
|
||||
|
||||
// Test that factory methods and convenience functions produce the same result
|
||||
query1 := factory.WithOrg(accountRef, orgRef)
|
||||
query2 := WithOrg(accountRef, orgRef)
|
||||
|
||||
// Both should be valid queries
|
||||
assert.NotNil(t, query1)
|
||||
assert.NotNil(t, query2)
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
ri "git.sendico.io/tech/sxchnge/bff/pkg/db/repository/index"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/storable"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/db/transaction"
|
||||
"git.sendico.io/tech/sxchnge/bff/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
@@ -50,8 +49,6 @@ type Repository interface {
|
||||
DropIndex(ctx context.Context, name string) error
|
||||
ListIndexDefinitions(ctx context.Context) ([]*ri.Definition, error)
|
||||
ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error)
|
||||
ListPermissionBound(ctx context.Context, query builder.Query) ([]model.PermissionBoundStorable, error)
|
||||
ListAccountBound(ctx context.Context, query builder.Query) ([]model.AccountBoundStorable, error)
|
||||
WithTransaction(ctx context.Context, cb transaction.Callback) (any, error)
|
||||
Collection() string
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user