Fix bugs and refactor: AuthContext, ProtectedRoute, DetectorDetail endpoint, settings hardening#32
Closed
Fix bugs and refactor: AuthContext, ProtectedRoute, DetectorDetail endpoint, settings hardening#32
Conversation
…ndpoint Co-authored-by: cisar2218 <69775422+cisar2218@users.noreply.github.com>
…n package name, clean up empty lines Co-authored-by: cisar2218 <69775422+cisar2218@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Review project structure for Django and React migration
Fix bugs and refactor: AuthContext, ProtectedRoute, DetectorDetail endpoint, settings hardening
Feb 20, 2026
Contributor
|
This agent run was triggered by mistake. Initial prompt was meant to be done to discuss how development direction in this project could be improved. Most of findings were addressed outside this PR. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Code review of the Django + React codebase identified several bugs and structural issues that would compound as the project grows. This PR addresses the most impactful ones.
Backend Bugs
logger.exception("Error creating organization")was called in the success path ofOrganizationsview — fixed tologger.infoMeasurementsPosthad no return whenserializer.is_valid()failed, returningNonewith HTTP 200 — fixed to return HTTP 400 with errors"Detektor not found."→"Detector not found."Backend Architecture
check_org_admin_permission: was copy-pasted in bothdetectors.pyandorganizations.py— extracted toapi/permissions.pyGET /detector/<id>/endpoint: frontend was fetching all detectors and doing client-side.find()by ID — inefficient and wrong at scaleDEBUG = Truehardcoded;ALLOWED_HOSTSincluded"*"— both now read from env vars with safe defaultsFrontend Bug
LogbookEntryPage.tsxline 187):<div className="panel">theme.colors.danger, padding: theme.spacing['3xl']was rendered as visible textFrontend Architecture
Eliminated prop-drilling —
apiBase,isAuthed,getAuthHeaderwere passed individually to every page component. Replaced withAuthContext:ProtectedRoutecomponent: replaced duplicatedif (!isAuthed) return <LoginRequired />in every page with a single wrapperisLoadingguard inApp.tsx: prevents flash of unauthenticated content while token is read fromlocalStoragegetAuthHeaderwithuseCallback([token])so it's stable inuseEffectdepsDetector/DetectorType/DetectorManufacturertypes intypes.ts: sameinterface Detectorwas defined separately in 3+ filespackage.jsonname typo:dosportal-rect→dosportal-reactOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.