MCPcopy
hub / github.com/superplanehq/superplane / describeOrganizationCreationStatus

Method describeOrganizationCreationStatus

pkg/public/server.go:807–852  ·  view source on GitHub ↗
(
	ctx context.Context,
	accountID string,
)

Source from the content-addressed store, hash-verified

805}
806
807func (s *Server) describeOrganizationCreationStatus(
808 ctx context.Context,
809 accountID string,
810) (*organizationCreationStatusResponse, error) {
811 organizationCount, err := models.CountOrganizationsByBillingAccount(accountID)
812 if err != nil {
813 log.WithError(err).
814 WithField("account_id", accountID).
815 WithField("stage", "count_organizations").
816 Error("failed to count organizations for billing account")
817 return nil, fmt.Errorf("count organizations for account %s: %w", accountID, err)
818 }
819
820 response := &organizationCreationStatusResponse{
821 Allowed: true,
822 UsageEnabled: s.usageService != nil && s.usageService.Enabled(),
823 CurrentOrganizations: int32(organizationCount),
824 }
825
826 if !response.UsageEnabled {
827 return response, nil
828 }
829
830 checkResponse, err := s.checkAccountOrganizationCreationLimits(
831 ctx,
832 accountID,
833 &usagepb.AccountState{Organizations: int32(organizationCount + 1)},
834 )
835 if err != nil {
836 log.WithError(err).
837 WithField("account_id", accountID).
838 WithField("stage", "check_account_limits").
839 WithField("grpc_code", status.Code(err).String()).
840 Error("failed to check account organization creation limits")
841 return nil, fmt.Errorf("check account limits for account %s: %w", accountID, err)
842 }
843
844 response.MaxOrganizations = checkResponse.GetLimits().GetMaxOrganizations()
845
846 if violationErr := usage.LimitViolationError(checkResponse.GetViolations()); violationErr != nil {
847 response.Allowed = false
848 response.Message = status.Convert(violationErr).Message()
849 }
850
851 return response, nil
852}
853
854func (s *Server) checkAccountOrganizationCreationLimits(
855 ctx context.Context,

Callers 2

createOrganizationMethod · 0.95

Calls 7

LimitViolationErrorFunction · 0.92
ErrorfMethod · 0.80
ErrorMethod · 0.65
EnabledMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected