Skip to content

Commit 8e22bcf

Browse files
AmanGIT07claude
andauthored
refactor(api): drop per-handler org-state checks covered by the gate (#1867)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 34dff88 commit 8e22bcf

7 files changed

Lines changed: 78 additions & 515 deletions

File tree

internal/api/v1beta1connect/domain.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,6 @@ func (h *ConnectHandler) CreateOrganizationDomain(ctx context.Context, request *
4646
}
4747

4848
func (h *ConnectHandler) DeleteOrganizationDomain(ctx context.Context, request *connect.Request[frontierv1beta1.DeleteOrganizationDomainRequest]) (*connect.Response[frontierv1beta1.DeleteOrganizationDomainResponse], error) {
49-
_, err := h.orgService.Get(ctx, request.Msg.GetOrgId())
50-
if err != nil {
51-
switch {
52-
case errors.Is(err, organization.ErrDisabled):
53-
return nil, connect.NewError(connect.CodeFailedPrecondition, ErrOrgDisabled)
54-
case errors.Is(err, organization.ErrNotExist):
55-
return nil, connect.NewError(connect.CodeNotFound, ErrNotFound)
56-
default:
57-
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("DeleteOrganizationDomain.Get: org_id=%s: %w", request.Msg.GetOrgId(), err))
58-
}
59-
}
60-
6149
if err := h.domainService.Delete(ctx, request.Msg.GetId()); err != nil {
6250
switch err {
6351
case domain.ErrNotExist:
@@ -72,18 +60,6 @@ func (h *ConnectHandler) DeleteOrganizationDomain(ctx context.Context, request *
7260
}
7361

7462
func (h *ConnectHandler) GetOrganizationDomain(ctx context.Context, request *connect.Request[frontierv1beta1.GetOrganizationDomainRequest]) (*connect.Response[frontierv1beta1.GetOrganizationDomainResponse], error) {
75-
_, err := h.orgService.Get(ctx, request.Msg.GetOrgId())
76-
if err != nil {
77-
switch {
78-
case errors.Is(err, organization.ErrDisabled):
79-
return nil, connect.NewError(connect.CodeFailedPrecondition, ErrOrgDisabled)
80-
case errors.Is(err, organization.ErrNotExist):
81-
return nil, connect.NewError(connect.CodeNotFound, ErrNotFound)
82-
default:
83-
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("GetOrganizationDomain.Get: org_id=%s: %w", request.Msg.GetOrgId(), err))
84-
}
85-
}
86-
8763
domainResp, err := h.domainService.Get(ctx, request.Msg.GetId())
8864
if err != nil {
8965
switch err {
@@ -131,18 +107,6 @@ func (h *ConnectHandler) JoinOrganization(ctx context.Context, request *connect.
131107
}
132108

133109
func (h *ConnectHandler) VerifyOrganizationDomain(ctx context.Context, request *connect.Request[frontierv1beta1.VerifyOrganizationDomainRequest]) (*connect.Response[frontierv1beta1.VerifyOrganizationDomainResponse], error) {
134-
_, err := h.orgService.Get(ctx, request.Msg.GetOrgId())
135-
if err != nil {
136-
switch {
137-
case errors.Is(err, organization.ErrDisabled):
138-
return nil, connect.NewError(connect.CodeFailedPrecondition, ErrOrgDisabled)
139-
case errors.Is(err, organization.ErrNotExist):
140-
return nil, connect.NewError(connect.CodeNotFound, ErrNotFound)
141-
default:
142-
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("VerifyOrganizationDomain.Get: org_id=%s: %w", request.Msg.GetOrgId(), err))
143-
}
144-
}
145-
146110
domainResp, err := h.domainService.VerifyDomain(ctx, request.Msg.GetId())
147111
if err != nil {
148112
switch err {
@@ -162,15 +126,14 @@ func (h *ConnectHandler) VerifyOrganizationDomain(ctx context.Context, request *
162126
}
163127

164128
func (h *ConnectHandler) ListOrganizationDomains(ctx context.Context, request *connect.Request[frontierv1beta1.ListOrganizationDomainsRequest]) (*connect.Response[frontierv1beta1.ListOrganizationDomainsResponse], error) {
165-
orgResp, err := h.orgService.Get(ctx, request.Msg.GetOrgId())
129+
// org state is enforced on the authorization path; resolve state blind
130+
orgResp, err := h.orgService.GetRaw(ctx, request.Msg.GetOrgId())
166131
if err != nil {
167132
switch {
168-
case errors.Is(err, organization.ErrDisabled):
169-
return nil, connect.NewError(connect.CodeFailedPrecondition, ErrOrgDisabled)
170133
case errors.Is(err, organization.ErrNotExist):
171134
return nil, connect.NewError(connect.CodeNotFound, ErrNotFound)
172135
default:
173-
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("ListOrganizationDomains.Get: org_id=%s: %w", request.Msg.GetOrgId(), err))
136+
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("ListOrganizationDomains.GetRaw: org_id=%s: %w", request.Msg.GetOrgId(), err))
174137
}
175138
}
176139

0 commit comments

Comments
 (0)