{"record":{"id":"2dc985a01ac476b9","repo":"theonedev/onedev","slug":"cannot-set-email-address-for-disabled-user","errorCode":null,"errorMessage":"Cannot set email address for disabled user","messagePattern":"Cannot set email address for disabled user","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java","lineNumber":77,"sourceCode":"\t\n\t@Api(order=150)\n\t@Path(\"/{emailAddressId}/verified\")\n\t@GET\n\tpublic boolean isEmailAddressVerified(@PathParam(\"emailAddressId\") Long emailAddressId) {\n\t\tEmailAddress emailAddress = emailAddressService.load(emailAddressId);\n    \tif (!SecurityUtils.isAdministrator() && !emailAddress.getOwner().equals(getAuthUser())) \n\t\t\tthrow new UnauthorizedException();\n    \treturn emailAddress.isVerified();\n\t}\n\t\n\t@Api(order=200, description=\"Create new email address\")\n\t@POST\n\tpublic Long createEmailAddress(@NotNull @Valid EmailAddress emailAddress) {\n\t\tvar owner = emailAddress.getOwner();\n\t\tif (!SecurityUtils.isAdministrator() && !owner.equals(getAuthUser()))\n\t\t\tthrow new UnauthorizedException();\n\t\telse if (owner.isDisabled())\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for disabled user\");\n\t\telse if (owner.getType() != User.Type.ORDINARY)\n\t\t\tthrow new NotAcceptableException(\"Cannot set email address for service or ai user\");\n\t\telse if (User.getLoginName(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"Email address with noreply domain is not allowed\");\n\t\telse if (emailAddressService.findByValue(emailAddress.getValue()) != null)\n\t\t\tthrow new NotAcceptableException(\"This email address is already used by another user\");\n\t\t\n\t\tif (SecurityUtils.isAdministrator()) \n\t\t\temailAddress.setVerificationCode(null);\n\t\t\n\t\temailAddressService.create(emailAddress);\n\n\t\tif (!getAuthUser().equals(owner)) \n\t\t\tauditService.audit(null, \"added email address \\\"\" + emailAddress.getValue() + \"\\\" in account \\\"\" + owner.getName() + \"\\\" via RESTful API\", null, null);\n\t\treturn emailAddress.getId();\n\t}\n\t\n\t@Api(order=250, description=\"Set as primary email address\")","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/EmailAddressResource.java#L59-L95","documentation":"The API refuses to create an email address for a disabled user account. Disabled users cannot receive mail or sign in, so attaching an email address to them is rejected with NotAcceptableException. This check applies regardless of whether the caller is an administrator.","triggerScenarios":"POST an EmailAddress whose owner.isDisabled() returns true, even when called by an administrator.","commonSituations":"Provisioning automation re-enabling/assigning addresses to deactivated (e.g. off-boarded) accounts; importing user data where accounts were disabled; race where user is disabled between validation and call.","solutions":["Re-enable the target user account before creating the email address","Skip disabled accounts in provisioning scripts","Pick a different active user as the owner"],"exampleFix":"// before\nif (owner.isDisabled()) createAddress(owner);\n// after\nif (!owner.isDisabled()) createAddress(owner); else reEnableUser(owner);","handlingStrategy":"validation","validationCode":"if (owner.isDisabled()) skip or re-enable user before create;","typeGuard":"boolean canAssign = owner != null && !owner.isDisabled();","tryCatchPattern":"try { createEmailAddress(ea); } catch (NotAcceptableException e) { /* disabled user: re-enable or skip */ }","preventionTips":["Filter disabled users out of provisioning loops","Re-enable accounts before assigning addresses","Keep user status synchronized with your IdP before provisioning"],"tags":["rest-api","user-account","onedev"],"backgroundTag":"invalid-state-transition","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}