Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- CI: fix Psalm cache directory, drop the stray `glpi-project/tools` composer dependency, declare a unique composer autoloader suffix
- Profile rights to reports are no longer reset to "no access" each time the plugin is installed or updated

## [1.10.3] - 2026-09-28

Expand Down
80 changes: 46 additions & 34 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,34 @@ public static function addRightToAllProfiles()
/** @var DBmysql $DB */
global $DB;

$query_config = [
'SELECT' => 'id',
'FROM' => PluginMreportingConfig::getTable(),
];

$query_profil = [
'SELECT' => 'id',
'FROM' => Profile::getTable(),
];
$profiles_ids = array_column(
iterator_to_array($DB->request(['SELECT' => 'id', 'FROM' => Profile::getTable()])),
'id',
);
$reports_ids = array_column(
iterator_to_array($DB->request(['SELECT' => 'id', 'FROM' => PluginMreportingConfig::getTable()])),
'id',
);

$result_config = $DB->request($query_config);
foreach ($DB->request($query_profil) as $prof) {
foreach ($result_config as $report) {
$DB->updateOrInsert('glpi_plugin_mreporting_profiles', [
'profiles_id' => $prof['id'],
'reports' => $report['id'],
'right' => null,
], [
'profiles_id' => $prof['id'],
'reports' => $report['id'],
]);
// 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([
'COUNT' => 'cpt',
'FROM' => self::getTable(),
'WHERE' => [
'profiles_id' => $profile_id,
'reports' => $report_id,
],
])->current()['cpt'] > 0;

if (!$already_exists) {
$DB->insert(self::getTable(), [
'profiles_id' => $profile_id,
'reports' => $report_id,
'right' => null,
]);
}
}
}
}
Expand Down Expand Up @@ -209,26 +216,31 @@ public static function addRightToProfile(?int $idProfile = null): void
/** @var DBmysql $DB */
global $DB;

$profiles_ids = [];
$profiles_ids = is_null($idProfile) ? Profile::getSuperAdminProfilesId() : [$idProfile];
$reports_ids = array_column(
iterator_to_array($DB->request(['SELECT' => 'id', 'FROM' => PluginMreportingConfig::getTable()])),
'id',
);

$config = new PluginMreportingConfig();
$reports = $config->find();

// Only create the missing profile/report combinations, never overwrite an existing right
foreach ($profiles_ids as $profileId) {
foreach ($reports as $report) {
$DB->updateOrInsert(
'glpi_plugin_mreporting_profiles',
[
foreach ($reports_ids as $report_id) {
$already_exists = $DB->request([
'COUNT' => 'cpt',
'FROM' => self::getTable(),
'WHERE' => [
'profiles_id' => $profileId,
'reports' => $report['id'],
'right' => READ,
'reports' => $report_id,
],
[
])->current()['cpt'] > 0;

if (!$already_exists) {
$DB->insert(self::getTable(), [
'profiles_id' => $profileId,
'reports' => $report['id'],
],
);
'reports' => $report_id,
'right' => READ,
]);
}
}
}
}
Expand Down
Loading