Skip to content
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

Feat: Add toggle for enabling uploading attachments #687

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

Ashutosh619-sudo
Copy link
Contributor

@Ashutosh619-sudo Ashutosh619-sudo commented Dec 18, 2024

Description

Please add PR description here, add screenshots if needed

Clickup

Please add link here
https://app.clickup.com/1864988/v/l/6-901604887942-1

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option to enable or disable attachment uploads.
  • Bug Fixes

    • Enhanced error handling and control flow for attachment upload processes.
  • Database Changes

    • Added a new field for attachment upload configuration in the database schema.
    • Updated database migration entries to reflect the new configuration.
  • Tests

    • Updated test data to include the new attachment upload configuration property.

Copy link

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces a new configuration option is_attachment_upload_enabled across multiple files. This boolean field allows conditional control over attachment uploads in NetSuite-related tasks. The changes span database migrations, model definitions, task logic, and test fixtures, enabling administrators to toggle attachment upload functionality through a configuration setting. The implementation ensures that attachment uploads can be selectively enabled or disabled based on workspace configuration.

Changes

File Change Summary
apps/netsuite/tasks.py Added conditional logic to check is_attachment_upload_enabled before executing attachment upload tasks
apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py Created migration to add new is_attachment_upload_enabled field
apps/workspaces/models.py Added is_attachment_upload_enabled boolean field to Configuration model
tests/sql_fixtures/reset_db_fixtures/reset_db.sql Updated database schema to include new column and migration entries
tests/test_workspaces/data.json Added is_attachment_upload_enabled: true to test configuration

Sequence Diagram

sequenceDiagram
    participant Admin as Workspace Admin
    participant Config as Configuration
    participant Task as Attachment Upload Task
    
    Admin->>Config: Set is_attachment_upload_enabled
    Config-->>Task: Provide upload configuration
    alt Upload Enabled
        Task->>Task: Execute Attachment Upload
    else Upload Disabled
        Task->>Task: Skip Attachment Upload
    end
Loading

Poem

🐰 A rabbit's tale of upload might,
Where configs dance in black and white
With is_attachment_upload so neat,
Control flows smooth, a coding treat!
Flexibility hops into sight! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 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 github-actions bot added the size/M Medium PR label Dec 18, 2024
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 (2)
apps/workspaces/models.py (1)

184-184: Enhance help text description

The help text could be more descriptive about the feature's purpose and impact.

Consider updating the help text to be more specific:

-    is_attachment_upload_enabled = models.BooleanField(default=True, help_text='Is Attachment upload enabled')
+    is_attachment_upload_enabled = models.BooleanField(
+        default=True,
+        help_text='Controls whether expense attachments are uploaded to NetSuite during export'
+    )
apps/netsuite/tasks.py (1)

513-517: Fix indentation to maintain consistency.

The indentation of this block is inconsistent with the rest of the file. Python is sensitive to indentation, and while this will work, it's important to maintain consistent style.

-    if configuration.is_attachment_upload_enabled:
-        async_task(
-                'apps.netsuite.tasks.upload_attachments_and_update_export',
-                expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
-            )
+    if configuration.is_attachment_upload_enabled:
+        async_task(
+            'apps.netsuite.tasks.upload_attachments_and_update_export',
+            expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
+        )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bf20f3f and b9214cf.

📒 Files selected for processing (5)
  • apps/netsuite/tasks.py (4 hunks)
  • apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py (1 hunks)
  • apps/workspaces/models.py (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (6 hunks)
  • tests/test_workspaces/data.json (1 hunks)
🔇 Additional comments (10)
tests/sql_fixtures/reset_db_fixtures/reset_db.sql (5)

6-6: LGTM: pg_dump version update

The update to pg_dump version 15.10 is a minor version change that includes bug fixes and improvements.


2701-2704: LGTM: Consistent data population

The data population maintains consistency with is_attachment_upload_enabled=true for all existing configurations, ensuring backward compatibility.


8001-8002: LGTM: Migration entries are properly sequenced

The migration entries are properly tracked and sequenced, with the sequence updated accordingly.

Also applies to: 11914-11914


326-327: Verify data migration strategy for the new column

The addition of is_attachment_upload_enabled with NOT NULL constraint is good for data integrity. However, let's verify the migration strategy.

✅ Verification successful

Let me gather more information about the migration file to ensure we have a complete picture.


Migration strategy for is_attachment_upload_enabled is properly implemented

The migration strategy is well-designed:

  • Column is added with default=True, ensuring no data inconsistency for existing records
  • The model definition matches the migration with the same default value
  • The feature is properly integrated in netsuite/tasks.py with appropriate conditional checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check migration file for default value and backfill strategy

# Check migration file content
rg -A 10 "is_attachment_upload_enabled" apps/workspaces/migrations/

# Verify if there are any existing configurations that might be affected
ast-grep --pattern 'class Configuration:
  $$$
  is_attachment_upload_enabled = $_
  $$$'

Length of output: 632


Script:

#!/bin/bash
# Get the full content of the migration file to verify the migration strategy
cat apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py

# Check if there are any existing usages of this configuration in the codebase
rg "is_attachment_upload_enabled" --type py

Length of output: 1178


12402-12408: Verify impact of new unique constraint on employee_mappings

The addition of a unique constraint on source_employee_id appears unrelated to the attachment upload feature. While it improves data integrity, we should verify:

  1. No existing duplicate source_employee_ids
  2. Impact on existing functionality
apps/workspaces/migrations/0041_configuration_is_attachment_upload_enabled.py (1)

1-18: LGTM!

The migration is correctly structured and maintains proper dependency chain.

tests/test_workspaces/data.json (1)

Line range hint 184-184: Verify implementation in tasks.py

The configuration toggle needs to be checked in the attachment upload logic.

Let's verify the implementation:

✅ Verification successful

Configuration toggle is properly implemented in tasks.py

The verification shows that the is_attachment_upload_enabled configuration toggle is correctly implemented:

  • The main attachment upload logic is in upload_attachments_and_update_export function
  • The toggle is properly checked before calling the upload function in all three expense creation flows:
    • Bill creation
    • Credit Card Charge creation
    • Expense Report creation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the new configuration field is properly used in tasks

# Look for attachment upload related functions and their usage of the new toggle
rg -A 5 "def create_(bill|credit_card_charge|expense_report)" apps/netsuite/tasks.py

# Check for attachment upload logic
rg -B 2 -A 5 "upload.*attachment" apps/netsuite/tasks.py

Length of output: 3477

apps/netsuite/tasks.py (3)

565-570: LGTM! Well-structured attachment handling.

The implementation correctly:

  1. Checks the configuration flag
  2. Processes attachments for each expense
  3. Stores attachment links for later use

664-668: LGTM! Clean implementation of conditional attachment upload.

The code correctly checks the configuration flag before initiating the async task for attachment upload.


513-517: Verify attachment upload operations across the codebase.

Let's ensure all attachment-related operations are properly gated by the new configuration flag.

Also applies to: 565-570, 664-668

✅ Verification successful

All attachment upload operations are properly gated by the configuration flag

Based on the search results, all attachment-related operations are correctly controlled by the is_attachment_upload_enabled flag:

  • The flag is properly defined in the Configuration model (apps/workspaces/models.py)
  • All attachment upload operations in apps/netsuite/tasks.py are gated by this flag:
    • Line 513: Credit card charge attachments
    • Line 565: Bill attachments
    • Line 664: Expense report attachments

The implementation is consistent and complete, with no missed attachment operations found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all attachment-related operations to verify they're properly controlled

# Search for attachment upload related function calls
echo "Searching for attachment upload related functions..."
rg -l "upload_attachments|load_attachments"

# Search for attachment-related configuration checks
echo "Searching for attachment configuration checks..."
rg "is_attachment_upload_enabled"

# Search for potential missed attachment operations
echo "Searching for potential missed attachment operations..."
rg -i "attachment" -g "!*.md"

Length of output: 16726

Comment on lines +28 to +29
"je_single_credit_line": false,
"is_attachment_upload_enabled": true
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix JSON formatting

Ensure proper comma separation between properties.

Apply this fix:

     "allow_intercompany_vendors": false,
-    "je_single_credit_line": false,
+    "je_single_credit_line": false,
     "is_attachment_upload_enabled": true

Committable suggestion skipped: line range outside the PR's diff.

Copy link

Tests Skipped Failures Errors Time
236 0 💤 0 ❌ 0 🔥 26.287s ⏱️

@Ashutosh619-sudo Ashutosh619-sudo merged commit 5887335 into master Dec 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants