Skip to content

Commit ef28d9f

Browse files
authored
Do not allow to update the tenant of a project (#116)
1 parent 5ddb142 commit ef28d9f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pkg/service/project.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ func (s *projectService) Create(ctx context.Context, req *v1.ProjectCreateReques
6565
return project.NewProjectResponse(), err
6666
}
6767
func (s *projectService) Update(ctx context.Context, req *v1.ProjectUpdateRequest) (*v1.ProjectResponse, error) {
68+
old, err := s.projectStore.Get(ctx, req.Project.Meta.Id)
69+
if err != nil {
70+
return nil, err
71+
}
6872
project := req.Project
69-
err := s.projectStore.Update(ctx, project)
73+
if old.TenantId != project.TenantId {
74+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("update tenant of project:%s is not allowed", project.Meta.Id))
75+
}
76+
err = s.projectStore.Update(ctx, project)
7077
return project.NewProjectResponse(), err
7178
}
7279
func (s *projectService) Delete(ctx context.Context, req *v1.ProjectDeleteRequest) (*v1.ProjectResponse, error) {

pkg/service/project_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ func TestUpdateProject(t *testing.T) {
113113
},
114114
}
115115

116+
storageMock.On("Get", ctx, t1.Meta.Id).Return(t1, nil)
117+
116118
storageMock.On("Update", ctx, t1).Return(nil)
117119
resp, err := ts.Update(ctx, tur)
118120
require.NoError(t, err)

0 commit comments

Comments
 (0)