-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for editing expenses #199
Conversation
|
WalkthroughThe recent changes introduce new functionalities and improvements across several modules. These include enhanced exception handling and validation in Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant WebhookView as WebhookCallbackView
participant Queue as async_handle_webhook_callback
participant Logger as Logger
participant Tasks as update_non_exported_expenses
User ->> WebhookView: POST /webhook with workspace_id
WebhookView ->> Queue: Call async_handle_webhook_callback with body, workspace_id
Queue ->> Logger: Log the webhook call details
Queue ->> Tasks: Update non-exported expenses
Tasks ->> Logger: Log expense update details
Tasks ->> Queue: Return result of update
Queue ->> WebhookView: Return response
alt Validation Error
WebhookView ->> Logger: Log error details
WebhookView ->> User: Return error response
else Success
WebhookView ->> User: Return success response
end
Poem
Warning Review ran into problemsProblems (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
Files selected for processing (8)
- apps/fyle/exceptions.py (2 hunks)
- apps/fyle/helpers.py (2 hunks)
- apps/fyle/queue.py (4 hunks)
- apps/fyle/tasks.py (2 hunks)
- apps/fyle/views.py (1 hunks)
- requirements.txt (1 hunks)
- tests/test_fyle/fixtures.py (1 hunks)
- tests/test_fyle/test_tasks.py (1 hunks)
Files skipped from review due to trivial changes (1)
- requirements.txt
Additional comments not posted (7)
tests/test_fyle/test_tasks.py (1)
12-62
: Comprehensive Test Coverage forupdate_non_exported_expenses
The test function
test_update_non_exported_expenses
adequately covers various scenarios including state changes and error handling. This ensures robustness in the feature's behavior under different conditions.apps/fyle/queue.py (1)
6-6
: Enhancements to Webhook Handling and LoggingThe addition of
workspace_id
toasync_handle_webhook_callback
and the integration of logging and validation checks are significant improvements. These changes enhance the robustness and traceability of the webhook handling mechanism.Also applies to: 15-18, 69-88
apps/fyle/views.py (1)
143-143
: Correct Integration ofworkspace_id
in Webhook CallbackThe update to include
workspace_id
in thepost
method ofWebhookCallbackView
ensures that the webhook handling is consistent with the workspace-specific enhancements made in other parts of the application.apps/fyle/exceptions.py (1)
8-8
: Enhanced Error Handling for Validation ErrorsThe addition of a handling block for
ValidationError
improves the application's robustness by ensuring that such errors are logged and appropriately communicated to the client.Also applies to: 94-96
apps/fyle/tasks.py (1)
127-149
: Implementation ofupdate_non_exported_expenses
The new function
update_non_exported_expenses
is implemented to handle updates to expenses based on their current state, ensuring that only eligible expenses are updated. This is a critical enhancement for the feature of editing expenses.apps/fyle/helpers.py (1)
8-10
: Imports are correctly used.The
ValidationError
is used for raising exceptions in the new function, andWorkspace
is used to fetch workspace details, validating their necessity.tests/test_fyle/fixtures.py (1)
2-267
: Test fixtures expanded to support new functionalities.The additions to the test fixtures are comprehensive and seem well-designed to support the new functionalities related to expense management and validation.
def assert_valid_request(workspace_id:int, org_id:str): | ||
""" | ||
Assert if the request is valid by checking | ||
the url_workspace_id and fyle_org_id workspace | ||
""" | ||
workspace = Workspace.objects.get(org_id=org_id) | ||
if workspace.id != workspace_id: | ||
raise ValidationError('Workspace mismatch') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider handling the case where no workspace matches the given org_id
.
Currently, if no workspace is found, a Workspace.DoesNotExist
exception will be raised. It would be more user-friendly to catch this exception and raise a ValidationError
with a clear message.
- workspace = Workspace.objects.get(org_id=org_id)
+ try:
+ workspace = Workspace.objects.get(org_id=org_id)
+ except Workspace.DoesNotExist:
+ raise ValidationError(f"No workspace found for org_id {org_id}")
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.
def assert_valid_request(workspace_id:int, org_id:str): | |
""" | |
Assert if the request is valid by checking | |
the url_workspace_id and fyle_org_id workspace | |
""" | |
workspace = Workspace.objects.get(org_id=org_id) | |
if workspace.id != workspace_id: | |
raise ValidationError('Workspace mismatch') | |
def assert_valid_request(workspace_id:int, org_id:str): | |
""" | |
Assert if the request is valid by checking | |
the url_workspace_id and fyle_org_id workspace | |
""" | |
try: | |
workspace = Workspace.objects.get(org_id=org_id) | |
except Workspace.DoesNotExist: | |
raise ValidationError(f"No workspace found for org_id {org_id}") | |
if workspace.id != workspace_id: | |
raise ValidationError('Workspace mismatch') |
elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE': | ||
org_id = body['data']['org_id'] | ||
logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data'))) | ||
assert_valid_request(workspace_id=workspace_id, org_id=org_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move out
Summary by CodeRabbit
update_non_exported_expenses
function to handle non-exported expenses.fyle
to version0.37.0
.fyle-integrations-platform-connector
to version1.38.1
.