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 <eldy@destailleur.fr>
This commit is contained in:
Pichinov-Jose 2026-06-11 09:33:14 +02:00 committed by GitHub
parent 410a07f628
commit 9ccdbff271
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 0 deletions

View file

@ -5,6 +5,7 @@
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Coryright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2026 Nick Fragoulis
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
*
* 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();
}

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2026 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2026 Nick Fragoulis
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
*
* 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"));

View file

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2026 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2026 Nick Fragoulis
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
*
* 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');

View file

@ -3,6 +3,7 @@
* Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
*
* 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