From f0059232240e3f6bc08b497b954d5f9af8aee084 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Tue, 23 Dec 2025 08:35:59 +0100 Subject: [PATCH] Fix missing membership profile when create new org Signed-off-by: Bryan Frimin --- pkg/iam/organization_service.go | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/pkg/iam/organization_service.go b/pkg/iam/organization_service.go index 06f851541..0b9388b34 100644 --- a/pkg/iam/organization_service.go +++ b/pkg/iam/organization_service.go @@ -410,6 +410,14 @@ func (s *OrganizationService) CreateOrganization( CreatedAt: now, UpdatedAt: now, } + membership = &coredata.Membership{ + ID: gid.New(tenantID, coredata.MembershipEntityType), + IdentityID: identityID, + OrganizationID: organizationID, + Role: coredata.MembershipRoleOwner, + CreatedAt: now, + UpdatedAt: now, + } logoFile *coredata.File horizontalLogoFile *coredata.File scope = coredata.NewScope(tenantID) @@ -492,8 +500,13 @@ func (s *OrganizationService) CreateOrganization( err := s.pg.WithTx( ctx, func(tx pg.Conn) error { + identity := &coredata.Identity{} + err := identity.LoadByID(ctx, tx, identityID) + if err != nil { + return fmt.Errorf("cannot load identity: %w", err) + } - err := organization.Insert(ctx, tx) + err = organization.Insert(ctx, tx) if err != nil { return fmt.Errorf("cannot insert organization: %w", err) } @@ -512,19 +525,24 @@ func (s *OrganizationService) CreateOrganization( } } - membership := &coredata.Membership{ - ID: gid.New(tenantID, coredata.MembershipEntityType), - IdentityID: identityID, - OrganizationID: organizationID, - Role: coredata.MembershipRoleOwner, - CreatedAt: now, - UpdatedAt: now, - } err = membership.Insert(ctx, tx, scope) if err != nil { return fmt.Errorf("cannot create membership: %w", err) } + profile := &coredata.MembershipProfile{ + ID: gid.New(tenantID, coredata.MembershipProfileEntityType), + MembershipID: membership.ID, + FullName: identity.FullName, + CreatedAt: now, + UpdatedAt: now, + } + + err = profile.Insert(ctx, tx) + if err != nil { + return fmt.Errorf("cannot insert profile: %w", err) + } + return nil }, )