Skip to content

[16.0][FIX] ai_tool: resolve tool model metadata with sudo - #94

Open
nobuQuartile wants to merge 1 commit into
OCA:16.0from
qrtl:16.0-fix-ai_tool-1
Open

[16.0][FIX] ai_tool: resolve tool model metadata with sudo#94
nobuQuartile wants to merge 1 commit into
OCA:16.0from
qrtl:16.0-fix-ai_tool-1

Conversation

@nobuQuartile

@nobuQuartile nobuQuartile commented Jul 21, 2026

Copy link
Copy Markdown

Problem

When a tool is listed or executed on behalf of a non-admin user (a plain
base.group_user internal user), the operation fails with:

You are not allowed to access 'Models' (ir.model) records.
This operation is allowed for the following groups:
    - Administration/Access Rights

AiTool._get_tool_definition and AiTool._execute_tool dereference
self.model_id.model, which reads the ir.model record. Reading ir.model
requires the Administration / Access Rights group, so any flow that runs as
a regular internal user (e.g. ai_oca_mcp keys owned by a non-admin user, where
the controller runs with_user(key.user_id)) is rejected before it can list or
call any tool.

Fix

Resolving which model/function a tool maps to is metadata, not user data.
Read the model name via sudo(), while keeping the actual tool execution under
the caller's own permissions (self.env[model] / record). Access control on
the real data operation is therefore unchanged; only the metadata lookup and
dispatch are allowed to proceed for non-admin users.

@qrtl

@nobuQuartile
nobuQuartile marked this pull request as draft July 21, 2026 00:35
@nobuQuartile
nobuQuartile force-pushed the 16.0-fix-ai_tool-1 branch 2 times, most recently from 054c400 to 501267b Compare July 21, 2026 00:50
Building and dispatching a tool reads ir.model via model_id, which a
plain internal user (base.group_user) cannot access. Resolve the model
name with sudo() while keeping the actual tool execution under the
caller's own permissions, so non-admin MCP keys can list and call tools.

Add a regression test exercising a non-admin user through
_get_tool_definition and _execute_tool.
@nobuQuartile
nobuQuartile marked this pull request as ready for review July 21, 2026 00:54

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: LG

@angelmoya angelmoya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants