-
-
Notifications
You must be signed in to change notification settings - Fork 313
Backend data labs #4405
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
Backend data labs #4405
Conversation
- Introduced a new Labs model with fields for name, description, estimated time, total tasks, and active status. - Added a management command to create initial lab data for SQL Injection, XSS, CSRF, and Command Injection. - Updated the dashboard view to fetch and display active labs with their respective details. New labs created, Knowledge in every task, Learning never ends.
|
""" WalkthroughThe changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant WebServer
participant DashboardView
participant LabsModel
User->>WebServer: GET /simulation/
WebServer->>DashboardView: Call dashboard(request)
DashboardView->>LabsModel: Query active labs (order by 'order')
LabsModel-->>DashboardView: Return labs queryset
DashboardView->>WebServer: Render Simulation.html with labs context
WebServer-->>User: Return rendered dashboard page
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (6)
blt/urls.py (1)
279-279: Prefer lowercase module names to avoid case-sensitivity surprisesThe new import targets
website.views.Simulation. While this works if the file is literally namedSimulation.py, it breaks on case-sensitive filesystems the moment the file is renamed to follow PEP 8 (simulation.py). Importing with a lowercase path keeps the codebase platform-agnostic and future-proof.-from website.views.Simulation import dashboard +from website.views.simulation import dashboard(If the file is already committed as
Simulation.py, consider renaming it in a follow-up PR.)website/models.py (1)
2479-2482: Consider adding database indexes for better query performance.Since the model will likely be frequently queried by
is_activeandorderfields, adding indexes could improve performance.class Meta: verbose_name = "Lab" verbose_name_plural = "Labs" ordering = ["order"] + indexes = [ + models.Index(fields=["is_active"]), + models.Index(fields=["order"]), + models.Index(fields=["is_active", "order"]), + ]website/views/Simulation.py (2)
16-23: Consider making the icon mapping more flexible and maintainable.The hardcoded icon mapping logic could be improved for better maintainability and extensibility.
Option 1: Move to model field
Add aniconfield to the Labs model:# In Labs model icon = models.CharField(max_length=50, default="database")Option 2: Use a mapping dictionary
-# Map lab icons based on lab name or add a default -icon = "database" # Default icon -if "xss" in lab.name.lower(): - icon = "code" -elif "csrf" in lab.name.lower(): - icon = "shield-check" -elif "command" in lab.name.lower(): - icon = "terminal" +# Icon mapping dictionary +ICON_MAPPING = { + "xss": "code", + "csrf": "shield-check", + "command": "terminal", +} + +icon = "database" # Default icon +for keyword, mapped_icon in ICON_MAPPING.items(): + if keyword in lab.name.lower(): + icon = mapped_icon + break
32-32: Consider making the color configurable rather than hardcoded.Having all labs use the same color
"#e74c3c"reduces visual differentiation and customization options.Option 1: Add color field to Labs model
# In Labs model color = models.CharField(max_length=7, default="#e74c3c", help_text="Hex color code")Option 2: Use a color palette
-"color": "#e74c3c", +# Define color palette +COLORS = ["#e74c3c", "#3498db", "#2ecc71", "#f39c12", "#9b59b6"] +"color": COLORS[lab.order % len(COLORS)],website/templates/Simulation.html (2)
75-88: Improve button accessibilityThe button relies solely on visual text; screen-reader users would benefit from an explicit label. Add
aria-labeland hide the decorative arrow:-<button class="w-full ..."> +<button class="w-full ..." aria-label="{{ 'Continue' if lab.progress > 0 else 'Start' }} Lab"> ... -<svg class="ml-2 -mr-1 h-4 w-4" +<svg class="ml-2 -mr-1 h-4 w-4" aria-hidden="true"
24-55: Avoid hard-coding brand colour multiple timesThe colour
#e74c3cis repeated in several SVG and button classes. Consider extracting it into a Tailwind CSS theme extension or a custom CSS variable (--brand-red) to ensure consistency and simplify future rebranding.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting
📒 Files selected for processing (6)
blt/urls.py(2 hunks)website/management/commands/create_initial_labs.py(1 hunks)website/migrations/0242_labs.py(1 hunks)website/models.py(1 hunks)website/templates/Simulation.html(1 hunks)website/views/Simulation.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
blt/urls.py (1)
website/views/Simulation.py (1)
dashboard(10-38)
website/management/commands/create_initial_labs.py (1)
website/models.py (1)
Labs(2457-2482)
website/views/Simulation.py (1)
website/models.py (1)
Labs(2457-2482)
🪛 Pylint (3.3.7)
website/management/commands/create_initial_labs.py
[refactor] 6-6: Too few public methods (1/2)
(R0903)
website/migrations/0242_labs.py
[refactor] 6-6: Too few public methods (0/2)
(R0903)
website/models.py
[refactor] 2479-2479: Too few public methods (0/2)
(R0903)
🪛 HTMLHint (1.5.0)
website/templates/Simulation.html
[error] 2-2: Doctype must be declared before any non-comment content.
(doctype-first)
[error] 76-76: Special characters must be escaped : [ > ].
(spec-char-escape)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run Tests
🔇 Additional comments (5)
blt/urls.py (1)
362-364: URL namedashboardis very generic – risk of collision
path("simulation/", dashboard, name="dashboard")introduces a top-level route whose name is simply"dashboard".
Because this project already contains many dashboard-related views, a duplicate reverse lookup (e.g.reverse("dashboard")) elsewhere would now silently resolve to the wrong URL and be difficult to trace.Recommend using a more specific name such as
"simulation_dashboard":-path("simulation/", dashboard, name="dashboard"), +path("simulation/", dashboard, name="simulation_dashboard"),Please verify no other URL pattern already uses
"dashboard".website/migrations/0242_labs.py (1)
1-31: Migration looks good and correctly implements the Labs model.The auto-generated migration properly creates the Labs table with all the required fields and options matching the model definition.
website/views/Simulation.py (1)
9-38: Good implementation of the dashboard view with proper security and structure.The view correctly uses
@login_requiredfor security, efficiently queries the database, and provides a clean data structure for the template. The approach is well-structured and follows Django best practices.website/management/commands/create_initial_labs.py (2)
11-36: Well-structured initial lab data covering essential security topics.The lab definitions are comprehensive and educational:
- Good coverage of fundamental security vulnerabilities
- Descriptive content that explains what learners will achieve
- Reasonable time estimates for each lab (30-60 minutes)
- Logical ordering for learning progression
39-53: Excellent implementation of the management command.The command follows Django best practices:
- Uses
get_or_create()to ensure idempotency- Provides clear feedback with success and warning messages
- Handles the creation process efficiently with proper error handling
…nto backend_data_labs
* only frontedn dashboard * Add Labs model and initial data creation command - Introduced a new Labs model with fields for name, description, estimated time, total tasks, and active status. - Added a management command to create initial lab data for SQL Injection, XSS, CSRF, and Command Injection. - Updated the dashboard view to fetch and display active labs with their respective details. New labs created, Knowledge in every task, Learning never ends. * pre_commit_done * for_passing_test --------- Co-authored-by: DonnieBLT <[email protected]>
fixes #4404
Added new Labs`model with fields:
Created management command create_initial_labs to populate initial security labs:
Updated simulation dashboard to display labs from database instead of hardcoded data
Added estimated time display to lab cards in UI
Summary by CodeRabbit
New Features
Database
Chores