From 9ccdbff27111386cb2ddcf407cfd7266182b1980 Mon Sep 17 00:00:00 2001 From: Pichinov-Jose Date: Thu, 11 Jun 2026 09:33:14 +0200 Subject: [PATCH] New: granular right for AI Assistant usage (#38312) The AI module currently has no declared rights ($this->rights stays empty), so per-user/group attribution of "who is allowed to talk to the LLM" is not possible. Assistant access is gated only by isModEnabled('ai'), meaning any authenticated user on an AI-enabled install can send organisational data to the configured LLM provider -- which is a GDPR / EU AI Act concern (see issue #38331). This patch introduces ONE proper Dolibarr right that admins can attribute per user/group via the standard permission UI (Users -> Permissions): ai/assistant/use -> right to use the AI Assistant page NOT granted by default; admins must explicitly assign it to authorized users Per the feedback from @sonikf and @eldy on PR #38312: - Setup access intentionally stays a hard-coded $user->admin check. The technical setup of the AI module (API keys, provider URLs) is an admin task in line with how every other Dolibarr module is configured -- a dedicated 'ai/setup/write' right would only duplicate responsibility that admins already hold. - ai/assistant/use defaults to OFF (not granted) so that, on a fresh install or after enabling the module, no user can talk to the LLM until the admin explicitly authorises them. This matches the EU AI Act expectation that AI usage is an opt-in per-user decision owned by the GDPR DPO / AI module DPA. Access checks added: - htdocs/ai/assistant/index.php + if (!$user->hasRight('ai','assistant','use')) accessforbidden(); Added after the existing isModEnabled('ai') / AI_MCP_ENABLED gate. - htdocs/ai/assistant/parse_intent.php + if (!$user->hasRight('ai','assistant','use')) accessforbidden(); Defence in depth: the AJAX endpoint that actually talks to the LLM cannot be reached by a user who lacks the right, even via direct call bypassing the Assistant page. - htdocs/ai/admin/setup.php Unchanged behaviour: $user->admin check stays (just a comment clarifying the reason). The right is declared between the existing MODULEBUILDER PERMISSIONS placeholders in modAi.class.php so the standard right-installation flow applies: after applying this change, administrators must disable/re-enable the AI module once to register the new right in llx_rights_def (existing Dolibarr mechanism, no migration script needed). Tested: - Fresh non-admin user (no extra right granted) -> Assistant page shows accessforbidden; parse_intent.php also blocks direct call. - Same user with 'ai/assistant/use' granted by an admin -> Assistant accessible, LLM round-trip works. - Admin user -> Assistant accessible transparently (admins hold every declared right by definition); Setup accessible via the unchanged $user->admin check. - Module disabled -> both still blocked by the existing isModEnabled gate. Refs: #38331 (EU AI Act / GDPR for the AI module). Co-authored-by: Laurent Destailleur --- htdocs/ai/admin/setup.php | 5 +++++ htdocs/ai/assistant/index.php | 7 +++++++ htdocs/ai/assistant/parse_intent.php | 7 +++++++ htdocs/core/modules/modAi.class.php | 21 +++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/htdocs/ai/admin/setup.php b/htdocs/ai/admin/setup.php index 4e3f52bec3c..a9573f676a2 100644 --- a/htdocs/ai/admin/setup.php +++ b/htdocs/ai/admin/setup.php @@ -5,6 +5,7 @@ * Copyright (C) 2024-2025 Frédéric France * Coryright (C) 2024 Alexandre Spangaro * Copyright (C) 2026 Nick Fragoulis + * Copyright (C) 2026 Jose Martinez * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -114,6 +115,10 @@ $setupnotempty = + count($formSetup->items); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); // Access control +// Setup intentionally stays admin-only: per @sonikf and @eldy feedback, +// the AI module's technical setup (API keys, provider configuration) is +// a task done by the admin user, just like for every other Dolibarr module. +// Per-user/group AI usage is gated separately by 'ai/assistant/use'. if (!$user->admin) { accessforbidden(); } diff --git a/htdocs/ai/assistant/index.php b/htdocs/ai/assistant/index.php index 18aaea850bf..25d2b3cca5f 100644 --- a/htdocs/ai/assistant/index.php +++ b/htdocs/ai/assistant/index.php @@ -1,6 +1,7 @@ * Copyright (C) 2026 Nick Fragoulis + * Copyright (C) 2026 Jose Martinez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,6 +38,12 @@ require '../../main.inc.php'; if (!isModEnabled('ai') || !getDolGlobalString('AI_ASSISTANT_ENABLED')) { accessforbidden('Module or feature not allowed'); } +// Per-user gate: the Assistant page is now governed by the standard +// 'ai/assistant/use' right (granted by default to new users), so admins +// can revoke access per user/group via the standard permission UI. +if (!$user->hasRight('ai', 'assistant', 'use')) { + accessforbidden(); +} global $langs; $langs->loadLangs(array("main", "other", "dict")); diff --git a/htdocs/ai/assistant/parse_intent.php b/htdocs/ai/assistant/parse_intent.php index 9c6fe7f9ca5..907329df1c1 100644 --- a/htdocs/ai/assistant/parse_intent.php +++ b/htdocs/ai/assistant/parse_intent.php @@ -1,6 +1,7 @@ * Copyright (C) 2026 Nick Fragoulis + * Copyright (C) 2026 Jose Martinez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,6 +56,12 @@ if (!isModEnabled('ai') || !getDolGlobalString('AI_ASSISTANT_ENABLED')) { global $db, $user, $conf, $langs; +// Same per-user gate as the Assistant page that calls this endpoint, so a +// user without 'ai/assistant/use' cannot reach the LLM through direct AJAX. +if (!$user->hasRight('ai', 'assistant', 'use')) { + accessforbidden(); +} + ob_start(); top_httphead('application/json'); diff --git a/htdocs/core/modules/modAi.class.php b/htdocs/core/modules/modAi.class.php index a47e4b8206f..8506a9c98c1 100644 --- a/htdocs/core/modules/modAi.class.php +++ b/htdocs/core/modules/modAi.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2018-2019 Nicolas ZABOURI * Copyright (C) 2019-2024 Frédéric France * Copyright (C) 2024 MDW + * Copyright (C) 2026 Jose Martinez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -259,6 +260,26 @@ class modAi extends DolibarrModules $r = 0; // Add here entries to declare new permissions /* BEGIN MODULEBUILDER PERMISSIONS */ + // Right to use the AI Assistant chat (read-level access to the AI workflow). + // + // NOT granted by default: per the GDPR / EU AI Act discussion on + // issue #38331 (and feedback by @sonikf and @eldy on this PR), + // AI Assistant usage must be attributed explicitly by an admin to + // the users/groups who are authorized to send organisational data + // to the configured LLM provider. The admin is typically the GDPR + // DPO officer who is also the de-facto DPA for the AI module, and + // owns the per-user authorization decision. + // + // Setup access intentionally remains a hard $user->admin check + // (technical setup, no dedicated right declared) so that the + // API-key configuration of the AI module stays in admin scope, + // in line with how every other Dolibarr module is configured. + $this->rights[$r][0] = $this->numero + 1; + $this->rights[$r][1] = 'Use the AI Assistant'; + $this->rights[$r][3] = 0; // default: NOT granted + $this->rights[$r][4] = 'assistant'; + $this->rights[$r][5] = 'use'; + $r++; /* END MODULEBUILDER PERMISSIONS */ // Main menu entries to add