-
-
Notifications
You must be signed in to change notification settings - Fork 647
Feature/improve module management ux #5059
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
base: main
Are you sure you want to change the base?
Changes from all commits
c46fa14
12b0464
bdf299b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,14 @@ | |
| import logging | ||
|
|
||
| import strawberry | ||
| from django.db.models import Q | ||
| from django.db.models import Prefetch, Q | ||
|
|
||
| from apps.mentorship.api.internal.graphql_errors import ( | ||
| AuthenticationRequiredError, | ||
| ManagementProgramAccessDeniedError, | ||
| ) | ||
| from apps.mentorship.api.internal.nodes.module import ModuleNode | ||
| from apps.mentorship.models import Module, Program | ||
| from apps.mentorship.models import Mentor, Module, Program | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -35,7 +35,14 @@ def get_program_modules(self, info: strawberry.Info, program_key: str) -> list[M | |
| return ( | ||
| Module.objects.filter(program=program) | ||
| .select_related("program", "project") | ||
| .prefetch_related("mentors__github_user") | ||
| .prefetch_related( | ||
| Prefetch( | ||
| "mentors", | ||
| queryset=Mentor.objects.select_related("github_user").order_by( | ||
| "github_user__login" | ||
|
Comment on lines
+41
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Look for any normalization of GitHub logins before persistence.
rg -n -C2 --type=py 'lower\(|casefold\(|github_user.*login|login.*github_user' backend frontend
# Check whether resolver/tests already cover mixed-case mentor ordering.
rg -n -C2 --type=py 'github_user__login|Lower\("github_user__login"\)|mentors.*order' backend
rg -n -C2 --glob '*test*.py' --glob '*test*.tsx' 'alice|Alice|zed|Zed|mentor.*order|github.*username' backend frontendRepository: OWASP/Nest Length of output: 50367 Ensure deterministic, case-insensitive mentor ordering.
Use Code fixfrom django.db.models.functions import Lower
# ...
queryset=Mentor.objects.select_related("github_user").order_by(
Lower("github_user__login")
)
# ...This applies to all occurrences in 🤖 Prompt for AI Agents |
||
| ), | ||
| ) | ||
| ) | ||
| .order_by("order", "started_at") | ||
| ) | ||
|
|
||
|
|
@@ -66,7 +73,14 @@ def get_management_program_modules( | |
|
|
||
| return ( | ||
| modules.select_related("program", "project") | ||
| .prefetch_related("mentors__github_user") | ||
| .prefetch_related( | ||
| Prefetch( | ||
| "mentors", | ||
| queryset=Mentor.objects.select_related("github_user").order_by( | ||
| "github_user__login" | ||
| ), | ||
| ) | ||
| ) | ||
| .distinct() | ||
| .order_by("order", "started_at") | ||
| ) | ||
|
|
@@ -77,7 +91,14 @@ def get_project_modules(self, project_key: str) -> list[ModuleNode]: | |
| return ( | ||
| Module.objects.filter(project__key=project_key) | ||
| .select_related("program", "project") | ||
| .prefetch_related("mentors__github_user") | ||
| .prefetch_related( | ||
| Prefetch( | ||
| "mentors", | ||
| queryset=Mentor.objects.select_related("github_user").order_by( | ||
| "github_user__login" | ||
| ), | ||
| ) | ||
| ) | ||
| .order_by("order", "started_at") | ||
| ) | ||
|
|
||
|
|
@@ -89,7 +110,14 @@ def get_module( | |
| try: | ||
| module = ( | ||
| Module.objects.select_related("program", "project") | ||
| .prefetch_related("mentors__github_user") | ||
| .prefetch_related( | ||
| Prefetch( | ||
| "mentors", | ||
| queryset=Mentor.objects.select_related("github_user").order_by( | ||
| "github_user__login" | ||
| ), | ||
| ) | ||
| ) | ||
| .get(key=module_key, program__key=program_key) | ||
| ) | ||
| except Module.DoesNotExist: | ||
|
|
@@ -116,7 +144,14 @@ def get_management_module( | |
| try: | ||
| module = ( | ||
| Module.objects.select_related("program", "project") | ||
| .prefetch_related("mentors__github_user") | ||
| .prefetch_related( | ||
| Prefetch( | ||
| "mentors", | ||
| queryset=Mentor.objects.select_related("github_user").order_by( | ||
| "github_user__login" | ||
| ), | ||
| ) | ||
| ) | ||
| .get(key=module_key, program__key=program_key) | ||
| ) | ||
| except Module.DoesNotExist: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,10 +325,16 @@ describe('ModuleForm', () => { | |
| expect(screen.getByTestId('text-input-module-labels')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders mentor logins field only when isEdit is true (line 312)', () => { | ||
| it('renders mentor logins field when isEdit is false', () => { | ||
| renderModuleForm({ isEdit: false }) | ||
| expect(screen.queryByTestId('text-input-module-mentor-logins')).not.toBeInTheDocument() | ||
| expect(screen.getByTestId('text-input-module-mentor-logins')).toBeInTheDocument() | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| const input = screen.getByTestId('input-module-mentor-logins') | ||
| fireEvent.change(input, { target: { value: 'johndoe, Kateryna' } }) | ||
| expect(mockSetFormData).toHaveBeenCalled() | ||
|
Comment on lines
+332
to
+334
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Assert the
🤖 Prompt for AI Agents |
||
| }) | ||
|
|
||
| it('renders mentor logins field when isEdit is true', () => { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| renderModuleForm({ isEdit: true }) | ||
| expect(screen.getByTestId('text-input-module-mentor-logins')).toBeInTheDocument() | ||
| }) | ||
|
|
||
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.
P2: Use
Lower("github_user__login")instead of"github_user__login"for case-insensitive alphabetical sorting. Without it, the sort depends on database collation—PostgreSQL's default is case-sensitive, so"Zed"would sort before"alice". Since GitHub usernames are case-insensitive, this would produce unintuitive ordering.This applies to all five occurrences in this file.
Prompt for AI agents
This applies to all five occurrences in this file.
@@ -35,7 +35,14 @@ def get_program_modules(self, info: strawberry.Info, program_key: str) -> list[M + .prefetch_related( + Prefetch( + "mentors", + queryset=Mentor.objects.select_related("github_user").order_by( + "github_user__login" + ), ```