Skip to content

Commit 372e77c

Browse files
authored
fix(server): add prop DisableOperationByOverUsedSeat on PolicyCheckPayload (#1829)
1 parent 3f30b6d commit 372e77c

File tree

7 files changed

+93
-13
lines changed

7 files changed

+93
-13
lines changed

server/gql/workspace.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type CreateWorkspacePayload {
100100
type PolicyCheckPayload {
101101
workspaceId: ID!
102102
enableToCreatePrivateProject: Boolean!
103+
disableOperationByOverUsedSeat: Boolean!
103104
}
104105

105106
type UpdateWorkspacePayload {

server/internal/adapter/gql/generated.go

Lines changed: 62 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/internal/adapter/gql/gqlmodel/models_gen.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/internal/adapter/gql/resolver_workspace_policy_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func TestWorkspacePolicyCheck_InputTypes(t *testing.T) {
1919

2020
// Test output structure
2121
output := &gqlmodel.PolicyCheckPayload{
22-
WorkspaceID: input.WorkspaceID,
23-
EnableToCreatePrivateProject: true,
22+
WorkspaceID: input.WorkspaceID,
23+
EnableToCreatePrivateProject: true,
24+
DisableOperationByOverUsedSeat: false,
2425
}
2526

2627
assert.Equal(t, input.WorkspaceID, output.WorkspaceID)
@@ -30,8 +31,9 @@ func TestWorkspacePolicyCheck_InputTypes(t *testing.T) {
3031
func TestWorkspacePolicyCheck_ResponseStructure(t *testing.T) {
3132
// Test that the response structure is correctly defined
3233
payload := &gqlmodel.PolicyCheckPayload{
33-
WorkspaceID: gqlmodel.ID("01H4XCVR7QZJN0Z8V9XN9N9N9N"),
34-
EnableToCreatePrivateProject: true,
34+
WorkspaceID: gqlmodel.ID("01H4XCVR7QZJN0Z8V9XN9N9N9N"),
35+
EnableToCreatePrivateProject: true,
36+
DisableOperationByOverUsedSeat: false,
3537
}
3638

3739
assert.Equal(t, gqlmodel.ID("01H4XCVR7QZJN0Z8V9XN9N9N9N"), payload.WorkspaceID)

server/internal/usecase/gateway/policy_checker.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
PolicyCheckCustomDomainCount PolicyCheckType = "visualizer_custom_domain_count"
1515
PolicyCheckGeneralPrivateProjectCreation PolicyCheckType = "general_private_project_creation"
1616
PolicyCheckGeneralPublicProjectCreation PolicyCheckType = "general_public_project_creation"
17+
PolicyCheckGeneralOperationAllowed PolicyCheckType = "general_operation_allowed"
1718
)
1819

1920
type PolicyCheckRequest struct {
@@ -48,3 +49,11 @@ func CreateGeneralPolicyCheckRequest(workspaceID accountdomain.WorkspaceID, visi
4849
Value: 1,
4950
}
5051
}
52+
53+
func CreateGeneralOperationAllowedCheckRequest(workspaceID accountdomain.WorkspaceID) PolicyCheckRequest {
54+
return PolicyCheckRequest{
55+
WorkspaceID: workspaceID,
56+
CheckType: PolicyCheckGeneralOperationAllowed,
57+
Value: 1,
58+
}
59+
}

server/internal/usecase/interactor/policy.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ func (i *Policy) GetWorkspacePolicy(ctx context.Context, wsid accountdomain.Work
3030
return nil, err
3131
}
3232

33-
res, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralPolicyCheckRequest(ws.ID(), project.VisibilityPrivate))
33+
createPrivateProject, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralPolicyCheckRequest(ws.ID(), project.VisibilityPrivate))
3434

3535
if err != nil {
3636
return nil, err
3737
}
3838

39+
operationAllowed, err := i.policyChecker.CheckPolicy(ctx, gateway.CreateGeneralOperationAllowedCheckRequest(ws.ID()))
40+
if err != nil {
41+
return nil, err
42+
}
43+
3944
return &policy.WorkspacePolicy{
40-
WorkspaceID: wsid,
41-
EnableToCreatePrivateProject: res.Allowed,
45+
WorkspaceID: wsid,
46+
EnableToCreatePrivateProject: createPrivateProject.Allowed,
47+
DisableOperationByOverUsedSeat: !operationAllowed.Allowed,
4248
}, nil
4349
}
4450

server/pkg/policy/policy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ type ID = workspace.PolicyID
1212
var ErrPolicyViolation = errors.New("policy violation")
1313

1414
type WorkspacePolicy struct {
15-
WorkspaceID workspace.ID
16-
EnableToCreatePrivateProject bool
15+
WorkspaceID workspace.ID
16+
EnableToCreatePrivateProject bool
17+
DisableOperationByOverUsedSeat bool
1718
}
1819

1920
type Policy struct {

0 commit comments

Comments
 (0)