Skip to content

feat: Added API and UI for Eligible Roles Relationship Type in entity panel - BED-7309#2458

Open
specter-flq wants to merge 4 commits intomainfrom
BED-7309--eligible-roles-accordion
Open

feat: Added API and UI for Eligible Roles Relationship Type in entity panel - BED-7309#2458
specter-flq wants to merge 4 commits intomainfrom
BED-7309--eligible-roles-accordion

Conversation

@specter-flq
Copy link
Contributor

@specter-flq specter-flq commented Mar 4, 2026

Description

Motivation and Context

Resolves: BED-7309

How Has This Been Tested?

Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Database Migrations

Checklist:

Summary by CodeRabbit

  • New Features
    • Added "Eligible Roles" display sections for Azure groups and users in the UI, enabling visibility of eligible role relationships
    • Introduced new API endpoints to query and retrieve eligible roles for Azure entities

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

This PR adds support for querying eligible roles for Azure entities (groups and users) by introducing new query functions, database operations, filters, constants, API endpoints, and UI sections across the Go backend and JavaScript frontend. The eligible roles functionality mirrors existing role-lookup patterns and expands Azure analysis capabilities.

Changes

Cohort / File(s) Summary
Azure Analysis Module
packages/go/analysis/azure/model.go, packages/go/analysis/azure/filters.go, packages/go/analysis/azure/queries.go, packages/go/analysis/azure/db_ops.go
Added eligible roles support: constant RelatedEntityTypeEligibleRoles, filter function FilterEntityEligibleRoles() for AZRoleEligible and AZRoleApprover relationships, and four new query/database functions (FetchEntityEligibleRolePaths, FetchEntityEligibleRoles, ListEntityEligibleRolePaths, ListEntityEligibleRoles) following existing traversal and pagination patterns.
Azure API Handler
cmd/api/src/api/v2/azure.go
Extended API v2 to handle RelatedEntityTypeEligibleRoles by adding graphRelatedEntityType case that calls ListEntityEligibleRolePaths() and listRelatedEntityType case that calls ListEntityEligibleRoles() with 0/0 pagination.
Frontend UI Configuration
packages/javascript/bh-shared-ui/src/utils/content.ts
Added "Eligible Roles" sections to allSections for AzureGroup and AzureUser, and introduced two new endpoints in entityRelationshipEndpoints: azgroup-eligible-roles and azuser-eligible-roles for fetching eligible roles via GET groups/{id}/eligible-roles and GET users/{id}/eligible-roles.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the critical 'Description' section that should detail the changes made, and the 'How Has This Been Tested?' section is incomplete with only placeholder text. Complete the Description section explaining the changes, and provide specific details about testing methodology, test cases, and environment setup used to validate the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding API and UI support for Eligible Roles relationship type, with a reference to the associated ticket BED-7309.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BED-7309--eligible-roles-accordion

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@specter-flq specter-flq changed the title Feat: Added API and UI for Eligible Roles Relationship Type in entity panel Feat: Added API and UI for Eligible Roles Relationship Type in entity panel - BED-7309 Mar 4, 2026
@specter-flq specter-flq self-assigned this Mar 5, 2026
@specter-flq specter-flq changed the title Feat: Added API and UI for Eligible Roles Relationship Type in entity panel - BED-7309 feat: Added API and UI for Eligible Roles Relationship Type in entity panel - BED-7309 Mar 5, 2026
@specter-flq specter-flq added api A pull request containing changes affecting the API code. user interface A pull request containing changes affecting the UI code. labels Mar 9, 2026
@specter-flq specter-flq marked this pull request as ready for review March 9, 2026 18:55
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/go/analysis/azure/filters.go`:
- Around line 41-42: The FilterEntityEligibleRoles function currently includes
both azure.AZRoleEligible and azure.AZRoleApprover in its KindIn criteria;
remove azure.AZRoleApprover so the filter only matches azure.AZRoleEligible.
Update the function FilterEntityEligibleRoles to use
query.KindIn(query.Relationship(), azure.AZRoleEligible) (leave AZRoleApprover
out) so the “Eligible Roles” flow no longer returns roles based on approver
edges.

In `@packages/go/analysis/azure/queries.go`:
- Around line 263-281: The current eligible-role traversals
(FetchEntityEligibleRolePaths and FetchEntityEligibleRoles) only follow direct
eligible-role edges and must mirror the inheritance logic used by
fetchRolesTraversalPlan: update their ops.TraversalPlan to include the
AZMemberOf branch (or otherwise traverse member-of edges) and apply the same
roleDescentFilter used in the active-role traversal so that role-assignable
group inheritance is followed; specifically, adjust the BranchQuery and
PathFilter fields (or add an intermediate branch) to combine
FilterEntityEligibleRoles with AZMemberOf and ensure roleDescentFilter is
applied to path segments just like in fetchRolesTraversalPlan.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 3fd19dc0-548a-4642-92c0-5c837702af5a

📥 Commits

Reviewing files that changed from the base of the PR and between 582cf0a and 519e5f3.

📒 Files selected for processing (6)
  • cmd/api/src/api/v2/azure.go
  • packages/go/analysis/azure/db_ops.go
  • packages/go/analysis/azure/filters.go
  • packages/go/analysis/azure/model.go
  • packages/go/analysis/azure/queries.go
  • packages/javascript/bh-shared-ui/src/utils/content.ts

Comment on lines +41 to +42
func FilterEntityEligibleRoles() graph.Criteria {
return query.KindIn(query.Relationship(), azure.AZRoleEligible, azure.AZRoleApprover)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep approver edges out of the eligible-roles filter.

AZRoleApprover already backs the separate role-approver flow, so including it here makes eligible-roles return roles an entity can approve even when it is not actually eligible for them. That will populate the new “Eligible Roles” table with the wrong relationship type.

Suggested fix
 func FilterEntityEligibleRoles() graph.Criteria {
-	return query.KindIn(query.Relationship(), azure.AZRoleEligible, azure.AZRoleApprover)
+	return query.Kind(query.Relationship(), azure.AZRoleEligible)
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func FilterEntityEligibleRoles() graph.Criteria {
return query.KindIn(query.Relationship(), azure.AZRoleEligible, azure.AZRoleApprover)
func FilterEntityEligibleRoles() graph.Criteria {
return query.Kind(query.Relationship(), azure.AZRoleEligible)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/go/analysis/azure/filters.go` around lines 41 - 42, The
FilterEntityEligibleRoles function currently includes both azure.AZRoleEligible
and azure.AZRoleApprover in its KindIn criteria; remove azure.AZRoleApprover so
the filter only matches azure.AZRoleEligible. Update the function
FilterEntityEligibleRoles to use query.KindIn(query.Relationship(),
azure.AZRoleEligible) (leave AZRoleApprover out) so the “Eligible Roles” flow no
longer returns roles based on approver edges.

Comment on lines +263 to +281
func FetchEntityEligibleRolePaths(tx graph.Transaction, node *graph.Node) (graph.PathSet, error) {
return ops.TraversePaths(tx, ops.TraversalPlan{
Root: node,
Direction: graph.DirectionOutbound,
BranchQuery: FilterEntityEligibleRoles,
PathFilter: func(ctx *ops.TraversalContext, segment *graph.PathSegment) bool {
return segment.Node.Kinds.ContainsOneOf(azure.Role)
},
})
}

func FetchEntityEligibleRoles(tx graph.Transaction, node *graph.Node, skip, limit int) (graph.NodeSet, error) {
return ops.AcyclicTraverseTerminals(tx, ops.TraversalPlan{
Root: node,
Direction: graph.DirectionOutbound,
Skip: skip,
Limit: limit,
BranchQuery: FilterEntityEligibleRoles,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Mirror the existing role-inheritance traversal here.

These traversals only follow direct eligible-role edges, so users who inherit eligibility through a role-assignable group will be omitted from both the list and graph endpoints. fetchRolesTraversalPlan already handles the analogous active-role case via AZMemberOf plus roleDescentFilter; the eligible-role path should apply the same inheritance rules.

Suggested direction
+func fetchEligibleRolesTraversalPlan(root *graph.Node, skip, limit int) ops.TraversalPlan {
+	return ops.TraversalPlan{
+		Root:      root,
+		Direction: graph.DirectionOutbound,
+		Skip:      skip,
+		Limit:     limit,
+		BranchQuery: func() graph.Criteria {
+			return query.KindIn(query.Relationship(), azure.MemberOf, azure.AZRoleEligible)
+		},
+		DescentFilter: roleDescentFilter,
+		PathFilter: func(_ *ops.TraversalContext, segment *graph.PathSegment) bool {
+			return segment.Node.Kinds.ContainsOneOf(azure.Role)
+		},
+	}
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/go/analysis/azure/queries.go` around lines 263 - 281, The current
eligible-role traversals (FetchEntityEligibleRolePaths and
FetchEntityEligibleRoles) only follow direct eligible-role edges and must mirror
the inheritance logic used by fetchRolesTraversalPlan: update their
ops.TraversalPlan to include the AZMemberOf branch (or otherwise traverse
member-of edges) and apply the same roleDescentFilter used in the active-role
traversal so that role-assignable group inheritance is followed; specifically,
adjust the BranchQuery and PathFilter fields (or add an intermediate branch) to
combine FilterEntityEligibleRoles with AZMemberOf and ensure roleDescentFilter
is applied to path segments just like in fetchRolesTraversalPlan.

@specter-flq specter-flq requested review from maffkipp and urangel March 9, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A pull request containing changes affecting the API code. user interface A pull request containing changes affecting the UI code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant