Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto admin-app compose-up-dev
.DEFAULT_GOAL := build
PROTON_COMMIT := "6de0e105ca8f1cb3719d35970bf54af1019f0048"
PROTON_COMMIT := "859ba765e6cfd44736ddcf42664b742fe7fd916e"

admin-app:
@echo " > generating admin build"
Expand Down
2 changes: 1 addition & 1 deletion cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func editProjectCommand(cliConfig *Config) *cli.Command {
spinner := printer.Spin("")
defer spinner.Stop()

var reqBody frontierv1beta1.ProjectRequestBody
var reqBody frontierv1beta1.UpdateProjectRequestBody
if err := file.Parse(filePath, &reqBody); err != nil {
return err
}
Expand Down
15 changes: 6 additions & 9 deletions internal/api/v1beta1connect/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (h *ConnectHandler) GetProject(ctx context.Context, request *connect.Reques

func (h *ConnectHandler) UpdateProject(ctx context.Context, request *connect.Request[frontierv1beta1.UpdateProjectRequest]) (*connect.Response[frontierv1beta1.UpdateProjectResponse], error) {
errorLogger := NewErrorLogger()
auditor := audit.GetAuditor(ctx, request.Msg.GetBody().GetOrgId())

if request.Msg.GetBody() == nil {
return nil, connect.NewError(connect.CodeInvalidArgument, ErrBadRequest)
Expand All @@ -112,17 +111,15 @@ func (h *ConnectHandler) UpdateProject(ctx context.Context, request *connect.Req
metaDataMap := metadata.Build(request.Msg.GetBody().GetMetadata().AsMap())

updatedProject, err := h.projectService.Update(ctx, project.Project{
ID: request.Msg.GetId(),
Name: request.Msg.GetBody().GetName(),
Title: request.Msg.GetBody().GetTitle(),
Organization: organization.Organization{ID: request.Msg.GetBody().GetOrgId()},
Metadata: metaDataMap,
ID: request.Msg.GetId(),
Name: request.Msg.GetBody().GetName(),
Title: request.Msg.GetBody().GetTitle(),
Metadata: metaDataMap,
})
if err != nil {
errorLogger.LogServiceError(ctx, request, "UpdateProject", err,
"project_id", request.Msg.GetId(),
"project_name", request.Msg.GetBody().GetName(),
"org_id", request.Msg.GetBody().GetOrgId())
"project_name", request.Msg.GetBody().GetName())
return nil, translateProjectServiceError(err)
}

Expand All @@ -132,7 +129,7 @@ func (h *ConnectHandler) UpdateProject(ctx context.Context, request *connect.Req
return nil, connect.NewError(connect.CodeInternal, ErrInternalServerError)
}

auditor.Log(audit.ProjectUpdatedEvent, audit.ProjectTarget(updatedProject.ID))
audit.GetAuditor(ctx, updatedProject.Organization.ID).Log(audit.ProjectUpdatedEvent, audit.ProjectTarget(updatedProject.ID))
return connect.NewResponse(&frontierv1beta1.UpdateProjectResponse{Project: projectPB}), nil
}

Expand Down
87 changes: 31 additions & 56 deletions internal/api/v1beta1connect/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ func TestHandler_GetProject(t *testing.T) {
}

func TestHandler_UpdateProject(t *testing.T) {
// Handler no longer forwards Organization to the service — UpdateProject
// cannot mutate a project's parent org.
updateInput := project.Project{
ID: testProjectMap[testProjectID].ID,
Name: testProjectMap[testProjectID].Name,
Metadata: testProjectMap[testProjectID].Metadata,
}
updateBody := &frontierv1beta1.UpdateProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
}
tests := []struct {
name string
setup func(ps *mocks.ProjectService)
Expand All @@ -392,99 +407,59 @@ func TestHandler_UpdateProject(t *testing.T) {
{
name: "should return internal error if project service return some error",
setup: func(ps *mocks.ProjectService) {
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), testProjectMap[testProjectID]).Return(project.Project{}, errors.New("test error"))
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), updateInput).Return(project.Project{}, errors.New("test error"))
},
request: connect.NewRequest(&frontierv1beta1.UpdateProjectRequest{
Id: testProjectID,
Body: &frontierv1beta1.ProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
OrgId: testProjectMap[testProjectID].Organization.ID,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
},
Id: testProjectID,
Body: updateBody,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInternal, ErrInternalServerError),
},
{
name: "should return bad request error if org id is not uuid",
name: "should translate organization.ErrInvalidUUID to invalid argument",
setup: func(ps *mocks.ProjectService) {
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), testProjectMap[testProjectID]).Return(project.Project{}, organization.ErrInvalidUUID)
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), updateInput).Return(project.Project{}, organization.ErrInvalidUUID)
},
request: connect.NewRequest(&frontierv1beta1.UpdateProjectRequest{
Id: testProjectID,
Body: &frontierv1beta1.ProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
OrgId: testProjectMap[testProjectID].Organization.ID,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
},
Id: testProjectID,
Body: updateBody,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
},
{
name: "should return not found error if project not exist",
setup: func(ps *mocks.ProjectService) {
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrNotExist)
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), updateInput).Return(project.Project{}, project.ErrNotExist)
},
request: connect.NewRequest(&frontierv1beta1.UpdateProjectRequest{
Id: testProjectID,
Body: &frontierv1beta1.ProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
OrgId: testProjectMap[testProjectID].Organization.ID,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
},
Id: testProjectID,
Body: updateBody,
}),
want: nil,
wantErr: connect.NewError(connect.CodeNotFound, ErrNotFound),
},
{
name: "should return conflict error if project service return err conflict",
setup: func(ps *mocks.ProjectService) {
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), testProjectMap[testProjectID]).Return(project.Project{}, project.ErrConflict)
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), updateInput).Return(project.Project{}, project.ErrConflict)
},
request: connect.NewRequest(&frontierv1beta1.UpdateProjectRequest{
Id: testProjectID,
Body: &frontierv1beta1.ProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
OrgId: testProjectMap[testProjectID].Organization.ID,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
},
Id: testProjectID,
Body: updateBody,
}),
want: nil,
wantErr: connect.NewError(connect.CodeAlreadyExists, ErrConflictRequest),
},
{
name: "should return success if project service return nil error",
setup: func(ps *mocks.ProjectService) {
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), testProjectMap[testProjectID]).Return(testProjectMap[testProjectID], nil)
ps.EXPECT().Update(mock.AnythingOfType("context.backgroundCtx"), updateInput).Return(testProjectMap[testProjectID], nil)
},
request: connect.NewRequest(&frontierv1beta1.UpdateProjectRequest{
Id: testProjectID,
Body: &frontierv1beta1.ProjectRequestBody{
Name: testProjectMap[testProjectID].Name,
OrgId: testProjectMap[testProjectID].Organization.ID,
Metadata: &structpb.Struct{
Fields: map[string]*structpb.Value{
"email": structpb.NewStringValue(testProjectMap[testProjectID].Metadata["email"].(string)),
},
},
},
Id: testProjectID,
Body: updateBody,
}),
want: connect.NewResponse(&frontierv1beta1.UpdateProjectResponse{
Project: &frontierv1beta1.Project{
Expand Down
6 changes: 0 additions & 6 deletions internal/store/postgres/project_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ func (r ProjectRepository) UpdateByID(ctx context.Context, prj project.Project)
query, params, err := dialect.Update(TABLE_PROJECTS).Set(
goqu.Record{
"title": prj.Title,
"org_id": prj.Organization.ID,
"metadata": marshaledMetadata,
"updated_at": goqu.L("now()"),
}).Where(goqu.Ex{"id": prj.ID}).Returning(&Project{}).ToSQL()
Expand All @@ -258,8 +257,6 @@ func (r ProjectRepository) UpdateByID(ctx context.Context, prj project.Project)
return project.Project{}, project.ErrInvalidUUID
case errors.Is(err, ErrDuplicateKey):
return project.Project{}, project.ErrConflict
case errors.Is(err, ErrForeignKeyViolation):
return project.Project{}, organization.ErrNotExist
default:
return project.Project{}, fmt.Errorf("%w: %s", dbErr, err)
}
Expand All @@ -286,7 +283,6 @@ func (r ProjectRepository) UpdateByName(ctx context.Context, prj project.Project
query, params, err := dialect.Update(TABLE_PROJECTS).Set(
goqu.Record{
"title": prj.Title,
"org_id": prj.Organization.ID,
"metadata": marshaledMetadata,
"updated_at": goqu.L("now()"),
}).Where(goqu.Ex{"name": prj.Name}).Returning(&Project{}).ToSQL()
Expand All @@ -306,8 +302,6 @@ func (r ProjectRepository) UpdateByName(ctx context.Context, prj project.Project
return project.Project{}, project.ErrInvalidUUID
case errors.Is(err, ErrDuplicateKey):
return project.Project{}, project.ErrConflict
case errors.Is(err, ErrForeignKeyViolation):
return project.Project{}, organization.ErrNotExist
default:
return project.Project{}, fmt.Errorf("%w: %s", dbErr, err)
}
Expand Down
42 changes: 0 additions & 42 deletions internal/store/postgres/project_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,28 +393,6 @@ func (s *ProjectRepositoryTestSuite) TestUpdateByID() {
},
ErrString: project.ErrInvalidUUID.Error(),
},
{
Description: "should return error if org id is not uuid",
ProjectToUpdate: project.Project{
ID: s.projects[0].ID,
Name: "not-exist",
Organization: organization.Organization{
ID: "not-uuid",
},
},
ErrString: project.ErrInvalidUUID.Error(),
},
{
Description: "should return error if org id not exist",
ProjectToUpdate: project.Project{
ID: s.projects[0].ID,
Name: "not-exist",
Organization: organization.Organization{
ID: uuid.NewString(),
},
},
ErrString: organization.ErrNotExist.Error(),
},
{
Description: "should return error if project id is empty",
ErrString: project.ErrInvalidID.Error(),
Expand Down Expand Up @@ -468,26 +446,6 @@ func (s *ProjectRepositoryTestSuite) TestUpdateByName() {
},
ErrString: project.ErrNotExist.Error(),
},
{
Description: "should return error if org id is not uuid",
ProjectToUpdate: project.Project{
Name: "not-exist",
Organization: organization.Organization{
ID: "not-uuid",
},
},
ErrString: organization.ErrInvalidUUID.Error(),
},
{
Description: "should return error if org id not exist",
ProjectToUpdate: project.Project{
Name: "not-exist",
Organization: organization.Organization{
ID: uuid.NewString(),
},
},
ErrString: project.ErrNotExist.Error(),
},
{
Description: "should return error if project slug is empty",
ErrString: project.ErrInvalidID.Error(),
Expand Down
Loading
Loading