Skip to content

feat: add API for automatic main menu - #19202

Merged
mshabarov merged 16 commits into
mainfrom
feat/19127-get-and-control-accessible-menu-routes
Apr 23, 2024
Merged

mshabarov merged 16 commits into
mainfrom
feat/19127-get-and-control-accessible-menu-routes

Conversation

@tltv

@tltv tltv commented Apr 18, 2024

Copy link
Copy Markdown
Contributor

Adds API to get and control only accessible routes for automatically build routes based on Menu annotated routes. This change is targeting primarily client side menu build with Hilla.

Adds RouteRegistry#getRegisteredAccessibleMenuRoutes to get a list of accessible RouteData objects. Method takes in a collection of access control objects which are implementing BeforeEnterListener. Supports NavigationAccessControl and ViewAccessChecker.

Adds MenuAccessControl interface to control getRegisteredAccessibleMenuRoutes return value. This change adds first part of control by adding API to enable, disable or automate populating client side main menu with the server side routes. Interface has space for future for more advanced control.

Default MenuAccessControl implementation can be customized by implementing it as a Spring bean, or by providing the implementation class via 'menu.access.control' property.

Fixes: #19127

@github-actions

github-actions Bot commented Apr 18, 2024 •

Copy link
Copy Markdown
Contributor

Test Results

1 097 files  + 2  1 097 suites  +2   1h 23m 24s ⏱️ -59s
6 977 tests +28  6 927 ✅ +28  50 💤 +1  0 ❌ ±0 
7 352 runs  +32  7 290 ✅ +32  62 💤 +1  0 ❌ ±0 

Results for commit 205b6d1. ± Comparison against base commit 6a0f1c6.

This pull request skips 1 test.
com.vaadin.flow.uitest.ui.webcomponent.PaperInputIT ‑ paperInputIsFunctional[any_Chrome_]

♻️ This comment has been updated with latest results.

@tltv
tltv marked this pull request as ready for review April 18, 2024 08:17
taefi
taefi previously requested changes Apr 18, 2024

@taefi taefi 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.

I added my review again, based on my understanding from the enhancement issue, and the usage of the newly introduced API getRegisteredAccessibleMenuRoutes in the vaadin/hilla#2338. Please feel free to discard, if my understanding of the issue is not correct.

@mshabarov

Copy link
Copy Markdown
Contributor

I tried to test this change along with the counterpart on Hilla side using this branch and noticed that this check returns false in getRegisteredAccessibleMenuRoutes method and the reason is that access is denied by annotation.

accessControl.checkAccess(navigationContext, true)
                            .decision() == AccessCheckDecision.ALLOW;

Flow view has an annotation, but probably something is misconfigured. I'm debugging it.

mshabarov
mshabarov previously approved these changes Apr 22, 2024

@mshabarov mshabarov 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.

Don't know what was a problem last time I tested, but now, in a second try, it works as expected, so once I have a AtMenu, menu item appears in the list, once I remove it - it disappears.

Approved, so we can merge it to main, if no big objections.

tltv added 13 commits April 22, 2024 18:19
Adds API to get and control only accessible routes for automatically build routes based on `Menu` annotated routes. This change is targeting primarily client side menu build with Hilla.

Adds `RouteRegistry#getRegisteredAccessibleMenuRoutes` to get a list of accessible RouteData objects. Method takes in a collection of access control objects which are implementing `BeforeEnterListener`. Supports `NavigationAccessControl` and `ViewAccessChecker`.

Adds `MenuAccessControl` interface to control `getRegisteredAccessibleMenuRoutes` return value. This change adds first part of control by adding API to enable, disable or automate populating client side main menu with the server side routes. Interface has space for future for more advanced control.

Default `MenuAccessControl` implementation can be customized by implementing it as a Spring bean, or by providing the implementation class via 'menu.access.control' property.

Fixes: #19127
No routes should be returned when having PopulateClientMenu.NEVER or PopulateClientMenu.AUTOMATIC + no client menu in use.
@tltv
tltv force-pushed the feat/19127-get-and-control-accessible-menu-routes branch from 7a7d720 to 9de2077 Compare April 22, 2024 15:20
mshabarov
mshabarov previously approved these changes Apr 23, 2024
@mshabarov

Copy link
Copy Markdown
Contributor

One comment from my side is that this feature misses a way to change the mode via config param, e.g. vaadin.menu.access.control=ALWAYS, one can only create a new bean or give a full class name as a value.
I propose to add it later to not block this feature.

Ignoring a single TestBench test due to inconsistent failures. Test isn't related to other changes.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@mshabarov
mshabarov dismissed taefi’s stale review April 23, 2024 06:25

All the comments seem to be addressed, let's discuss later if something isn't clear enough

@mshabarov
mshabarov merged commit 4a6ca45 into main Apr 23, 2024
@mshabarov
mshabarov deleted the feat/19127-get-and-control-accessible-menu-routes branch April 23, 2024 06:39
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.4.0.alpha24 and is also targeting the upcoming stable 24.4.0 version.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow customizing how Flow views are included in the automatic main menu

8 participants