Skip to content

Commit

Permalink
Merge pull request #974 from traPtitech/fix/app-ownerid
Browse files Browse the repository at this point in the history
他人のリポジトリからアプリを作ったときに、アプリ作成者がアプリオーナーになるように
  • Loading branch information
pirosiki197 authored Nov 16, 2024
2 parents 96cb7c2 + afcfbc0 commit dbbdcea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/infrastructure/grpc/api_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"connectrpc.com/connect"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/samber/lo"
"github.com/traPtitech/neoshowcase/pkg/domain"
"github.com/traPtitech/neoshowcase/pkg/domain/web"
"github.com/traPtitech/neoshowcase/pkg/infrastructure/grpc/pb"
Expand All @@ -21,6 +22,13 @@ func (s *APIService) CreateApplication(ctx context.Context, req *connect.Request
user := web.GetUser(ctx)
now := time.Now()
config := pbconvert.FromPBApplicationConfig(msg.Config)

repo, err := s.svc.GetRepository(ctx, msg.RepositoryId)
if err != nil {
return nil, handleUseCaseError(err)
}
ownerIDs := lo.Uniq(append(repo.OwnerIDs, user.ID))

app := &domain.Application{
ID: domain.NewID(),
Name: msg.Name,
Expand All @@ -36,9 +44,9 @@ func (s *APIService) CreateApplication(ctx context.Context, req *connect.Request
Config: config,
Websites: ds.Map(msg.Websites, pbconvert.FromPBCreateWebsiteRequest),
PortPublications: ds.Map(msg.PortPublications, pbconvert.FromPBPortPublication),
OwnerIDs: []string{user.ID},
OwnerIDs: ownerIDs,
}
app, err := s.svc.CreateApplication(ctx, app)
app, err = s.svc.CreateApplication(ctx, app)
if err != nil {
return nil, handleUseCaseError(err)
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/usecase/apiserver/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ func (s *Service) validateApp(ctx context.Context, app *domain.Application) erro
}

func (s *Service) CreateApplication(ctx context.Context, app *domain.Application) (*domain.Application, error) {
// Fill owners field
repo, err := s.gitRepo.GetRepository(ctx, app.RepositoryID)
if err != nil {
return nil, errors.Wrap(err, "failed to get repository metadata")
}
app.OwnerIDs = repo.OwnerIDs

for _, website := range app.Websites {
website.Normalize()
Expand Down

0 comments on commit dbbdcea

Please sign in to comment.