fixed doc env vars + mongo v2 migration

This commit is contained in:
Stephan D
2026-01-31 00:26:42 +01:00
parent cbb7bd8ba6
commit 1aa7e287fb
356 changed files with 1705 additions and 1729 deletions

View File

@@ -7,11 +7,11 @@ import (
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
func SetArchived[T storable.Storable](ctx context.Context, logger mlogger.Logger, newArchived bool, objectRef primitive.ObjectID, repo repository.Repository) error {
func SetArchived[T storable.Storable](ctx context.Context, logger mlogger.Logger, newArchived bool, objectRef bson.ObjectID, repo repository.Repository) error {
objs, err := GetObjects[T](ctx, logger, repository.IDFilter(objectRef), nil, repo)
if err != nil {
logger.Warn("Failed to fetch object", zap.Error(err), mzap.ObjRef("object_ref", objectRef))

View File

@@ -7,7 +7,7 @@ import (
"github.com/tech/sendico/pkg/db/repository/builder"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)

View File

@@ -28,7 +28,7 @@ import (
"github.com/tech/sendico/pkg/model"
mutil "github.com/tech/sendico/pkg/mutil/db"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -40,7 +40,7 @@ import (
func GetAccountBoundObjects[T any](
ctx context.Context,
logger mlogger.Logger,
accountRef, organizationRef primitive.ObjectID,
accountRef, organizationRef bson.ObjectID,
filter builder.Query,
cursor *model.ViewCursor,
enforcer auth.Enforcer,
@@ -70,7 +70,7 @@ func GetAccountBoundObjects[T any](
return nil, merrors.NoData("no_account_bound_objects_found")
}
allowed := make([]primitive.ObjectID, 0, len(allObjects))
allowed := make([]bson.ObjectID, 0, len(allObjects))
for _, ref := range allObjects {
allowed = append(allowed, *ref.GetID())
}

View File

@@ -12,14 +12,14 @@ import (
"github.com/tech/sendico/pkg/model"
mutil "github.com/tech/sendico/pkg/mutil/db"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
func GetProtectedObjects[T any](
ctx context.Context,
logger mlogger.Logger,
accountRef, organizationRef primitive.ObjectID,
accountRef, organizationRef bson.ObjectID,
action model.Action,
filter builder.Query,
cursor *model.ViewCursor,
@@ -44,7 +44,7 @@ func GetProtectedObjects[T any](
return nil, err
}
allowed := make([]primitive.ObjectID, 0, len(res))
allowed := make([]bson.ObjectID, 0, len(res))
for _, ref := range refs {
if ok := res[*ref.GetID()]; ok {
allowed = append(allowed, *ref.GetID())

View File

@@ -6,12 +6,12 @@ import (
"github.com/tech/sendico/pkg/db/repository"
"github.com/tech/sendico/pkg/db/storable"
"github.com/tech/sendico/pkg/mlogger"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
func GetObjectByID(ctx context.Context, logger mlogger.Logger, id string, val storable.Storable, repo repository.Repository) error {
p, err := primitive.ObjectIDFromHex(id)
p, err := bson.ObjectIDFromHex(id)
if err != nil {
logger.Warn("Failed to decode object reference", zap.String("reference", id), zap.String("collection", val.Collection()))
return err

View File

@@ -3,20 +3,20 @@ package helpers
import (
"context"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
// AccountManager defines the interface for account management operations
type AccountManager interface {
// DeleteOrganization deletes an organization and all its associated data
// The caller is responsible for wrapping this in a transaction
DeleteOrganization(ctx context.Context, orgRef primitive.ObjectID) error
DeleteOrganization(ctx context.Context, orgRef bson.ObjectID) error
// DeleteAccount deletes an account and all its associated data
// The caller is responsible for wrapping this in a transaction
DeleteAccount(ctx context.Context, accountRef primitive.ObjectID) error
DeleteAccount(ctx context.Context, accountRef bson.ObjectID) error
// DeleteAll deletes all data for a given account and organization
// The caller is responsible for wrapping this in a transaction
DeleteAll(ctx context.Context, accountRef, organizationRef primitive.ObjectID) error
DeleteAll(ctx context.Context, accountRef, organizationRef bson.ObjectID) error
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/tech/sendico/pkg/db/policy"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -45,7 +45,7 @@ func NewAccountManager(
// DeleteOrganization deletes an organization and all its associated data
// The caller is responsible for wrapping this in a transaction
func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitive.ObjectID) error {
func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef bson.ObjectID) error {
m.logger.Debug("Deleting organization", mzap.ObjRef("org_ref", orgRef))
// Delete organization roles
@@ -61,7 +61,7 @@ func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitiv
}
// Finally delete the organization itself
if err := m.orgDB.Delete(ctx, primitive.NilObjectID, orgRef); err != nil {
if err := m.orgDB.Delete(ctx, bson.NilObjectID, orgRef); err != nil {
m.logger.Warn("Failed to delete organization", zap.Error(err), mzap.ObjRef("org_ref", orgRef))
return err
}
@@ -72,7 +72,7 @@ func (m *AccountManager) DeleteOrganization(ctx context.Context, orgRef primitiv
// DeleteAccount deletes an account and all its associated data
// The caller is responsible for wrapping this in a transaction
func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef primitive.ObjectID) error {
func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef bson.ObjectID) error {
m.logger.Debug("Deleting account", mzap.ObjRef("account_ref", accountRef))
// Delete the account
@@ -87,7 +87,7 @@ func (m *AccountManager) DeleteAccount(ctx context.Context, accountRef primitive
// DeleteAll deletes all data for a given account and organization
// The caller is responsible for wrapping this in a transaction
func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organizationRef primitive.ObjectID) error {
func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organizationRef bson.ObjectID) error {
m.logger.Debug("Deleting all data", mzap.ObjRef("account_ref", accountRef), mzap.ObjRef("organization_ref", organizationRef))
// Delete organization first (which will cascade delete all related data)
@@ -107,7 +107,7 @@ func (m *AccountManager) DeleteAll(ctx context.Context, accountRef, organization
}
// deleteOrganizationRoles deletes all roles for an organization
func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef primitive.ObjectID) error {
func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef bson.ObjectID) error {
// Get all roles for the organization
roles, err := m.authManager.Role().List(ctx, orgRef)
if err != nil {
@@ -128,7 +128,7 @@ func (m *AccountManager) deleteOrganizationRoles(ctx context.Context, orgRef pri
}
// deleteOrganizationPolicies deletes all policies for an organization
func (m *AccountManager) deleteOrganizationPolicies(_ context.Context, _ primitive.ObjectID) error {
func (m *AccountManager) deleteOrganizationPolicies(_ context.Context, _ bson.ObjectID) error {
// Note: PolicyDB is used for both roles and policies, but the interface is unclear
// This would need to be implemented differently or skipped for now
m.logger.Warn("Policy deletion not implemented - interface unclear")

View File

@@ -2,11 +2,11 @@ package mzap
import (
"github.com/tech/sendico/pkg/db/storable"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
func ObjRef(name string, objRef primitive.ObjectID) zap.Field {
func ObjRef(name string, objRef bson.ObjectID) zap.Field {
return zap.String(name, objRef.Hex())
}