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

fix: Add user_id check before error in event invoice API #7403

Merged
merged 5 commits into from
Nov 3, 2020

Conversation

manav1403
Copy link
Contributor

Fixes #7402

Short description of what this resolves:

added user_id check before Forbidden error is raised

Changes proposed in this pull request:

  • Changes to if condition

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@@ -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:
Copy link
Member

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

@manav1403
Copy link
Contributor Author

@iamareebjamal pls review

@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #7403 into development will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##           development    #7403   +/-   ##
============================================
  Coverage        64.74%   64.74%           
============================================
  Files              262      262           
  Lines            13235    13236    +1     
============================================
+ Hits              8569     8570    +1     
  Misses            4666     4666           
Impacted Files Coverage Δ
app/api/event_invoices.py 63.54% <100.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5459387...b7a8abd. Read the comment docs.

@@ -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:
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you guide me?

Copy link
Member

Choose a reason for hiding this comment

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

Check view_args

Copy link
Contributor Author

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?

@iamareebjamal iamareebjamal changed the title added user_id check before error fix: Added user_id check before error Nov 2, 2020
@auto-label auto-label bot added the fix label Nov 2, 2020
@iamareebjamal iamareebjamal changed the title fix: Added user_id check before error fix: Add user_id check before error in event invoice API Nov 2, 2020
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:
Copy link
Member

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

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:
Copy link
Member

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

@iamareebjamal iamareebjamal merged commit fc7de44 into fossasia:development Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow user to view their own event's invoices
2 participants