-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: Add user_id check before error in event invoice API #7403
Conversation
app/api/event_invoices.py
Outdated
@@ -30,7 +30,7 @@ def query(self, view_kwargs): | |||
""" | |||
user = current_user | |||
user_id = view_kwargs.get('user_id') | |||
if user_id != user.id and not user.is_staff: | |||
if user_id and user_id != user.id and not user.is_staff: |
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.
Good work. It should throw error if /v1/event-invoices
is accessed
@iamareebjamal pls review |
Codecov Report
@@ Coverage Diff @@
## development #7403 +/- ##
============================================
Coverage 64.74% 64.74%
============================================
Files 262 262
Lines 13235 13236 +1
============================================
+ Hits 8569 8570 +1
Misses 4666 4666
Continue to review full report at Codecov.
|
app/api/event_invoices.py
Outdated
@@ -30,6 +30,8 @@ def query(self, view_kwargs): | |||
""" | |||
user = current_user | |||
user_id = view_kwargs.get('user_id') | |||
if '/v1/event-invoices' in request.url and not user.is_staff: |
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.
This is not how we do it
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.
can you guide me?
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.
Check view_args
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.
Is the way I opted now is correct or still go for args?
app/api/event_invoices.py
Outdated
or view_kwargs.get('event_identifier') | ||
if not params and not user.is_staff: | ||
raise ForbiddenError({'source': ''}, 'Admin access is required') | ||
if user_id and user_id != user.id and not user.is_staff: |
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.
Both the conditions can be combined
app/api/event_invoices.py
Outdated
if '/v1/event-invoices' in request.url and not user.is_staff: | ||
params = user_id or view_kwargs.get('event_id') \ | ||
or view_kwargs.get('event_identifier') | ||
if not params and not user.is_staff: |
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.
I think checking for an empty dict is much easier
Fixes #7402
Short description of what this resolves:
added user_id check before Forbidden error is raised
Changes proposed in this pull request:
Checklist
development
branch.