(ctx context.Context, req *adminv1.CreateOrganizationRequest)
| 107 | } |
| 108 | |
| 109 | func (s *Server) CreateOrganization(ctx context.Context, req *adminv1.CreateOrganizationRequest) (*adminv1.CreateOrganizationResponse, error) { |
| 110 | observability.AddRequestAttributes(ctx, |
| 111 | attribute.String("args.org", req.Name), |
| 112 | attribute.String("args.description", req.Description), |
| 113 | ) |
| 114 | |
| 115 | // Check the request is made by an authenticated user |
| 116 | claims := auth.GetClaims(ctx) |
| 117 | if claims.OwnerType() != auth.OwnerTypeUser { |
| 118 | return nil, status.Error(codes.Unauthenticated, "not authenticated as a user") |
| 119 | } |
| 120 | |
| 121 | user, err := s.admin.DB.FindUser(ctx, claims.OwnerID()) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | |
| 126 | if !claims.Superuser(ctx) { |
| 127 | // check single user org limit for this user |
| 128 | count, err := s.admin.DB.CountSingleuserOrganizationsForMemberUser(ctx, user.ID) |
| 129 | if err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | if user.QuotaSingleuserOrgs >= 0 && count >= user.QuotaSingleuserOrgs { |
| 133 | return nil, status.Errorf(codes.FailedPrecondition, "quota exceeded: you can only create %d single-user orgs", user.QuotaSingleuserOrgs) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | org, err := s.admin.CreateOrganizationForUser(ctx, user.ID, user.Email, req.Name, req.DisplayName, req.Description) |
| 138 | if err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | return &adminv1.CreateOrganizationResponse{ |
| 143 | Organization: s.organizationToDTO(org, true), |
| 144 | }, nil |
| 145 | } |
| 146 | |
| 147 | func (s *Server) DeleteOrganization(ctx context.Context, req *adminv1.DeleteOrganizationRequest) (*adminv1.DeleteOrganizationResponse, error) { |
| 148 | observability.AddRequestAttributes(ctx, attribute.String("args.org", req.Org)) |
nothing calls this directly
no test coverage detected