-
Notifications
You must be signed in to change notification settings - Fork 1
Feat: Check entity slide issue #932
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sageintacctsdk.exceptions import InvalidTokenError | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from intacctsdk.exceptions import InvalidTokenError as IntacctRESTInvalidTokenError | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from apps.sage_intacct.helpers import sync_dimensions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from apps.sage_intacct.helpers import sync_dimensions, check_entity_slide_error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from apps.sage_intacct.models import SageIntacctAttributesCount | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from apps.sage_intacct.serializers import SageIntacctAttributesCountSerializer, SageIntacctFieldSerializer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from apps.workspaces.enums import CacheKeyEnum | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -343,3 +343,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serializer_class = SageIntacctAttributesCountSerializer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lookup_field = 'workspace_id' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lookup_url_kwarg = 'workspace_id' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class EntitySlideCheckView(generics.CreateAPIView): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Check if a location entity causes an entity slide error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def post(self, request: Request, *args, **kwargs) -> Response: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entity_id = request.data.get('entity_id') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspace_id = kwargs['workspace_id'] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_valid(entity_id is not None, 'Entity ID is required') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_entity_slide_error(workspace_id=workspace_id, entity_id=entity_id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data={'entity_slide_error': False}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status=status.HTTP_200_OK | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except SageIntacctCredential.DoesNotExist: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info('Sage Intacct credentials not found for workspace_id - %s', workspace_id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data={'message': 'Sage Intacct credentials not found'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status=status.HTTP_400_BAD_REQUEST | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except (InvalidTokenError, IntacctRESTInvalidTokenError): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| invalidate_sage_intacct_credentials(workspace_id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info('Invalid Sage Intacct token for workspace_id - %s', workspace_id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data={'message': 'Invalid Sage Intacct token'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status=status.HTTP_400_BAD_REQUEST | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Entity slide error for workspace_id - %s, entity_id - %s: %s', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspace_id, entity_id, str(e) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data={'entity_slide_error': True, 'message': str(e)}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warningCode scanning / CodeQL Information exposure through an exception Medium Stack trace information Error loading related location Loading
Copilot AutofixAI 4 days ago In general, to fix information exposure via exceptions, avoid sending raw exception objects or their messages to the client. Instead, log the full details on the server (possibly with stack trace) and return a generic, non-sensitive message to the user. If you need to signal specific conditions to the client, use predefined safe codes/flags instead of arbitrary exception text. For this specific view (
Changes needed:
No new imports or helper methods are required;
Suggested changeset
1
apps/sage_intacct/views.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status=status.HTTP_200_OK | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+377
to
+384
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not expose raw exceptions in API responses. Line 383 returns Proposed fix- except Exception as e:
- logger.info(
- 'Entity slide error for workspace_id - %s, entity_id - %s: %s',
- workspace_id, entity_id, str(e)
- )
- return Response(
- data={'entity_slide_error': True, 'message': str(e)},
- status=status.HTTP_200_OK
- )
+ except Exception:
+ logger.exception(
+ 'Unexpected error while checking entity slide for workspace_id - %s, entity_id - %s',
+ workspace_id, entity_id
+ )
+ return Response(
+ data={'message': 'Unable to validate entity access at this time'},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR
+ )🧰 Tools🪛 GitHub Check: CodeQL[warning] 383-383: Information exposure through an exception 🪛 Ruff (0.15.2)[warning] 377-377: Do not catch blind exception: (BLE001) 🤖 Prompt for AI Agents |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Validate
entity_idis non-empty, not just non-null.Line 356 accepts
""/ whitespace, which can lead to invalid SDK calls instead of a clean request validation failure.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents