Add api membership during organization creation

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-11-13 18:01:00 +01:00
parent 542dfb9890
commit 08c6cc8d09
2 changed files with 53 additions and 0 deletions

View File

@@ -1377,6 +1377,7 @@ func (r *membershipConnectionResolver) TotalCount(ctx context.Context, obj *type
// CreateOrganization is the resolver for the createOrganization field.
func (r *mutationResolver) CreateOrganization(ctx context.Context, input types.CreateOrganizationInput) (*types.CreateOrganizationPayload, error) {
currentUser := UserFromContext(ctx)
currentAPIKey := UserAPIKeyFromContext(ctx)
tenantID := gid.NewTenantID()
@@ -1411,6 +1412,25 @@ func (r *mutationResolver) CreateOrganization(ctx context.Context, input types.C
panic(fmt.Errorf("cannot add user to organization: %w", err))
}
if currentAPIKey != nil {
membership, err := authz.GetMembershipByUserAndOrganizationID(ctx, currentUser.ID, organization.ID)
if err != nil {
panic(fmt.Errorf("cannot get user membership: %w", err))
}
err = r.authSvc.AddAPIKeyMembershipToOrganization(
ctx,
tenantID,
currentAPIKey.ID,
membership.ID,
organization.ID,
coredata.APIRoleFull,
)
if err != nil {
panic(fmt.Errorf("cannot add API key membership to organization: %w", err))
}
}
_, err = prb.Peoples.Create(
ctx,
probo.CreatePeopleRequest{