Skip to content

Manage dashboard access rights per Group and per User - #144

Open
MichaelRodriguesOficial wants to merge 11 commits into
pluginsGLPI:mainfrom
MichaelRodriguesOficial:main
Open

MichaelRodriguesOficial wants to merge 11 commits into
pluginsGLPI:mainfrom
MichaelRodriguesOficial:main

Conversation

@MichaelRodriguesOficial

@MichaelRodriguesOficial MichaelRodriguesOficial commented Jul 13, 2026 •

Copy link
Copy Markdown

Update to better manage access to the dashboards.

Checklist before requesting a review

  • 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

Currently, dashboard access can only be granted per Profile. This PR adds the ability to also grant access per Group and per User, using the same rights mechanism already used for profiles.

  • Adds a new PluginMetabaseItemright class, mirroring PluginMetabaseProfileright, storing rights keyed by itemtype (Group or User) + items_id + dashboard_id.
  • Adds a new "Metabase" tab on the Group and User forms. READ on the group/user shows the tab and the rights matrix, UPDATE is required to change anything (Save and "Allow/Disallow access to all"), same as PluginMetabaseProfileright. The rights are checked on the targeted group/user itself, both when displaying the tab and when saving.
  • Rights are additive (OR): a dashboard is shown on Central if the user's profile, any of their groups, or the user themselves has been granted READ. A "No access" value on a group or user only means "no right granted there", it does not override access granted through another source.
  • User and group rights are resolved once for all dashboards (a single query) instead of once per dashboard on the Central page.
  • Dashboard ids submitted when saving are checked against the dashboards that really exist in Metabase.
  • Rights are cleaned when a group or user is purged.
  • No changes to the existing profile-based rights: they keep working exactly as before, this is purely additive.

I did not add automated tests since the plugin doesn't currently have a test suite in place. I tested manually against GLPI 12.0.1 (plugin install/activate, tab and form permissions with READ only vs READ+UPDATE, Central visibility with profile / group / user rights, and that the batched resolution gives the same result as the previous per-dashboard check). PHP-CS-Fixer and PHPStan report nothing on the changed files.

Screenshots:

Group User

Update to better manage access to the dashboards.
@stonebuzz
stonebuzz requested review from Rom1-B and stonebuzz July 17, 2026 07:28
@stonebuzz stonebuzz assigned stonebuzz and unassigned stonebuzz Jul 17, 2026
@stonebuzz stonebuzz added the enhancement New feature or request label Jul 17, 2026
Comment thread inc/itemright.class.php Resolved
Comment thread inc/itemright.class.php Resolved
Comment thread inc/dashboard.class.php Resolved
Comment thread inc/dashboard.class.php Resolved
Comment thread inc/itemright.class.php Resolved
Comment thread inc/itemright.class.php Resolved
Comment thread inc/itemright.class.php Resolved
MichaelRodriguesOficial and others added 4 commits July 23, 2026 17:42
Co-authored-by: Stanislas <skita@teclib.com>
Co-authored-by: Stanislas <skita@teclib.com>
Co-authored-by: Stanislas <skita@teclib.com>
Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com>

@Rom1-B Rom1-B 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.

Several errors in the CI

Comment thread inc/itemright.class.php Resolved
@MichaelRodriguesOficial
MichaelRodriguesOficial marked this pull request as draft September 1, 2026 21:38
@MichaelRodriguesOficial
MichaelRodriguesOficial marked this pull request as ready for review September 2, 2026 16:14
@MichaelRodriguesOficial
MichaelRodriguesOficial marked this pull request as draft September 2, 2026 16:24
@MichaelRodriguesOficial
MichaelRodriguesOficial marked this pull request as ready for review September 2, 2026 18:24

@Rom1-B Rom1-B 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.

Please correct the CI issues before requesting another review.

Michael Rodrigues and others added 2 commits October 16, 2026 14:36
- Fix PHP syntax error introduced by the docblock suggestion in itemright.class.php
- Render the rights matrix with a Twig template (no more echo)
- READ on the group/user is enough to see the tab, UPDATE is required to save
- Check rights on the targeted group/user itself, not only the global right
- Rename dashboard_uuid column to dashboard_id
- Add int type hint and docblock on canCurrentUserViewDashboard()
- Remove rights when a group or user is purged
- Rebase on GLPI 12 / 1.5.0 and add CHANGELOG entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115rGXdmY7mffoJzXeFPGhw
@MichaelRodriguesOficial

Copy link
Copy Markdown
Author

Thanks for the reviews, and sorry for the noise — the CI failures came from a suggestion I applied
through the web UI that broke a docblock and caused a PHP syntax error. On top of that, my previous
rework had been pushed to another branch, not to the one this PR uses.

This is now fixed and rebased on 1.5.0 / GLPI 12:

  • Rights matrix rendered with a Twig template (no more echo)
  • READ on the group/user shows the tab, UPDATE is required to save (same as Profileright);
    rights are checked on the targeted item itself
  • dashboard_uuid renamed to dashboard_id
  • int type hint + docblock on canCurrentUserViewDashboard() as suggested
  • Rights are cleaned when a group/user is purged
  • CHANGELOG entry added

Lint, PHP-CS-Fixer, PHPStan, Psalm, Rector, TwigCS and licence headers pass locally against GLPI 12,
as well as plugin install/uninstall.

…n item rights form

- showForCentral(): resolve user and group rights once for all dashboards
  instead of once per dashboard inside the array_filter loop
- tab visibility now uses the same per-item READ check as the tab content
- ignore dashboard ids that do not exist in Metabase when saving rights
- README: mention group and user rights management
@MichaelRodriguesOficial

Copy link
Copy Markdown
Author

Since the last review I pushed 979d2f3 (plus a merge of the current main, which only brings the organization workflow files):

  • Query count on Central (@Rom1-B's comment on the per-dashboard user/group lookups): user and group rights are now resolved once for all dashboards with a single query (PluginMetabaseItemright::getViewableDashboardIds()), called before the array_filter() in showForCentral(), instead of once per dashboard. Profile rights keep the existing check.
  • Tab gating: getTabNameForItem() now uses the same per-item READ check as the tab content ($item->can($id, READ)), so the tab is not shown for a group/user the current user cannot read.
  • Saving rights: dashboard ids posted to front/itemright.form.php are checked against the dashboards that exist in Metabase before being stored or used to enable embedding.
  • dashboard_id (@stonebuzz): the column is now dashboard_id in the new table; PluginMetabaseProfileright keeps its existing dashboard_uuid column, which I left untouched to keep this PR purely additive.
  • README updated to mention group and user rights.

I tested it manually against GLPI 12.0.1: plugin install/activate, tab and form permissions with READ only vs READ + UPDATE (a READ-only user gets a 403 on save and nothing is changed), Central visibility with profile, group and user rights, and that the batched resolution gives the same result as the previous per-dashboard check. PHP-CS-Fixer and PHPStan report nothing on the changed files.

Could a maintainer approve the CI workflow run? Then I'll fix anything it reports before asking for another review. Thanks!

@Rom1-B Rom1-B 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.

No tests yet; fine given the plugin has no suite, but a small one covering getViewableDashboardIds() would be welcome.

Comment thread inc/dashboard.class.php
*
* @return bool
*/
public static function canCurrentUserViewDashboard(int $dashboardId): bool

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.

Nothing calls canCurrentUserViewDashboard() anymore, nor PluginMetabaseItemright::canItemsViewDashboard() besides it. Can you drop both?

Comment thread front/itemright.form.php
}

// UPDATE right on the targeted group / user is required to change its dashboard rights.
$item->check($items_id, UPDATE);

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.

With default profiles, a Technician has user UPDATE and can grant themselves every dashboard. Editing should also require the right that guards profile-based dashboard rights (also set can_update accordingly in showForItem()).

Suggested change
$item->check($items_id, UPDATE);
$item->check($items_id, UPDATE);
Session::checkRight(Profile::$rightname, UPDATE);

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants