Skip to content

Feature/file manager#10

Merged
sPROFFEs merged 2 commits into
mainfrom
feature/file-manager
Jun 5, 2025
Merged

Feature/file manager#10
sPROFFEs merged 2 commits into
mainfrom
feature/file-manager

Conversation

@sPROFFEs
Copy link
Copy Markdown
Member

@sPROFFEs sPROFFEs commented Jun 5, 2025

Refactor and improve code quality

This commit includes several code improvements and refactorings:

  1. Refactored app/core/models.py for log counting:

    • Introduced a private helper method _count_logs_since in the SystemLog model to consolidate logic for counting logs based on time, level, and security status.
    • Updated get_error_count_last_24h and get_security_events_count_last_24h to use this new helper method, reducing code duplication.
  2. Made security log retention configurable:

    • Added a SECURITY_LOG_RETENTION_DAYS configuration variable in app/config.py (defaulting to 90 days, settable via environment variable).
    • Modified the cleanup_old_logs method in SystemLog to use this configuration value instead of a hardcoded one.
  3. Improved app/core/models.py documentation and readability:

    • Added a docstring to LogSearchQuery.to_dict().
    • Ensured dictionary definitions and SQLAlchemy queries in SystemLog methods are formatted for better readability.
    • Removed some redundant local imports of datetime and timedelta.
  4. Refactored exception handling in app/auth/routes.py:

    • Introduced a private helper function _handle_auth_exception to standardize logging and flash messages for exceptions occurring during user login and registration.
    • Updated the login and register routes to use this helper, reducing boilerplate.

Also default terminal path changed to /home/$USER

sPROFFEs added 2 commits June 5, 2025 17:11
Refactor and improve code quality

This commit includes several code improvements and refactorings:

1.  **Refactored `app/core/models.py` for log counting:**
    *   Introduced a private helper method `_count_logs_since` in the `SystemLog` model to consolidate logic for counting logs based on time, level, and security status.
    *   Updated `get_error_count_last_24h` and `get_security_events_count_last_24h` to use this new helper method, reducing code duplication.

2.  **Made security log retention configurable:**
    *   Added a `SECURITY_LOG_RETENTION_DAYS` configuration variable in `app/config.py` (defaulting to 90 days, settable via environment variable).
    *   Modified the `cleanup_old_logs` method in `SystemLog` to use this configuration value instead of a hardcoded one.

3.  **Improved `app/core/models.py` documentation and readability:**
    *   Added a docstring to `LogSearchQuery.to_dict()`.
    *   Ensured dictionary definitions and SQLAlchemy queries in `SystemLog` methods are formatted for better readability.
    *   Removed some redundant local imports of `datetime` and `timedelta`.

4.  **Refactored exception handling in `app/auth/routes.py`:**
    *   Introduced a private helper function `_handle_auth_exception` to standardize logging and flash messages for exceptions occurring during user login and registration.
    *   Updated the `login` and `register` routes to use this helper, reducing boilerplate.

These changes aim to improve code maintainability, readability, and configurability.
@sPROFFEs sPROFFEs merged commit 34b6988 into main Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant