-
Notifications
You must be signed in to change notification settings - Fork 27
refactor: split routers/services, add core auth tests, and stabilize dependencies #44
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?
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary of ChangesHello @safiya2610, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's foundational structure and stability. It moves away from monolithic code by clearly delineating responsibilities between routing and service layers, making the codebase easier to understand, modify, and scale. The addition of comprehensive authentication tests provides a safety net for critical user flows, while locked dependencies prevent unexpected issues arising from version discrepancies. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request is a great step towards a cleaner architecture by splitting logic into routers and services, and stabilizing dependencies. The code is generally well-structured. However, I've found a few critical issues that need to be addressed. There's a security vulnerability in the image deletion logic that could allow unauthorized file deletion, and an incorrect use of raise RedirectResponse in a dependency that will likely cause crashes in production. I've also pointed out a security concern with storing empty passwords for OAuth users. Other comments focus on improving maintainability by reducing code duplication, adding type hints, adhering to PEP 8, and fixing some invalid HTML. Addressing these points will significantly improve the application's robustness and security.
| if not request.session.get("user"): | ||
| return RedirectResponse("/login", 303) |
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.
This authentication check is duplicated in several routes (/, /update-narrative). To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a shared FastAPI dependency. You've already created a require_user dependency in app/routers/gallery.py. Once corrected, it should be moved to a central location (e.g., app/dependencies.py) and reused here. The endpoint would then look like:
from app.dependencies import require_user
@router.post("/update-narrative")
def update_narrative(
user: str = Depends(require_user),
filename: str = Form(...),
# ...
):
# ... no need for the manual session check
cur.execute(..., (..., user))
# ...| if not request.session.get("user"): | ||
| return RedirectResponse("/login", 303) |
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.
| try: | ||
| with open("cleaned_data.json", "r", encoding="utf-8") as f: | ||
| CLEANED = json.load(f) | ||
| except Exception as e: | ||
| CLEANED = {"colors": []} |
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.
Catching a broad Exception is generally not recommended as it can hide unexpected errors. It's better to catch more specific exceptions, such as FileNotFoundError and json.JSONDecodeError. Additionally, the caught exception e is not logged, which makes debugging difficult. Consider using the logging module to record the error.
| try: | |
| with open("cleaned_data.json", "r", encoding="utf-8") as f: | |
| CLEANED = json.load(f) | |
| except Exception as e: | |
| CLEANED = {"colors": []} | |
| try: | |
| with open("cleaned_data.json", "r", encoding="utf-8") as f: | |
| CLEANED = json.load(f) | |
| except (FileNotFoundError, json.JSONDecodeError) as e: | |
| # Consider logging the error, e.g., logging.warning("Could not load cleaned_data.json: %s", e) | |
| CLEANED = {"colors": []} |
| bestd = d | ||
| best = name | ||
|
|
||
| if bestd > 45: |
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.
|
|
||
| pos = {"happiness", "joy", "optimism", "love", "peace", "purity", "energy", "enthusiasm"} | ||
| neg = {"sadness", "grief", "anger", "fear", "death", "disgust"} | ||
| neu = set() |
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.
| class="narrative-box" | ||
| placeholder="Write a note about this image..." | ||
| onblur="this.form.submit()" | ||
| >{{ img[2] if img[2] not in ['private','public'] else '' }}</textarea> |
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.
This logic {{ img[2] if img[2] not in ['private','public'] else '' }} is confusing. It appears to be checking the narrative field (img[2]) for visibility values. However, the database schema has distinct columns for narrative and visibility. This suggests a potential data modeling issue or a bug where data is being stored incorrectly. This code is hard to understand and maintain. Please clarify why this check is necessary or refactor the data handling to keep these concerns separate.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
@pradeeban @mdxabu |
Summary
Improves code quality and stability without changing app behavior.
Changes
routers/andservices/requirements/lock.txt)Why
How to Run
Future Task
Convert auth helpers into FastAPI dependencies
Add JWT-based authentication
Introduce Pydantic schemas
CI pipeline (GitHub Actions)
Docker support
What is DONE till now
pytestbase.in,test.in,dev.inpip-compileToDo