{"record":{"id":"e902b472f5aa4e79","repo":"passbolt/passbolt_api","slug":"the-record-model-is-not-valid","errorCode":null,"errorMessage":"The record model is not valid.","messagePattern":"The record model is not valid\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Controller/DirectoryIgnoreController.php","lineNumber":68,"sourceCode":"\n    /**\n     * Check if a record is ignored\n     *\n     * @param string $foreignModel foreign model\n     * @param string $foreignKey foreign key\n     * @throws \\App\\Error\\Exception\\ValidationException If the model name or id is not valid\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException if the current user is not an admin\n     * @return void\n     */\n    public function toggle(string $foreignModel, string $foreignKey): void\n    {\n        if ($this->User->role() !== Role::ADMIN) {\n            throw new ForbiddenException(__('You are not authorized to access that location.'));\n        }\n        $this->assertDirectoryEnabled();\n        $foreignModel = $this->normalizeForeignModel($foreignModel);\n        if (!Validation::inList($foreignModel, ['Groups', 'Users', 'DirectoryEntries'])) {\n            throw new BadRequestException(__('The record model is not valid.'));\n        }\n\n        $ignored = null;\n        try {\n            $ignored = $this->DirectoryIgnore->get($foreignKey);\n            $this->DirectoryIgnore->delete($ignored);\n        } catch (RecordNotFoundException $exception) {\n        }\n        $this->success(__('The record is currently ignored as part of directory synchronization.'), $ignored);\n    }\n\n    /**\n     * Check if a record is ignored\n     *\n     * @param string $foreignModel foreign model\n     * @param string $foreignKey foreign key\n     * @throws \\App\\Error\\Exception\\ValidationException If the model name or id is not valid\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException if the current user is not an admin","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Controller/DirectoryIgnoreController.php#L50-L86","documentation":"BadRequestException thrown by DirectoryIgnoreController::toggle when the foreignModel path argument, after normalization, is not one of the allowed values Groups, Users, or DirectoryEntries. normalizeForeignModel singularizes/pluralizes the URL segment, so only the canonical model names are accepted; anything else is rejected as an invalid record model.","triggerScenarios":"Calling the toggle route with a mistyped or unsupported model segment, e.g. /directoryignore/group/<uuid>.json (singular not normalized as expected), /directoryignore/User/<uuid>, or a model that has no ignore support such as 'Gpgkeys'.","commonSituations":"Hand-written curl scripts using singular forms; API docs from older plugin versions listing different model names; clients iterating over directory entity types beyond the three supported ones; URL-encoding or trailing-slash artifacts changing the segment.","solutions":["Use exactly one of the supported model names in the URL: Groups, Users, or DirectoryEntries (case-sensitive).","Verify the foreignModel argument in the client/script matches the route template and isn't truncated or altered by encoding.","Confirm the entity type you intend to ignore is actually supported; map custom types to one of the three before calling.","Check normalizeForeignModel in the controller to see which input forms are accepted, and align the caller with it."],"exampleFix":"// before\nPUT /directoryignore/group/<uuid>.json\n// after\nPUT /directoryignore/groups/<uuid>.json","handlingStrategy":"validation","validationCode":"$allowed = ['Groups', 'Users', 'DirectoryEntries'];\nif (!in_array(ucfirst($model), $allowed, true)) {\n    throw new InvalidArgumentException(\"Unsupported foreignModel '$model'; use one of: \" . implode(', ', $allowed));\n}","typeGuard":"function isSupportedForeignModel(string $m): bool { return in_array($m, ['Groups', 'Users', 'DirectoryEntries'], true); }","tryCatchPattern":"try {\n    $apiClient->put('/directoryignore/' . $model . '/' . $id . '.json');\n} catch (BadRequestException $e) {\n    if ($e->getMessage() === 'The record model is not valid.') {\n        // correct the model segment to Groups|Users|DirectoryEntries\n    }\n}","preventionTips":["Keep the supported model list in a shared constant on both client and route definitions.","Never hand-build URLs with singular/casual model names; validate segments before the call.","Consult DirectoryIgnoreController::normalizeForeignModel for accepted input forms.","Write an integration test covering all three valid model values."],"tags":["validation","api","directory-sync","bad-request"],"backgroundTag":"invalid-enum-value","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"}