{"record":{"id":"5abee5cb5b4ce246","repo":"passbolt/passbolt_api","slug":"could-not-validate-policy-data","errorCode":null,"errorMessage":"Could not validate policy data.","messagePattern":"Could not validate policy data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":422,"severity":"error","filePath":"plugins/PassboltEe/AccountRecovery/src/Model/Table/AccountRecoveryOrganizationPoliciesTable.php","lineNumber":332,"sourceCode":"            'modified_by' => $uac->getId(),\n        ];\n        $accessibleFields = [\n            'policy' => true,\n            'created' => true,\n            'modified' => true,\n            'created_by' => true,\n            'modified_by' => true,\n        ];\n\n        if (isset($publicKeyId)) {\n            $data['public_key_id'] = $publicKeyId;\n            $accessibleFields['public_key_id'] = true;\n        }\n\n        $newPolicy = $this->newEntity($data, ['accessibleFields' => $accessibleFields]);\n        if ($newPolicy->getErrors()) {\n            $em = __('Could not validate policy data.');\n            throw new ValidationException($em, $newPolicy, $this);\n        }\n\n        return $newPolicy;\n    }\n\n    /**\n     * Return a new org policy entity that is set to disabled\n     *\n     * @param \\App\\Utility\\UserAccessControl $uac The user at the origin of the operation\n     * @return \\Passbolt\\AccountRecovery\\Model\\Entity\\AccountRecoveryOrganizationPolicy entity ready to be saved\n     */\n    public function newEntityForDisable(UserAccessControl $uac): AccountRecoveryOrganizationPolicy\n    {\n        /** @var \\Passbolt\\AccountRecovery\\Model\\Entity\\AccountRecoveryOrganizationPolicy $policy */\n        $policy = $this->newEntity([\n                'policy' => AccountRecoveryOrganizationPolicy::ACCOUNT_RECOVERY_ORGANIZATION_POLICY_DISABLED,\n                'created_by' => $uac->getId(),\n                'modified_by' => $uac->getId(),","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/AccountRecovery/src/Model/Table/AccountRecoveryOrganizationPoliciesTable.php#L314-L350","documentation":"A ValidationException raised when building the account recovery organization policy entity: the newEntity() call produced field errors (e.g. invalid policy status/strategy or a bad public_key_id reference). The entity errors are attached to the exception so callers get field-level details.","triggerScenarios":"POST/PUT /account-recovery/organization-policies with an invalid 'policy' value, a public_key_id that fails validation, or required fields missing per the table's validation rules.","commonSituations":"Client sends policy value not in the allowed enum after an upgrade; admin tries to enable the policy without a generated organization key; stale public_key_id pointing at a revoked key.","solutions":["Inspect the exception's entity errors to see which field failed.","Use only supported policy values (e.g. 'opt-in'/'mandatory') for your server version.","Generate/associate a valid organization public key before setting the policy.","Re-run with the latest client to match current schema field names."],"exampleFix":"// before\n{ \"policy\": \"yes\" }\n// after\n{ \"policy\": \"opt-in\", \"account_recovery_organization_public_key_id\": \"<valid-uuid>\" }","handlingStrategy":"try-catch","validationCode":"const ALLOWED = ['opt-in','mandatory'];\nif (!ALLOWED.includes(policy.policy)) throw new Error('unsupported policy value');\nif (policy.account_recovery_organization_public_key_id && !isUuid(policy.account_recovery_organization_public_key_id)) throw new Error('bad key id');","typeGuard":"function isUuid(v) { return typeof v === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v); }","tryCatchPattern":"try { await api.saveOrganizationPolicy(policy); } catch (e) { if (e.body && e.body.account_recovery_organization_policy) { reportFieldErrors(e.body.account_recovery_organization_policy); } else { throw e; } }","preventionTips":["Read field-level errors from the validation exception body.","Only use policy values supported by your server version.","Ensure an organization key exists before enabling the policy.","Pin client/server versions during rollouts."],"tags":["validation","entity","account-recovery","organization-policy"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}