satellite/console: store partner id on api key and project creation (#2743)

* init

* remove commented code

* add test

* remove unnecessary code

* add error log
This commit is contained in:
Yingrong Zhao 2019-08-12 17:29:40 -04:00 committed by GitHub
parent 3e41767f22
commit 878a3c802b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -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(

View File

@ -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)

View File

@ -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