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