Skip to content

Commit 3c7c5a7

Browse files
soneda-yuyaCopilot
andauthored
feat(server): when operation is not allowed, return false (#1832)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 66ea989 commit 3c7c5a7

File tree

5 files changed

+1512
-27
lines changed

5 files changed

+1512
-27
lines changed

server/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ require (
149149
github.com/smartystreets/assertions v1.1.1 // indirect
150150
github.com/smartystreets/goconvey v1.6.4 // indirect
151151
github.com/sosodev/duration v1.3.1 // indirect
152+
github.com/stretchr/objx v0.5.2 // indirect
152153
github.com/urfave/cli/v2 v2.27.6 // indirect
153154
github.com/valyala/bytebufferpool v1.0.0 // indirect
154155
github.com/valyala/fasthttp v1.34.0 // indirect

server/internal/usecase/interactor/project.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ func (i *Project) Create(ctx context.Context, input interfaces.CreateProjectPara
368368
visibility := project.VisibilityPublic
369369

370370
if i.policyChecker != nil {
371+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(input.WorkspaceID))
372+
if err != nil {
373+
return nil, err
374+
}
375+
if !operationAllowed.Allowed {
376+
return nil, visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by overused seat", errors.New("operation is disabled by overused seat"))
377+
}
378+
371379
errPrivate := i.checkGeneralPolicy(ctx, input.WorkspaceID, project.VisibilityPrivate)
372380
if errPrivate != nil {
373381
visibility = project.VisibilityPublic
@@ -411,6 +419,15 @@ func (i *Project) Update(ctx context.Context, p interfaces.UpdateProjectParam, o
411419
if err != nil {
412420
return nil, err
413421
}
422+
423+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(prj.Workspace()))
424+
if err != nil {
425+
return nil, err
426+
}
427+
if !operationAllowed.Allowed {
428+
return nil, visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by over used seat", errors.New("operation is disabled by over used seat"))
429+
}
430+
414431
if err := i.CanWriteWorkspace(prj.Workspace(), operator); err != nil {
415432
return nil, err
416433
}
@@ -542,6 +559,13 @@ func (i *Project) UpdateVisibility(ctx context.Context, pid id.ProjectID, visibi
542559
if err != nil {
543560
return nil, err
544561
}
562+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(prj.Workspace()))
563+
if err != nil {
564+
return nil, err
565+
}
566+
if !operationAllowed.Allowed {
567+
return nil, visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by over used seat", errors.New("operation is disabled by over used seat"))
568+
}
545569

546570
if err := i.CanWriteWorkspace(prj.Workspace(), operator); err != nil {
547571
return nil, err
@@ -718,6 +742,14 @@ func (i *Project) Publish(ctx context.Context, params interfaces.PublishProjectP
718742
return nil, err
719743
}
720744

745+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(prj.Workspace()))
746+
if err != nil {
747+
return nil, err
748+
}
749+
if !operationAllowed.Allowed {
750+
return nil, visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by over used seat", errors.New("operation is disabled by over used seat"))
751+
}
752+
721753
sc, err := i.sceneRepo.FindByProject(ctx, prj.ID())
722754
if err != nil {
723755
return nil, err
@@ -911,6 +943,14 @@ func (i *Project) Delete(ctx context.Context, projectID id.ProjectID, operator *
911943
return err
912944
}
913945

946+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(prj.Workspace()))
947+
if err != nil {
948+
return err
949+
}
950+
if !operationAllowed.Allowed {
951+
return visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by over used seat", errors.New("operation is disabled by over used seat"))
952+
}
953+
914954
deleter := ProjectDeleter{
915955
SceneDeleter: SceneDeleter{
916956
Scene: i.sceneRepo,
@@ -943,6 +983,14 @@ func (i *Project) ExportProjectData(ctx context.Context, pid id.ProjectID, zipWr
943983
return nil, errors.New("project " + err.Error())
944984
}
945985

986+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(prj.Workspace()))
987+
if err != nil {
988+
return nil, err
989+
}
990+
if !operationAllowed.Allowed {
991+
return nil, visualizer.ErrorWithCallerLogging(ctx, "operation is disabled by over used seat", errors.New("operation is disabled by over used seat"))
992+
}
993+
946994
if prj.IsDeleted() {
947995
fmt.Printf("Error Deleted project: %v\n", prj.ID())
948996
return nil, errors.New("This project is deleted")

0 commit comments

Comments
 (0)