MCPcopy Create free account
hub / github.com/bytebase/bytebase / preUndeleteUserGuard

Method preUndeleteUserGuard

backend/api/v1/user_service.go:960–969  ·  view source on GitHub ↗

preUndeleteUserGuard checks seat limits before reactivating a principal. A soft-deleted principal does not occupy a seat, so undeleting one that is already referenced by workspace IAM (via allUsers, a direct binding, or a group) re-occupies a seat and must respect the limit. When the principal is no

(ctx context.Context, workspaceID string, user *store.UserMessage)

Source from the content-addressed store, hash-verified

958// group) re-occupies a seat and must respect the limit. When the principal is
959// not referenced, undeleting adds no seat and is always allowed.
960func (s *UserService) preUndeleteUserGuard(ctx context.Context, workspaceID string, user *store.UserMessage) error {
961 p, err := s.store.GetWorkspaceIamPolicy(ctx, workspaceID)
962 if err != nil {
963 return connect.NewError(connect.CodeInternal, errors.Wrap(err, "failed to get workspace IAM policy"))
964 }
965 if len(utils.GetUserIAMPolicyBindings(ctx, s.store, workspaceID, user, p.Policy)) == 0 {
966 return nil
967 }
968 return userCountGuard(ctx, s.store, s.licenseService, workspaceID, p.Policy, s.profile.SaaS)
969}
970
971func policyContainsAllUsers(policy *storepb.IamPolicy) bool {
972 for _, binding := range policy.Bindings {

Callers 1

UndeleteUserMethod · 0.95

Calls 3

GetUserIAMPolicyBindingsFunction · 0.92
userCountGuardFunction · 0.85
GetWorkspaceIamPolicyMethod · 0.80

Tested by

no test coverage detected