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

@@ -20,7 +20,7 @@ import (
"github.com/tech/sendico/pkg/mutil/mzap"
"github.com/tech/sendico/server/interface/middleware"
"github.com/tech/sendico/server/internal/mutil/flrstring"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -120,7 +120,7 @@ func (s *service) CreateAccount(
ctx context.Context,
org *model.Organization,
acct *model.Account,
roleDescID primitive.ObjectID,
roleDescID bson.ObjectID,
) error {
if org == nil {
return merrors.InvalidArgument("Organization must not be nil")
@@ -128,7 +128,7 @@ func (s *service) CreateAccount(
if acct == nil || len(acct.Login) == 0 {
return merrors.InvalidArgument("Account must have a non-empty login")
}
if roleDescID == primitive.NilObjectID {
if roleDescID == bson.NilObjectID {
return merrors.InvalidArgument("Role description must be provided")
}
// 1) Create the account
@@ -152,7 +152,7 @@ func (s *service) CreateAccount(
func (s *service) DeleteAccount(
ctx context.Context,
org *model.Organization,
accountRef primitive.ObjectID,
accountRef bson.ObjectID,
) error {
// Check if this is the only member in the organization
if len(org.Members) <= 1 {
@@ -178,7 +178,7 @@ func (s *service) DeleteAccount(
func (s *service) RemoveAccountFromOrganization(
ctx context.Context,
org *model.Organization,
accountRef primitive.ObjectID,
accountRef bson.ObjectID,
) error {
if org == nil {
return merrors.InvalidArgument("Organization must not be nil")
@@ -233,7 +233,7 @@ func (s *service) JoinOrganization(
ctx context.Context,
org *model.Organization,
account *model.Account,
roleDescID primitive.ObjectID,
roleDescID bson.ObjectID,
) error {
if slices.Contains(org.Members, account.ID) {
s.logger.Debug("Account is already a member", mzap.StorableRef(org), mzap.StorableRef(account))
@@ -260,7 +260,7 @@ func (s *service) JoinOrganization(
return nil
}
func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef primitive.ObjectID) error {
func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef bson.ObjectID) error {
s.logger.Info("Deleting roles for organization", mzap.ObjRef("organization_ref", orgRef))
// Get all roles for the organization
@@ -282,7 +282,7 @@ func (s *service) deleteOrganizationRoles(ctx context.Context, orgRef primitive.
return nil
}
func (s *service) deleteOrganizationPolicies(ctx context.Context, orgRef primitive.ObjectID) error {
func (s *service) deleteOrganizationPolicies(ctx context.Context, orgRef bson.ObjectID) error {
s.logger.Info("Deleting policies for organization", mzap.ObjRef("organization_ref", orgRef))
// Get all policies for the organization
@@ -323,7 +323,7 @@ func (s *service) DeleteOrganization(
}
// 10. Finally, delete the organization itself
if err := s.orgDB.Delete(ctx, primitive.NilObjectID, org.ID); err != nil {
if err := s.orgDB.Delete(ctx, bson.NilObjectID, org.ID); err != nil {
s.logger.Warn("Failed to delete organization", zap.Error(err), mzap.StorableRef(org))
return nil, err
}
@@ -342,7 +342,7 @@ func (s *service) DeleteOrganization(
func (s *service) DeleteAll(
ctx context.Context,
org *model.Organization,
accountRef primitive.ObjectID,
accountRef bson.ObjectID,
) error {
s.logger.Info("Starting complete deletion (organization + account)",
mzap.StorableRef(org), mzap.ObjRef("account_ref", accountRef))

View File

@@ -3,23 +3,23 @@ package accountserviceimp
import (
"testing"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson/primitive"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/model"
"go.mongodb.org/mongo-driver/v2/bson"
)
func TestDeleteAccount_Validation(t *testing.T) {
t.Run("DeleteAccount_LastMemberFails", func(t *testing.T) {
orgID := primitive.NewObjectID()
accountID := primitive.NewObjectID()
orgID := bson.NewObjectID()
accountID := bson.NewObjectID()
org := &model.Organization{
OrganizationBase: model.OrganizationBase{
Describable: model.Describable{Name: "Single Member Org"},
},
Members: []primitive.ObjectID{accountID}, // Only one member
Members: []bson.ObjectID{accountID}, // Only one member
}
org.ID = orgID
@@ -30,15 +30,15 @@ func TestDeleteAccount_Validation(t *testing.T) {
})
t.Run("DeleteAccount_MultipleMembersSuccess", func(t *testing.T) {
orgID := primitive.NewObjectID()
accountID := primitive.NewObjectID()
otherAccountID := primitive.NewObjectID()
orgID := bson.NewObjectID()
accountID := bson.NewObjectID()
otherAccountID := bson.NewObjectID()
org := &model.Organization{
OrganizationBase: model.OrganizationBase{
Describable: model.Describable{Name: "Multi Member Org"},
},
Members: []primitive.ObjectID{accountID, otherAccountID}, // Multiple members
Members: []bson.ObjectID{accountID, otherAccountID}, // Multiple members
}
org.ID = orgID
@@ -48,13 +48,13 @@ func TestDeleteAccount_Validation(t *testing.T) {
})
t.Run("DeleteAccount_EmptyMembersList", func(t *testing.T) {
orgID := primitive.NewObjectID()
orgID := bson.NewObjectID()
org := &model.Organization{
OrganizationBase: model.OrganizationBase{
Describable: model.Describable{Name: "Empty Org"},
},
Members: []primitive.ObjectID{}, // No members
Members: []bson.ObjectID{}, // No members
}
org.ID = orgID
@@ -85,7 +85,7 @@ func TestDeleteOrganization_Validation(t *testing.T) {
Describable: model.Describable{Name: "Valid Organization"},
},
}
org.ID = primitive.NewObjectID()
org.ID = bson.NewObjectID()
err := validateDeleteOrganization(org)
require.NoError(t, err)
@@ -94,7 +94,7 @@ func TestDeleteOrganization_Validation(t *testing.T) {
func TestDeleteAll_Validation(t *testing.T) {
t.Run("DeleteAll_NilOrganization", func(t *testing.T) {
accountID := primitive.NewObjectID()
accountID := bson.NewObjectID()
err := validateDeleteAll(nil, accountID)
require.Error(t, err)
assert.Contains(t, err.Error(), "organization cannot be nil")
@@ -106,9 +106,9 @@ func TestDeleteAll_Validation(t *testing.T) {
Describable: model.Describable{Name: "Valid Organization"},
},
}
org.ID = primitive.NewObjectID()
org.ID = bson.NewObjectID()
err := validateDeleteAll(org, primitive.NilObjectID)
err := validateDeleteAll(org, bson.NilObjectID)
require.Error(t, err)
assert.Contains(t, err.Error(), "account ID cannot be empty")
})
@@ -119,8 +119,8 @@ func TestDeleteAll_Validation(t *testing.T) {
Describable: model.Describable{Name: "Valid Organization"},
},
}
org.ID = primitive.NewObjectID()
accountID := primitive.NewObjectID()
org.ID = bson.NewObjectID()
accountID := bson.NewObjectID()
err := validateDeleteAll(org, accountID)
require.NoError(t, err)
@@ -139,17 +139,17 @@ func validateDeleteOrganization(org *model.Organization) error {
if org == nil {
return merrors.InvalidArgument("organization cannot be nil")
}
if org.ID == primitive.NilObjectID {
if org.ID == bson.NilObjectID {
return merrors.InvalidArgument("organization ID cannot be empty")
}
return nil
}
func validateDeleteAll(org *model.Organization, accountRef primitive.ObjectID) error {
func validateDeleteAll(org *model.Organization, accountRef bson.ObjectID) error {
if org == nil {
return merrors.InvalidArgument("organization cannot be nil")
}
if accountRef == primitive.NilObjectID {
if accountRef == bson.NilObjectID {
return merrors.InvalidArgument("account ID cannot be empty")
}
return nil