Conversation
…nances into code-cleanup-160
|
Hey @reenu153 / @LaraMerdol, Thank you for these changes! There's currently a fairly big queue in PRs so I wont be able to merge this right away, but I do appreciate the effort! I'll let you know when I get round to testing and merging this :) |
|
|
||
|
|
||
| def RandomCode(length=6): | ||
| def generate_verification_code(length=6): |
There was a problem hiding this comment.
| def generate_verification_code(length=6): | |
| def generate_verification_code(length: int = 6): |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/core/views/auth/passwords/generate.py (1)
101-101:⚠️ Potential issue | 🟠 MajorSecurity concern: Password reset code logged to stdout.
The
print(f"code is {CODE}")statement logs the raw password reset code. While this appears to be a temporary debug mechanism (given the commented-out email code above), logging sensitive authentication tokens to stdout poses a security risk in production environments where logs may be captured and stored.Consider removing this debug statement or gating it behind a development-only flag.
Proposed fix
- print(f"code is {CODE}") + # TODO: Remove debug logging or implement proper email sending + if settings.DEBUG: + print(f"code is {CODE}")
🧹 Nitpick comments (4)
backend/migrations/0022_loginlog_service_alter_verificationcodes_expiry_and_more.py (1)
5-5: Unused import in migration file.The
import backend.modelsstatement appears unused - the migration referencesbackend.core.models.add_3hrs_from_nowandbackend.core.models.generate_verification_codedirectly via their dotted paths.Note: This is auto-generated migration code, so modifying it is optional. Django resolves the dotted paths at runtime regardless of this import.
backend/migrations/0023_apikey_invoiceonetimeschedule.py (1)
6-6: Unused import in migration file.The
import backend.modelsstatement appears unused - the migration referencesbackend.core.models.generate_api_keydirectly via dotted path.Note: This is auto-generated migration code, so modifying it is optional.
backend/storage/views/upload.py (1)
102-105: Passing the model class instead of an instance is unconventional.
get_file_upload_pathexpects aninstanceas the first parameter, butFileStorageFile(the class) is passed here. This works becauseoptional_actoris always provided, which bypasses the instance attribute checks. However, this relies on the implementation detail ofget_file_upload_pathand could break if that function's logic changes.Consider creating a minimal mock object or documenting this usage pattern to make the intent clearer.
backend/finance/models.py (1)
22-26: Imported constantsDECIMAL_MAX_DIGITSandDECIMAL_PLACESappear unused.These constants are imported but the file still uses hardcoded values like
max_digits=15, decimal_places=2for decimal fields (e.g., lines 67, 78-81, 130-131). Consider applying these constants to decimal fields for consistency, or remove the unused imports if they were intentionally left unchanged.
| @@ -0,0 +1,13 @@ | |||
| # Backend core cosntant.py | |||
There was a problem hiding this comment.
Typo in comment: "cosntant.py" should be "constants.py".
Proposed fix
-# Backend core cosntant.py
+# Backend core constants.py📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # Backend core cosntant.py | |
| # Backend core constants.py |
Description
This pull request refactors the code primarily to address the code cleanup tasks outlined in issue #160. The refactoring addresses several code smells and aims to improve the readability, maintainability, and structure of the codebase.
Refactoring Details:
Magic Numbers/Constants:
backend/core/constants.pyfile to define named constants for recurring numerical values (e.g.,MAX_LENGTH_STANDARD,MAX_LENGTH_NAME,MAX_LENGTH_DESCRIPTION,DECIMAL_MAX_DIGITS,DECIMAL_PLACES).max_lengthanddecimalconstraints in models with the defined constants.Inappropriate/Unclear Naming:
_public_storage→get_public_storage_private_storage→get_private_storageRandomCode→generate_verification_codeRandomAPICode→generate_api_keyupload_to_user_separate_folder→get_file_upload_pathSet blank=False for name fields: Ensures name and related fields (e.g., description, event_name) are required across multiple models to prevent missing data.
Checklist
djLint-er on any new code
(checks
will
fail without)
changes
What type of PR is this?
Added/updated tests?
Related PRs, Issues etc
Summary by CodeRabbit
New Features
Chores