Skip to content

Commit

Permalink
fix(account): user cannot be created in multitenant
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Apr 3, 2024
1 parent 72a0857 commit 5cbc45b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions account/accountusecase/accountinteractor/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ func (i *Workspace) Create(ctx context.Context, name string, firstUser workspace
return nil, accountinterfaces.ErrInvalidOperator
}

return Run1(ctx, operator, i.repos, Usecase().Transaction(), func(ctx context.Context) (*workspace.Workspace, error) {
if len(strings.TrimSpace(name)) == 0 {
return nil, user.ErrInvalidName
}
if len(strings.TrimSpace(name)) == 0 {
return nil, user.ErrInvalidName
}

firstUsers, err := i.userquery.FetchByID(ctx, []user.ID{firstUser})
if err != nil || len(firstUsers) == 0 {
if err == nil {
return nil, rerror.ErrNotFound
}
return nil, err
firstUsers, err := i.userquery.FetchByID(ctx, []user.ID{firstUser})
if err != nil || len(firstUsers) == 0 {
if err == nil {
return nil, rerror.ErrNotFound
}
return nil, err
}

return Run1(ctx, operator, i.repos, Usecase().Transaction(), func(ctx context.Context) (*workspace.Workspace, error) {
ws, err := workspace.New().
NewID().
Name(name).
Expand Down Expand Up @@ -119,6 +119,11 @@ func (i *Workspace) AddUserMember(ctx context.Context, workspaceID workspace.ID,
return nil, accountinterfaces.ErrInvalidOperator
}

ul, err := i.userquery.FetchByID(ctx, maps.Keys(users))
if err != nil {
return nil, err
}

return Run1(ctx, operator, i.repos, Usecase().Transaction().WithOwnableWorkspaces(workspaceID), func(ctx context.Context) (*workspace.Workspace, error) {
ws, err := i.repos.Workspace.FindByID(ctx, workspaceID)
if err != nil {
Expand All @@ -129,11 +134,6 @@ func (i *Workspace) AddUserMember(ctx context.Context, workspaceID workspace.ID,
return nil, workspace.ErrCannotModifyPersonalWorkspace
}

ul, err := i.userquery.FetchByID(ctx, maps.Keys(users))
if err != nil {
return nil, err
}

if i.enforceMemberCount != nil {
if err := i.enforceMemberCount(ctx, ws, ul, operator); err != nil {
return nil, err
Expand Down

0 comments on commit 5cbc45b

Please sign in to comment.