Skip to content

Conversation

@vikrantgravitee
Copy link
Contributor

@vikrantgravitee vikrantgravitee commented Nov 2, 2025

Issue

https://gravitee.atlassian.net/browse/APIM-10981

Description

The UserResource.getUserGroups endpoint now correctly filters groups by environment when the 'q' query parameter is provided with valid environmentId.
Sample:
management/organizations/{orgID}/users/{userID}/groups?q={envID} => filters data based on envID
management/organizations/{orgID}/users/{userID}/groups => provides full list of groups for the user

The issue was that old API is already deprecated GET management/organizations/{orgId}/environments/{envId}/users/{userId}/groups but if user wants to filter data based on the envId then there was no option to do so.

Changes:

  • Added GroupService.findByUserAndEnvironment method to filter groups by environment ID
  • Implemented environment-based filtering logic in GroupServiceImpl
  • Updated UserResource to call findByUserAndEnvironment with environment id when provided in query param.
  • Added comprehensive test coverage.

Previously, the endpoint returned all organization groups and no option was available for end user to filter data based on environment id.

Screen.Recording.2025-11-02.at.12.19.35.PM.mov

Updated fix with QUERY PARAM:

Screen.Recording.2025-11-11.at.9.59.02.PM.mov

Additional context

@vikrantgravitee vikrantgravitee requested a review from a team as a code owner November 2, 2025 06:52
@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch from a48b71b to 3ac9b1d Compare November 2, 2025 06:52
@gemini-code-assist
Copy link

Summary of Changes

Hello @vikrantgravitee, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical bug in the user group retrieval API. Previously, when requesting user groups for a specific environment, the system erroneously returned all groups associated with the user across the entire organization. The changes introduce a new service method and update the API endpoint to correctly filter these groups by the provided environment ID, ensuring that only groups relevant to the specified environment are returned. This enhances data accuracy and adheres to the intended scope of the API.

Highlights

  • Environment Scope Fix: Corrected an issue where the GET management/organizations/{orgId}/environments/{envId}/users/{userId}/groups endpoint was returning all groups across the organization instead of respecting the specified environment scope.
  • New Service Method: Introduced GroupService.findByUserAndEnvironment to enable filtering of user groups by environment ID.
  • Implementation of Filtering Logic: Added environment-based filtering logic within GroupServiceImpl to process and return only relevant groups.
  • API Endpoint Update: Updated UserResource to utilize the new findByUserAndEnvironment method, ensuring the correct environment context is applied.
  • Comprehensive Test Coverage: Included a new test class, GroupService_FindByUserAndEnvironmentTest, with various scenarios to validate the new filtering functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where user groups were not being filtered by environment. The approach of adding a new service method findByUserAndEnvironment and using it in the UserResource is sound. The new logic is also well-tested. I've added a few suggestions to improve code cleanliness and adherence to best practices.

@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch 2 times, most recently from 455ab68 to 8d22add Compare November 2, 2025 06:54
@phiz71
Copy link
Member

phiz71 commented Nov 4, 2025

⚠️ management/organizations/{orgId}/environments/{envId}/users/xxxx is deprecated
See this

A user is attached to an organization. We should use management/organizations/{orgId}/users/{userId}/groups instead to list the groups of a given user.

What is the use case you are trying to fix here ?

@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch 3 times, most recently from dd8e5b6 to 3eb1fe5 Compare November 11, 2025 16:31
@vikrantgravitee vikrantgravitee changed the title fix: respect env scope when fetching user groups with envId fix: filter user groups by env scope in query parameter Nov 11, 2025
@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch from 3eb1fe5 to c0548b8 Compare November 11, 2025 16:44
@vikrantgravitee
Copy link
Contributor Author

⚠️ management/organizations/{orgId}/environments/{envId}/users/xxxx is deprecated See this

A user is attached to an organization. We should use management/organizations/{orgId}/users/{userId}/groups instead to list the groups of a given user.

What is the use case you are trying to fix here ?

Thank you @phiz71 for pointing it out and for the right suggestion.
As discussed, I’ve updated the org-level API to include a query parameter for filtering user groups.

Use case:
The customer wants to filter groups assigned to a user based on the environment.

@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch 4 times, most recently from 2a10d6a to febbb65 Compare November 13, 2025 05:06
@vikrantgravitee
Copy link
Contributor Author

New test after new code changes per suggestion:

Screen.Recording.2025-11-13.at.10.37.00.AM.mov

@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch from febbb65 to f3ab813 Compare November 13, 2025 09:16
@vikrantgravitee vikrantgravitee force-pushed the APIM-10981-fix-filter-user-groups-by-environment branch from f3ab813 to 6ad4afe Compare November 13, 2025 09:16
@vikrantgravitee vikrantgravitee merged commit 063a99d into 4.8.x Nov 13, 2025
20 checks passed
@vikrantgravitee vikrantgravitee deleted the APIM-10981-fix-filter-user-groups-by-environment branch November 13, 2025 13:10
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.

3 participants