Skip to content

Try deploy2#425

Closed
ruuushhh wants to merge 3 commits intomasterfrom
try-deploy2
Closed

Try deploy2#425
ruuushhh wants to merge 3 commits intomasterfrom
try-deploy2

Conversation

@ruuushhh
Copy link
Contributor

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2025

Walkthrough

This pull request introduces a comprehensive update to track user actions across multiple models in the application. The changes involve adding created_by and updated_by fields to several models including ExpenseGroupSettings, GeneralMapping, WorkspaceGeneralSettings, and associated migration files. Additionally, the project updates the fyle-accounting-mappings package to version 1.36.3 and modifies serializers and views to pass user context during update operations. The README.md is also updated with environment variable configuration details.

Changes

File Change Summary
README.md Added section detailing Docker environment variable setup
requirements.txt Updated fyle-accounting-mappings from 1.35.0 to 1.36.3
apps/fyle/models.py
apps/mappings/models.py
apps/workspaces/models.py
Added AutoAddCreateUpdateInfoMixin to models, enabling user tracking
apps/fyle/migrations/0023_auto_20250108_0817.py
apps/mappings/migrations/0007_auto_20250108_0817.py
apps/workspaces/migrations/0042_auto_20250108_0817.py
Created migrations to add created_by and updated_by fields
apps/workspaces/apis/advanced_settings/serializers.py
apps/workspaces/apis/export_settings/serializers.py
apps/workspaces/apis/import_settings/serializers.py
Modified update methods to include user context
apps/workspaces/apis/advanced_settings/views.py
apps/workspaces/apis/export_settings/views.py
apps/workspaces/apis/import_settings/views.py
Added get_serializer_context method to pass request
tests/test_fyle/fixtures.py
tests/test_workspaces/fixtures.py
Updated test fixtures with new user tracking fields
tests/test_fyle/test_models.py Updated test to include user parameter in method call
Dockerfile Commented out flake8 linting check
fyle_integrations_imports Removed subproject commit reference

Suggested reviewers

  • ashwin1111

Possibly related PRs

Poem

🐰 A Rabbit's Ode to User Tracking 🕵️

Bits and bytes now tell a tale,
Of who created, who did prevail
With created_by and updated_by
Our code now knows just who and why
Tracking changes, hop by hop! 🚀


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

PR title must start with "fix:", "feat:", "chore:", "refactor", or "test:" (case-insensitive)

@github-actions
Copy link

PR description must contain a link to a ClickUp (case-insensitive)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (9)
apps/workspaces/apis/import_settings/views.py (1)

13-20: LGTM! Consider enhancing the docstring.

The implementation correctly overrides the context to include the request object, following Django REST framework's best practices.

Consider expanding the docstring to include:

    def get_serializer_context(self):
        """
        Override to include the request in the serializer context.
        This allows serializers to access the current user.
+       Returns:
+           dict: The serializer context including the request object
        """
apps/workspaces/apis/export_settings/views.py (1)

13-20: Consider reducing code duplication across views.

While the implementation is correct, this exact same code exists in multiple view classes. Consider creating a mixin to share this functionality.

Example implementation:

class SerializerContextRequestMixin:
    def get_serializer_context(self):
        """
        Include the request in the serializer context.
        This allows serializers to access the current user.
        
        Returns:
            dict: The serializer context including the request object
        """
        context = super().get_serializer_context()
        context['request'] = self.request
        return context

class ExportSettingsView(SerializerContextRequestMixin, generics.RetrieveUpdateAPIView):
    # ... rest of the implementation
apps/mappings/migrations/0007_auto_20250108_0817.py (1)

13-22: Consider using EmailField for email storage.

While CharField works, Django's EmailField would provide built-in email validation and better semantic meaning for these fields.

-            field=models.CharField(blank=True, help_text='Email of the user who created this record', max_length=255, null=True),
+            field=models.EmailField(blank=True, help_text='Email of the user who created this record', max_length=255, null=True),
-            field=models.CharField(blank=True, help_text='Email of the user who last updated this record', max_length=255, null=True),
+            field=models.EmailField(blank=True, help_text='Email of the user who last updated this record', max_length=255, null=True),
tests/test_workspaces/fixtures.py (1)

24-25: Use more realistic test email addresses.

The current test emails (asdvhjasb@anjfas.com and asbdja@nkasnd.com) appear to be randomly typed. Consider using more realistic test email addresses that follow common patterns (e.g., user1@example.com) for better test readability and maintainability.

-        "created_by": "asdvhjasb@anjfas.com",
-        "updated_by": "asbdja@nkasnd.com"
+        "created_by": "user1@example.com",
+        "updated_by": "user2@example.com"
tests/test_fyle/test_models.py (1)

51-53: Consider making the test more robust.

The test assumes workspace ID 1 exists and has a user. This could make the test fragile. Consider using the create_temp_workspace fixture that's already being used to get the user, rather than hardcoding the workspace ID.

-    user = Workspace.objects.get(id=1).user
+    workspace = create_temp_workspace
+    user = workspace.user

     ExpenseGroupSettings.update_expense_group_settings(payload, workspace_id, user)
apps/workspaces/models.py (1)

146-146: LGTM! Consider adding docstring updates.

The addition of AutoAddCreateUpdateInfoMixin enhances user action tracking. Consider updating the model's docstring to document the new tracking fields (created_by and updated_by).

README.md (1)

22-22: Enhance security in environment variables documentation.

Consider these security improvements for the environment variables section:

  1. Add a note about not committing actual credentials to version control
  2. Provide an example .env.example file instead of embedding variables in docker-compose.yml
  3. Add placeholders (e.g., <your-secret-key>) instead of example values for sensitive fields

Also applies to: 23-39

tests/sql_fixtures/reset_db_fixtures/reset_db.sql (2)

819-821: Consider adding NOT NULL constraints for audit columns.

The created_by and updated_by columns are currently nullable. For proper audit tracking, consider making these columns NOT NULL and providing default values for existing records.

-    created_by character varying(255),
-    updated_by character varying(255)
+    created_by character varying(255) NOT NULL DEFAULT 'system',
+    updated_by character varying(255) NOT NULL DEFAULT 'system'

1077-1079: Add foreign key constraint for expense_field_id.

The expense_field_id column appears to be a reference to another table but lacks a foreign key constraint. Consider adding one to maintain referential integrity.

Also, similar to the previous comment, consider making the audit columns NOT NULL with default values.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f1de65 and 78985a2.

📒 Files selected for processing (18)
  • README.md (1 hunks)
  • apps/fyle/migrations/0023_auto_20250108_0817.py (1 hunks)
  • apps/fyle/models.py (4 hunks)
  • apps/mappings/migrations/0007_auto_20250108_0817.py (1 hunks)
  • apps/mappings/models.py (2 hunks)
  • apps/workspaces/apis/advanced_settings/serializers.py (3 hunks)
  • apps/workspaces/apis/advanced_settings/views.py (1 hunks)
  • apps/workspaces/apis/export_settings/serializers.py (4 hunks)
  • apps/workspaces/apis/export_settings/views.py (1 hunks)
  • apps/workspaces/apis/import_settings/serializers.py (4 hunks)
  • apps/workspaces/apis/import_settings/views.py (1 hunks)
  • apps/workspaces/migrations/0042_auto_20250108_0817.py (1 hunks)
  • apps/workspaces/models.py (2 hunks)
  • requirements.txt (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (10 hunks)
  • tests/test_fyle/fixtures.py (1 hunks)
  • tests/test_fyle/test_models.py (2 hunks)
  • tests/test_workspaces/fixtures.py (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • requirements.txt
  • tests/test_fyle/fixtures.py
🧰 Additional context used
🪛 GitHub Actions: Continuous Deployment
apps/fyle/models.py

[error] 16-16: Redefinition of unused 'AutoAddCreateUpdateInfoMixin' from line 14. The class is imported or defined multiple times.

🪛 GitHub Actions: Continuous Integration
apps/fyle/models.py

[error] 16-16: Redefinition of unused 'AutoAddCreateUpdateInfoMixin' from line 14. The class is imported or defined twice.

🪛 GitHub Actions: Codecov Report Upload
apps/fyle/models.py

[error] 16-16: Redefinition of unused 'AutoAddCreateUpdateInfoMixin' from line 14. The class is imported or defined twice.

🔇 Additional comments (15)
apps/workspaces/apis/advanced_settings/views.py (1)

13-20: Same code duplication issue as noted earlier.

This is the third occurrence of identical context override code. Please refer to the refactoring suggestion in the ExportSettingsView review.

apps/fyle/migrations/0023_auto_20250108_0817.py (1)

13-22: LGTM! Well-structured migration for user tracking fields.

The migration properly adds created_by and updated_by fields with appropriate field types, constraints, and help text.

apps/workspaces/migrations/0042_auto_20250108_0817.py (1)

13-22: LGTM! Consistent implementation of user tracking fields.

The migration maintains consistency with other models by using identical field definitions for created_by and updated_by.

apps/mappings/models.py (1)

7-7: Verify the integration of AutoAddCreateUpdateInfoMixin.

The mixin has been added to handle user tracking, but we should verify:

  1. That the views pass the user context correctly
  2. That the mixin's functionality is properly integrated with Django's request cycle

Let's check the related view implementations:

Also applies to: 38-38

✅ Verification successful

AutoAddCreateUpdateInfoMixin integration verified successfully

The mixin is properly integrated with:

  • Views passing request context correctly
  • Serializers using update_or_create with user context
  • All necessary components for user tracking in place
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for view classes that handle GeneralMapping
rg -l "GeneralMapping" | grep "views.py"

# Check if these views implement get_serializer_context
rg "def get_serializer_context" $(rg -l "GeneralMapping" | grep "views.py")

Length of output: 367


Script:

#!/bin/bash
# Check view implementations for GeneralMapping usage and context
for file in apps/workspaces/apis/*/views.py; do
    echo "=== $file ==="
    # Show class definitions and GeneralMapping usage
    rg "class.*GeneralMapping|def.*GeneralMapping" "$file" -B 2 -A 5
    # Show get_serializer_context implementation
    rg "def get_serializer_context" "$file" -B 1 -A 3
done

Length of output: 2291


Script:

#!/bin/bash
# Get complete view implementations
echo "=== Searching for GeneralMapping usage ==="
rg "GeneralMapping" apps/workspaces/apis/*/views.py -B 5 -A 10

echo -e "\n=== Complete get_serializer_context implementations ==="
rg "get_serializer_context" apps/workspaces/apis/*/views.py -B 2 -A 5

echo -e "\n=== View base classes ==="
rg "^class.*\(.*View" apps/workspaces/apis/*/views.py -B 1 -A 2

Length of output: 5348


Script:

#!/bin/bash
# Check serializer implementations
echo "=== Searching for GeneralMapping in serializers ==="
rg "GeneralMapping" apps/workspaces/apis/*/serializers.py -B 5 -A 10

echo -e "\n=== Check serializer base classes and Meta ==="
for file in apps/workspaces/apis/*/serializers.py; do
    echo "=== $file ==="
    rg "^class.*Serializer.*:|class Meta:" "$file" -B 1 -A 5
done

Length of output: 24583

apps/workspaces/apis/advanced_settings/serializers.py (2)

85-86: LGTM! Robust user context retrieval.

The implementation safely handles cases where the request or user might be unavailable.


117-117: LGTM! Consistent user tracking implementation.

The user context is properly passed to both update operations, aligning with the PR objective of tracking user actions.

Also applies to: 128-128

apps/workspaces/apis/import_settings/serializers.py (2)

107-108: LGTM! Consistent user context implementation.

The implementation matches the pattern used in other serializers, maintaining codebase consistency.


145-145: LGTM! Comprehensive user tracking coverage.

User context is properly added to all database operations, ensuring complete tracking of changes.

Also applies to: 158-158, 211-211

apps/workspaces/apis/export_settings/serializers.py (2)

104-105: LGTM! Consistent user context retrieval.

The implementation follows the established pattern across serializers.


138-138: LGTM! Complete user tracking implementation.

User context is properly added to all relevant database operations, including WorkspaceGeneralSettings, MappingSetting, ExpenseGroupSettings, and GeneralMapping.

Also applies to: 155-155, 189-189, 197-197

apps/fyle/models.py (2)

438-438: LGTM! User tracking implementation.

The addition of user tracking through the user parameter in update_or_create is correctly implemented.


281-281: Verify all callers of update_expense_group_settings.

The method signature has changed to include the user parameter. Let's verify all callers have been updated accordingly.

Also applies to: 342-342

✅ Verification successful

All callers of update_expense_group_settings are properly updated

All identified callers are already passing the user parameter correctly:

  • apps/workspaces/apis/export_settings/serializers.py
  • tests/test_fyle/test_models.py
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to update_expense_group_settings
rg -A 2 "update_expense_group_settings\(" --type python

Length of output: 88


Script:

#!/bin/bash
# Search for method definition and calls with more context
rg -A 5 "update_expense_group_settings" 

# Also try to find the method definition using ast-grep
ast-grep --pattern 'def update_expense_group_settings($$$)'

Length of output: 1631

tests/sql_fixtures/reset_db_fixtures/reset_db.sql (3)

2661-2664: LGTM! Migration sequence is properly ordered.

The migration sequence is properly incremented and timestamps maintain chronological order.


4860-4861: LGTM! Data migration maintains consistency.

The COPY commands properly include all new columns and maintain data consistency during migration.

Also applies to: 4932-4933, 4957-4963, 5088-5089


819-821: LGTM! Schema changes enhance audit capabilities.

The addition of created_by and updated_by columns across multiple tables improves the audit trail without introducing security concerns.

Also applies to: 1077-1079, 1204-1205, 1546-1547

from django.db import models
from django.db.models import Count, JSONField
from fyle_accounting_mappings.models import ExpenseAttribute
from fyle_accounting_mappings.mixins import AutoAddCreateUpdateInfoMixin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate import.

The AutoAddCreateUpdateInfoMixin is imported twice (line 14 and 15). Remove one of the duplicate imports to fix the pipeline failures.

-from fyle_accounting_mappings.mixins import AutoAddCreateUpdateInfoMixin

@github-actions
Copy link

PR title must start with "fix:", "feat:", "chore:", "refactor", or "test:" (case-insensitive)

@github-actions
Copy link

PR description must contain a link to a ClickUp (case-insensitive)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78985a2 and 38f6746.

📒 Files selected for processing (2)
  • Dockerfile (1 hunks)
  • fyle_integrations_imports (0 hunks)
💤 Files with no reviewable changes (1)
  • fyle_integrations_imports
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: pytest
  • GitHub Check: staging_deploy


# Do linting checks
RUN flake8 .
# RUN flake8 .
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Consider using selective linting configuration instead of disabling checks completely

While there are legitimate linting issues in the codebase (primarily line length violations), completely disabling flake8 checks is not the best solution. Instead:

  1. Create a setup.cfg or .flake8 configuration file to:

    • Adjust max line length if needed (e.g., 100-120 characters)
    • Add specific exclusions for test files and fixtures
    • Configure per-file-type rules
  2. Use inline # noqa comments for legitimate exceptions like long URLs or data structures

This maintains code quality while accommodating practical needs.

🔗 Analysis chain

Do not disable linting checks in the build process.

Commenting out the flake8 check reduces code quality guarantees and may allow problematic code to slip through. This change appears unrelated to the PR's primary objective of implementing user tracking.

Instead of disabling linting:

  1. Fix any linting issues in the codebase
  2. If temporary bypass is absolutely necessary, document why in the PR description

Let's verify if there are actual linting issues that need to be addressed:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential linting issues in the changed files
git diff origin/main HEAD --name-only | grep '\.py$' | xargs flake8 || echo "Linting issues found in changed files"

Length of output: 387


Script:

#!/bin/bash
# Find Python files
echo "=== Python Files ==="
fd -e py

# Check for long lines (>79 chars)
echo -e "\n=== Lines > 79 chars ==="
fd -e py -x rg -n '.{80,}'

# Check for trailing whitespace
echo -e "\n=== Trailing Whitespace ==="
fd -e py -x rg -n '\s+$'

# Check for mixed indentation
echo -e "\n=== Mixed Indentation ==="
fd -e py -x rg -n '^ *\t'

Length of output: 66359

@ruuushhh ruuushhh closed this Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants