{"record":{"id":"86a1dffb716aaa60","repo":"bitwarden/server","slug":"org-admin-not-found","errorCode":null,"errorMessage":"Org admin not found.","messagePattern":"Org admin not found\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs","lineNumber":696,"sourceCode":"    }\n\n    public async Task InitiateDeleteAsync(Provider provider, string providerAdminEmail)\n    {\n        if (string.IsNullOrWhiteSpace(provider.Name))\n        {\n            throw new BadRequestException(\"Provider name not found.\");\n        }\n        var providerAdmin = await _userRepository.GetByEmailAsync(providerAdminEmail);\n        if (providerAdmin == null)\n        {\n            throw new BadRequestException(\"Provider admin not found.\");\n        }\n\n        var providerAdminOrgUser = await _providerUserRepository.GetByProviderUserAsync(provider.Id, providerAdmin.Id);\n        if (providerAdminOrgUser == null || providerAdminOrgUser.Status != ProviderUserStatusType.Confirmed ||\n            providerAdminOrgUser.Type != ProviderUserType.ProviderAdmin)\n        {\n            throw new BadRequestException(\"Org admin not found.\");\n        }\n\n        var token = _providerDeleteTokenDataFactory.Protect(new ProviderDeleteTokenable(provider, 1));\n        await _mailService.SendInitiateDeletProviderEmailAsync(providerAdminEmail, provider, token);\n    }\n\n    public async Task DeleteAsync(Provider provider, string token)\n    {\n        if (!_providerDeleteTokenDataFactory.TryUnprotect(token, out var data) || !data.Valid || !data.IsValid(provider))\n        {\n            throw new BadRequestException(\"Invalid token.\");\n        }\n        await DeleteAsync(provider);\n    }\n\n    public async Task DeleteAsync(Provider provider)\n    {\n        await _providerRepository.DeleteAsync(provider);","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/AdminConsole/Services/ProviderService.cs#L678-L714","documentation":"Thrown by ProviderService.InitiateDeleteAsync when the user found by email is not a Confirmed ProviderAdmin of the provider being deleted (providerAdminOrgUser is null, or Status != Confirmed, or Type != ProviderAdmin). Only a confirmed admin of that provider may authorize its deletion. BadRequestException (HTTP 400).","triggerScenarios":"Initiating deletion with an email whose user exists but is not linked to this provider, is still Invited/Accepted (not Confirmed), or is a ServiceUser/ProviderUser but not ProviderAdmin.","commonSituations":"Using a billing-only or lower-privilege contact email; an admin whose invitation was never accepted/confirmed; a user who belongs to a different provider.","solutions":["Use the email of a confirmed ProviderAdmin of the specific provider being deleted.","Confirm/accept the admin's provider invitation first, then initiate deletion.","Verify providerAdminOrgUser.Type == ProviderAdmin and Status == Confirmed before calling."],"exampleFix":"// before\nawait providerService.InitiateDeleteAsync(provider, adminEmail);\n\n// after\nvar admin = await _userRepository.GetByEmailAsync(adminEmail);\nvar pu = await _providerUserRepository.GetByProviderUserAsync(provider.Id, admin.Id);\nif (pu is not { Type: ProviderUserType.ProviderAdmin, Status: ProviderUserStatusType.Confirmed })\n{\n    return BadRequest(\"Admin is not a confirmed provider admin.\");\n}\nawait providerService.InitiateDeleteAsync(provider, adminEmail);","handlingStrategy":"validation","validationCode":"var pu = await providerUserRepository.GetByProviderUserAsync(provider.Id, admin.Id);\nif (pu is not { Type: ProviderUserType.ProviderAdmin, Status: ProviderUserStatusType.Confirmed })\n    return BadRequest(\"Not a confirmed provider admin.\");","typeGuard":"static bool IsConfirmedAdmin(ProviderUser? pu) =>\n    pu is { Type: ProviderUserType.ProviderAdmin, Status: ProviderUserStatusType.Confirmed };","tryCatchPattern":null,"preventionTips":["Confirm the admin's provider invitation before deletion.","Verify admin Type and Status against the specific provider."],"tags":["provider","authorization","deletion","bad-request"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}