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: masked card num employee name description #578

Merged
merged 5 commits into from
Nov 26, 2024

Conversation

anishfyle
Copy link
Contributor

@anishfyle anishfyle commented Nov 20, 2024

Description

  • add masked corporate card number and employee name to description

Clickup

Summary by CodeRabbit

  • New Features

    • Introduced a new field for storing masked corporate card numbers in expense records.
    • Enhanced expense reporting by including employee names and masked card numbers in expense purpose details.
    • Added a new field to capture the type of payment associated with expenses.
    • Updated expense-related data structures to include masked corporate card numbers for improved data privacy.
  • Bug Fixes

    • Improved tracking of transaction dates in expense group descriptions.
  • Documentation

    • Updated help texts for new fields to provide clarity on their purpose.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

This pull request introduces changes to the fyle and sage_intacct applications. A new field, masked_corporate_card_number, is added to the Expense model in the fyle application, allowing for the storage of masked corporate card numbers. In the sage_intacct application, modifications include updates to the get_expense_purpose function and the addition of a new field, expense_payment_type, in two classes. These changes enhance data handling and reporting capabilities related to expenses and payment processing.

Changes

File Path Change Summary
apps/fyle/migrations/0035_expense_masked_corporate_card_number.py Added migration for new field masked_corporate_card_number in Expense model (nullable, CharField).
apps/fyle/models.py Added field masked_corporate_card_number to Expense model (CharField, max_length=255, nullable). Updated create_expense_objects method to handle new field.
apps/sage_intacct/models.py Updated get_expense_purpose to include employee_name and card_number in the details dictionary. Added expense_payment_type field to ExpenseReportLineitem and ChargeCardTransactionLineitem classes. Updated methods for better transaction tracking and vendor association.
tests/test_fyle/fixtures.py Added masked_corporate_card_number key to various expense-related data structures in the data dictionary.
tests/test_workspaces/fixtures.py Added masked_corporate_card_number key with value '**** 4567' to the expenses dictionary in the data structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Expense
    participant SageIntacct

    User->>Expense: Create Expense with masked_corporate_card_number
    Expense->>SageIntacct: Send expense details
    SageIntacct->>SageIntacct: Process expense purpose
    SageIntacct-->>User: Confirm expense created
Loading

🐇 "In the garden, changes bloom,
New fields sprout, making room.
Masked cards hide, secrets kept,
Expenses tracked, no more inept.
With each line, our tale grows bright,
Hopping forward, pure delight!" 🌼

Possibly related PRs

  • feat: add 'Billable' field to CCT line items #550: The changes in this PR involve the addition of a new field (billable) to the ChargeCardTransactionLineitem model, which may relate to the handling of expenses, similar to the new masked_corporate_card_number field added in the main PR. Both PRs modify expense-related models, indicating a potential connection in how expenses are structured and processed.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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/S Small PR label Nov 20, 2024
Copy link

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

Copy link

Tests Skipped Failures Errors Time
282 0 💤 0 ❌ 0 🔥 39.840s ⏱️

Copy link

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

Copy link
Contributor

@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: 3

🧹 Outside diff range and nitpick comments (3)
apps/fyle/migrations/0035_expense_masked_corporate_card_number.py (1)

13-17: Refine the field definition for masked card numbers

While the basic structure is correct, consider these essential refinements:

  1. Reduce max_length to a more appropriate value (e.g., 20 characters should be sufficient for a masked 16-digit card number)
  2. Add a db_index=True if you plan to query by this field
  3. Consider adding a validator for the masked format

Here's the suggested implementation:

 migrations.AddField(
     model_name='expense',
     name='masked_corporate_card_number',
-    field=models.CharField(help_text='Masked Corporate Card Number', max_length=255, null=True),
+    field=models.CharField(
+        help_text='Masked Corporate Card Number (e.g., ****-****-****-1234)',
+        max_length=20,
+        null=True,
+        db_index=True,
+        validators=[
+            RegexValidator(
+                regex=r'^\*+[-\s]*\*+[-\s]*\*+[-\s]*\d{4}$',
+                message='Invalid masked card number format'
+            )
+        ]
+    ),
 ),
apps/sage_intacct/models.py (1)

453-454: Consider adding data privacy documentation.

Since the code handles sensitive data (masked card numbers), consider adding documentation about data privacy requirements and masking rules in the module docstring.

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

1168-1169: Consider adding length constraints for masked card numbers

While the schema changes look good, consider adding CHECK constraints to ensure the masked_corporate_card_number follows a consistent format (e.g., length and pattern).

Example constraint:

ALTER TABLE expenses 
ADD CONSTRAINT check_masked_card_number 
CHECK (length(masked_corporate_card_number) >= 4 AND length(masked_corporate_card_number) <= 16);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e35fea6 and 86f64af.

📒 Files selected for processing (4)
  • apps/fyle/migrations/0035_expense_masked_corporate_card_number.py (1 hunks)
  • apps/fyle/models.py (1 hunks)
  • apps/sage_intacct/models.py (1 hunks)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql (4 hunks)
🔥 Files not summarized due to errors (1)
  • tests/sql_fixtures/reset_db_fixtures/reset_db.sql: Error: Server error: no LLM provider could handle the message
🔇 Additional comments (5)
apps/fyle/models.py (1)

147-147: LGTM! Good security practice using masked card numbers.

The new field is properly defined with appropriate constraints and follows security best practices by storing masked rather than full card numbers.

apps/sage_intacct/models.py (2)

453-454: LGTM! The changes enhance expense purpose details.

The addition of employee_name and masked card number to the expense purpose details improves the context available in the expense description.


Line range hint 1-1200: LGTM! Model changes are well-structured.

The addition of the expense_payment_type field to the relevant models follows Django best practices and is properly documented.

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

4139-4139: LGTM: Migration record properly added

The migration for adding the masked_corporate_card_number is correctly recorded in the migrations table.


8147-8147: LGTM: Sequence value correctly updated

The migration sequence is properly updated to match the latest migration ID.

@anishfyle anishfyle changed the title Masked card num employee name description feat: masked card num employee name description Nov 20, 2024
@anishfyle anishfyle requested a review from ruuushhh November 20, 2024 03:24
@ruuushhh ruuushhh removed their request for review November 20, 2024 05:00
Copy link

Tests Skipped Failures Errors Time
282 0 💤 18 ❌ 0 🔥 40.693s ⏱️

@github-actions github-actions bot added size/M Medium PR and removed size/S Small PR labels Nov 26, 2024
Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
tests/test_workspaces/fixtures.py (1)

65-66: LGTM! Consider adding more test cases.

The addition of the masked corporate card number field with proper masking format (showing only last 4 digits) is good. However, consider enriching the test fixtures with additional test cases to cover various scenarios.

Consider adding more expense entries to cover scenarios such as:

 'expenses':[
     {
         // ... existing test case ...
         'masked_corporate_card_number': '**** 4567'
     },
+    {
+        // ... similar expense but with different card ...
+        'masked_corporate_card_number': '**** 9876'
+    },
+    {
+        // ... expense without card number ...
+        'masked_corporate_card_number': None
+    }
 ]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 893c855 and bc9c3db.

📒 Files selected for processing (2)
  • tests/test_fyle/fixtures.py (14 hunks)
  • tests/test_workspaces/fixtures.py (1 hunks)
🔇 Additional comments (2)
tests/test_fyle/fixtures.py (2)

293-294: Implementation of masked corporate card numbers looks good!

The masked corporate card number field has been consistently added across all test fixtures with proper masking pattern showing only the last 4 digits. This follows security best practices for handling sensitive card data.

Also applies to: 340-341, 387-388, 432-433, 479-480, 524-525, 576-577, 629-630, 681-682, 734-735, 787-788, 841-842, 892-893, 946-947


293-294: Verify consistent masking pattern across the application

While the test fixtures use a consistent masking pattern '**** 4567', let's verify this matches the implementation.

Also applies to: 340-341, 387-388, 432-433, 479-480, 524-525, 576-577, 629-630, 681-682, 734-735, 787-788, 841-842, 892-893, 946-947

✅ Verification successful

Let me gather more information about the card number masking implementation.


Let me try one final search to check for any card number formatting in the API or utility layers.


Card number masking appears to be handled externally

Based on the codebase analysis, the masked_corporate_card_number field is only used to store and pass through already masked card numbers. There's no masking logic implemented within this codebase, suggesting the masking is handled by the Fyle API or external service before the data reaches this application. The test fixtures are using a consistent pattern that likely matches what's received from the external service.

  • The field is defined in apps/fyle/models.py as a CharField that stores pre-masked numbers
  • The value is passed through without modification in apps/sage_intacct/models.py
  • No masking/formatting logic was found in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for masked card number patterns in the codebase
# to verify consistent implementation

# Look for masking pattern definitions
rg -g '!tests/*' "masked.*card.*number|card.*mask" -A 2

# Look for actual masking implementation
ast-grep --pattern 'mask$_($_, $_) {
  $$$
}'

Length of output: 1447


Script:

#!/bin/bash
# Search for any card number masking or formatting patterns in the codebase
rg -g '!tests/*' -i "card.*number.*format|format.*card|mask.*card" -A 3

# Look for any utility functions that might handle card number formatting
ast-grep --pattern 'def $_($$$) {
  $$$
  card
  $$$
}'

# Check if there are any constants or configurations related to card masking
rg -g '!tests/*' "MASK|FORMAT.*CARD|CARD.*FORMAT" -A 2

Length of output: 2515


Script:

#!/bin/bash
# Search for any API or utility code that might handle card numbers
rg -g '!tests/*' "def.*expense.*card|class.*expense.*card" -A 5

# Look for any card-related serializers or formatters
ast-grep --pattern 'class $_Serializer($_) {
  $$$
  card
  $$$
}'

# Check for any card-related API endpoints
rg -g '!tests/*' "@api_view|@route" -A 3 | rg -i "card"

Length of output: 190

Copy link

Tests Skipped Failures Errors Time
282 0 💤 0 ❌ 0 🔥 40.295s ⏱️

@anishfyle anishfyle requested a review from ruuushhh November 26, 2024 09:17
@anishfyle anishfyle merged commit 92b7aa2 into master Nov 26, 2024
4 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