MCPcopy Create free account
hub / github.com/rilldata/rill / LeaveOrganization

Method LeaveOrganization

admin/server/organizations.go:728–772  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.LeaveOrganizationRequest)

Source from the content-addressed store, hash-verified

726}
727
728func (s *Server) LeaveOrganization(ctx context.Context, req *adminv1.LeaveOrganizationRequest) (*adminv1.LeaveOrganizationResponse, error) {
729 observability.AddRequestAttributes(ctx,
730 attribute.String("args.org", req.Org),
731 )
732
733 // Check the request is made by an authenticated user
734 claims := auth.GetClaims(ctx)
735 if claims.OwnerType() != auth.OwnerTypeUser {
736 return nil, status.Error(codes.Unauthenticated, "not authenticated as a user")
737 }
738
739 org, err := s.admin.DB.FindOrganizationByName(ctx, req.Org)
740 if err != nil {
741 return nil, err
742 }
743
744 if !claims.OrganizationPermissions(ctx, org.ID).ManageOrgMembers {
745 return nil, status.Error(codes.PermissionDenied, "not allowed to remove org members")
746 }
747
748 user, err := s.admin.DB.FindUser(ctx, claims.OwnerID())
749 if err != nil {
750 return nil, err
751 }
752
753 if org.BillingEmail == user.Email {
754 return nil, status.Error(codes.FailedPrecondition, "this user is the billing email for the organization, please update the billing email before leaving")
755 }
756
757 // check if the user is the last admin
758 _, isLastAdmin, err := s.admin.DB.FindOrganizationMemberUserAdminStatus(ctx, org.ID, user.ID)
759 if err != nil {
760 return nil, err
761 }
762 if isLastAdmin {
763 return nil, status.Error(codes.FailedPrecondition, "cannot leave because you are the last admin")
764 }
765
766 err = s.admin.DeleteOrganizationMemberUser(ctx, org.ID, user.ID)
767 if err != nil {
768 return nil, err
769 }
770
771 return &adminv1.LeaveOrganizationResponse{}, nil
772}
773
774func (s *Server) CreateWhitelistedDomain(ctx context.Context, req *adminv1.CreateWhitelistedDomainRequest) (*adminv1.CreateWhitelistedDomainResponse, error) {
775 observability.AddRequestAttributes(ctx,

Callers

nothing calls this directly

Calls 11

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
StringMethod · 0.65
OwnerTypeMethod · 0.65
FindUserMethod · 0.65
OwnerIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected