-
-
Notifications
You must be signed in to change notification settings - Fork 287
Impove chapter/project leaders presentation #2411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arkid15r
merged 12 commits into
OWASP:main
from
rudransh-shrivastava:feature/leaders-presentation
Oct 12, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4fa213c
add `entity_leaders` node and field
rudransh-shrivastava 89e5fac
refactor and extract Leaders component
rudransh-shrivastava 87afa73
add tests, Coderabbit and Sonar bot suggestions
rudransh-shrivastava 5f4839c
Update code
rudransh-shrivastava e638ef5
sort alphabetically
rudransh-shrivastava c523c7b
use fontawesome icon
rudransh-shrivastava e31ed65
Update docstring
rudransh-shrivastava 218efdb
Update code
rudransh-shrivastava 269daf7
sort alphabetically
rudransh-shrivastava fa340f7
Merge branch 'main' into feature/leaders-presentation
rudransh-shrivastava e468270
Merge branch 'main' into pr/rudransh-shrivastava/2411
arkid15r f7c3fa2
Update code
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """OWASP app entity member GraphQL node.""" | ||
|
|
||
| import strawberry | ||
| import strawberry_django | ||
|
|
||
| from apps.github.api.internal.nodes.user import UserNode | ||
| from apps.owasp.models.entity_member import EntityMember | ||
|
|
||
|
|
||
| @strawberry_django.type( | ||
| EntityMember, | ||
| fields=[ | ||
| "description", | ||
| "is_active", | ||
| "is_reviewed", | ||
| "member_email", | ||
| "member_name", | ||
| "order", | ||
| "role", | ||
| ], | ||
| ) | ||
| class EntityMemberNode(strawberry.relay.Node): | ||
| """Entity member node.""" | ||
|
|
||
| member: UserNode | None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { render, screen, fireEvent } from '@testing-library/react' | ||
| import { mockProjectDetailsData } from '@unit/data/mockProjectDetailsData' | ||
| import { useRouter } from 'next/navigation' | ||
| import Leaders from 'components/Leaders' | ||
|
|
||
| jest.mock('next/navigation', () => ({ | ||
| useRouter: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('components/AnchorTitle', () => ({ | ||
| __esModule: true, | ||
| default: ({ title }: { title: string }) => <span>{title}</span>, | ||
| })) | ||
|
|
||
| jest.mock('wrappers/FontAwesomeIconWrapper', () => ({ | ||
| __esModule: true, | ||
| default: () => <i className="fa" />, | ||
| })) | ||
|
|
||
| describe('Leaders Component', () => { | ||
| const push = jest.fn() | ||
| beforeEach(() => { | ||
| ;(useRouter as jest.Mock).mockReturnValue({ push }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('renders a list of leaders', () => { | ||
| render(<Leaders users={mockProjectDetailsData.project.entityLeaders} />) | ||
|
|
||
| expect(screen.getByText('Leaders')).toBeInTheDocument() | ||
| expect(screen.getByText('Alice')).toBeInTheDocument() | ||
| expect(screen.getByText('Project Leader')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders the section title even with no leaders', () => { | ||
| render(<Leaders users={[]} />) | ||
| expect(screen.getByText('Leaders')).toBeInTheDocument() | ||
| expect(screen.queryByText('Alice')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('navigates to the correct page on button click', () => { | ||
| render(<Leaders users={mockProjectDetailsData.project.entityLeaders} />) | ||
|
|
||
| const viewProfileButton = screen.getByText('View Profile') | ||
| fireEvent.click(viewProfileButton) | ||
|
|
||
| expect(push).toHaveBeenCalledWith('/members/alice') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
LGTM! Verify dataloader usage for optimal performance.
The
memberrelationship field is correctly typed asUserNode | None, matching the nullable foreign key in the EntityMember model. Strawberry Django should automatically resolve this relationship using a dataloader to avoid N+1 queries when fetching multiple leaders.To confirm this optimization is working, verify that the generated GraphQL queries for lists of leaders (e.g., on chapter/project pages) batch the user lookups rather than issuing separate queries per leader.
Run the following script to check if strawberry_django dataloaders are configured in your schema:
🏁 Script executed:
Length of output: 1322
🏁 Script executed:
Length of output: 125
Configure DataLoaderPlugin in the Strawberry Schema
The schema instantiation in backend/settings/graphql.py (around line 43) is currently:
Without the DataLoader plugin, member relationships won’t be batched, leading to N+1 queries. Update it to:
This ensures all FK relations (like
member) are fetched in batches.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this relevant to the current PR objective?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rudransh-shrivastava, you're right to question this—it's not strictly required for the functional PR objective. The leaders block will work and display correctly without the DataLoader plugin configuration.
However, it's a performance consideration: without DataLoaders, when rendering multiple leaders on chapter/project pages, Django will issue separate database queries for each leader's
memberrelationship (the N+1 query problem). This could impact page load times, especially for entities with many leaders.Your options:
backend/settings/graphql.py) to proactively prevent performance issuesWould you like me to create a separate issue to track this performance optimization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arkid15r Hello, is this something we should consider? I assume the actual solution might be a bit more complex since
DataLoaderPluginimport CR suggests, does not exist.DataLoaderexists, but I'm not sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rudransh-shrivastava could you create an issue to look into this later? Thank you!