Skip to content

Fix: preserve profile rights on plugin install/update (GLPI 11) - #398

Open
Rom1-B wants to merge 1 commit into
11.0/bugfixesfrom
fix/profile-rights-reset-on-update
Open

Rom1-B wants to merge 1 commit into
11.0/bugfixesfrom
fix/profile-rights-reset-on-update

Conversation

@Rom1-B

@Rom1-B Rom1-B commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !46505
  • Backport of Fix - Loss of profile rights when updating the plugin #348
  • Profile rights on More Reporting charts were silently reset to "no access" every time the plugin was installed or updated, because the rights-seeding functions overwrote the right of every existing profile/report combination instead of only filling in missing ones.
  • On Cloud Private, periodic reinstalls of the plugin made previously configured rights disappear without any error in the logs.
  • Rights are now preserved across installs and updates; only missing profile/report combinations get created.

Screenshots (if appropriate):

@Rom1-B
Rom1-B requested review from MyvTsv and stonebuzz October 7, 2026 08:48
@Rom1-B
Rom1-B changed the base branch from main to 11.0/bugfixes October 7, 2026 08:50
@Rom1-B Rom1-B changed the title Fix: preserve profile rights on plugin install/update Fix: preserve profile rights on plugin install/update (GLPI 11) Oct 8, 2026

@stonebuzz stonebuzz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

plugin_mreporting_install() calls addRightToAllProfiles() (inserts right = NULL for every profile, super-admin included) before addRightToProfile() (READ for super-admins). Previously the second call overwrote NULL with READ; now it sees the row already exists and skips it. Result: on a fresh install, and for every new report created by createFirstConfig() during an update, super-admin profiles end up with no access. Swapping the two calls restores the intended defaults without touching existing rights.

PluginMreportingProfile::addRightToProfile();
PluginMreportingProfile::addRightToAllProfiles();

Comment thread inc/profile.class.php
// Only create the missing profile/report combinations, never overwrite an existing right
foreach ($profiles_ids as $profile_id) {
foreach ($reports_ids as $report_id) {
$already_exists = $DB->request([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One COUNT query per profile × report pair (N+1), in both methods. With e.g. 40 profiles and 70 reports that is 2800 queries on each install/update, and addRightToProfile() also runs on every profile creation. Fetch existing pairs once and check in memory.

$existing = [];
foreach ($DB->request(['SELECT' => ['profiles_id', 'reports'], 'FROM' => self::getTable()]) as $row) {
    $existing[$row['profiles_id'] . '-' . $row['reports']] = true;
}
// then: if (!isset($existing[$profile_id . '-' . $report_id])) { $DB->insert(...); }

Comment thread inc/profile.class.php
$reports = $config->find();

// Only create the missing profile/report combinations, never overwrite an existing right
foreach ($profiles_ids as $profileId) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The insert-if-missing loop is duplicated verbatim in both methods, only the profile list and the default right differ. A private helper (array $profiles_ids, ?int $right) would remove the duplication.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants