From 878a3c802b9014ca38c8bb59159f90f349185bce Mon Sep 17 00:00:00 2001 From: Yingrong Zhao Date: Mon, 12 Aug 2019 17:29:40 -0400 Subject: [PATCH] satellite/console: store partner id on api key and project creation (#2743) * init * remove commented code * add test * remove unnecessary code * add error log --- .../console/consoleweb/consoleql/mutation_test.go | 1 + satellite/console/service.go | 12 +++--------- satellite/satellitedb/projects.go | 9 +++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/satellite/console/consoleweb/consoleql/mutation_test.go b/satellite/console/consoleweb/consoleql/mutation_test.go index 0990f4d3a..4e17218b4 100644 --- a/satellite/console/consoleweb/consoleql/mutation_test.go +++ b/satellite/console/consoleweb/consoleql/mutation_test.go @@ -343,6 +343,7 @@ func TestGrapqhlMutation(t *testing.T) { project, err := service.GetProject(authCtx, *pID) require.NoError(t, err) + require.Equal(t, rootUser.PartnerID, project.PartnerID) t.Run("Update project description mutation", func(t *testing.T) { query := fmt.Sprintf( diff --git a/satellite/console/service.go b/satellite/console/service.go index 83809158c..2a4127660 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -717,9 +717,11 @@ func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p Description: projectInfo.Description, Name: projectInfo.Name, OwnerID: auth.User.ID, + PartnerID: auth.User.PartnerID, }, ) if err != nil { + s.log.Error("internal error", zap.Error(err)) return errs.New(internalErrMsg) } @@ -947,15 +949,7 @@ func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name st Name: name, ProjectID: projectID, Secret: secret, - } - - user, err := s.GetUser(ctx, auth.User.ID) - if err != nil { - return nil, nil, err - } - // If the user has a partnerID set it in the apikey for value attribution - if !user.PartnerID.IsZero() { - apikey.PartnerID = user.PartnerID + PartnerID: auth.User.PartnerID, } info, err := s.store.APIKeys().Create(ctx, key.Head(), apikey) diff --git a/satellite/satellitedb/projects.go b/satellite/satellitedb/projects.go index 1c643f2b4..d2eb1a1f1 100644 --- a/satellite/satellitedb/projects.go +++ b/satellite/satellitedb/projects.go @@ -134,6 +134,14 @@ func projectFromDBX(ctx context.Context, project *dbx.Project) (_ *console.Proje return nil, err } + var partnerID uuid.UUID + if len(project.PartnerId) > 0 { + partnerID, err = bytesToUUID(project.PartnerId) + if err != nil { + return nil, err + } + } + ownerID, err := bytesToUUID(project.OwnerId) if err != nil { return nil, err @@ -143,6 +151,7 @@ func projectFromDBX(ctx context.Context, project *dbx.Project) (_ *console.Proje ID: id, Name: project.Name, Description: project.Description, + PartnerID: partnerID, OwnerID: ownerID, CreatedAt: project.CreatedAt, }, nil