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: Check user permission before exporting #6581

Merged

Conversation

prateekj117
Copy link
Member

Fixes #6571

Short description of what this resolves:

Export event has some information which should not be available to a normal user. So check user permissions before exporting an event.

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.

@auto-label auto-label bot added the fix label Nov 6, 2019
@prateekj117 prateekj117 changed the title fix: Check user permission before exporting [WIP] fix: Check user permission before exporting Nov 6, 2019
@auto-label auto-label bot removed the fix label Nov 6, 2019
@codecov
Copy link

codecov bot commented Nov 6, 2019

Codecov Report

Merging #6581 into development will increase coverage by 0.27%.
The diff coverage is 83.63%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #6581      +/-   ##
===============================================
+ Coverage        65.03%   65.31%   +0.27%     
===============================================
  Files              296      297       +1     
  Lines            15247    15227      -20     
===============================================
+ Hits              9916     9945      +29     
+ Misses            5331     5282      -49
Impacted Files Coverage Δ
app/api/exports.py 42.1% <100%> (+18.1%) ⬆️
app/api/helpers/permissions.py 35.89% <35.71%> (+2.25%) ⬆️
app/api/schema/tickets.py 84.81% <0%> (-2.04%) ⬇️
app/api/auth.py 24.15% <0%> (-0.16%) ⬇️
app/api/helpers/query.py 44% <0%> (ø) ⬆️
app/api/custom/orders.py 31.63% <0%> (ø)
app/__init__.py 87.75% <0%> (+0.06%) ⬆️
app/api/orders.py 26.81% <0%> (+0.13%) ⬆️
app/api/helpers/scheduled_jobs.py 24.39% <0%> (+0.95%) ⬆️

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 006110f...ba24a32. Read the comment docs.

@prateekj117 prateekj117 changed the title [WIP] fix: Check user permission before exporting fix: Check user permission before exporting Nov 6, 2019
@auto-label auto-label bot added the fix label Nov 6, 2019
@fossasia fossasia deleted a comment Nov 6, 2019
@prateekj117
Copy link
Member Author

@iamareebjamal Please review. This will require some changes. I don't get the purpose of passing an argument.

@fossasia fossasia deleted a comment Nov 6, 2019
@prateekj117
Copy link
Member Author

@iamareebjamal Done. Please review.

@fossasia fossasia deleted a comment Nov 7, 2019
user.is_moderator(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):
user.is_moderator(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):

Choose a reason for hiding this comment

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

continuation line with same indent as next logical line

user.is_track_organizer(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):
user.is_track_organizer(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):

Choose a reason for hiding this comment

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

continuation line with same indent as next logical line

user.is_registrar(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):
user.is_registrar(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):

Choose a reason for hiding this comment

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

continuation line with same indent as next logical line

@@ -1,4 +1,6 @@
from flask_rest_jsonapi.exceptions import JsonApiException
from flask_rest_jsonapi.errors import jsonapi_errors
from flask import make_response, json, abort

Choose a reason for hiding this comment

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

'flask.abort' imported but unused
'flask.json' imported but unused
'flask.make_response' imported but unused

@@ -1,4 +1,6 @@
from flask_rest_jsonapi.exceptions import JsonApiException
from flask_rest_jsonapi.errors import jsonapi_errors

Choose a reason for hiding this comment

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

'flask_rest_jsonapi.errors.jsonapi_errors' imported but unused

@prateekj117
Copy link
Member Author

@iamareebjamal Done. Please review.

@fossasia fossasia deleted a comment Nov 7, 2019
@@ -6,7 +6,7 @@

from app.api.helpers.export_helpers import export_event_json, create_export_job
from app.api.helpers.permission_manager import has_access
from app.api.helpers.exceptions import assert_forbidden
from app.api.helpers.permissions import assert_forbidden
Copy link
Member

Choose a reason for hiding this comment

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

Should be in exceptions

@@ -257,3 +260,10 @@ def decorated_function(*args, **kwargs):
return f(*args, **kwargs)

return decorated_function


def assert_forbidden(access_level):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def assert_forbidden(access_level):
def assert_forbidden(has_access):

from flask_jwt_extended import verify_jwt_in_request, current_user

from app.api.helpers.db import save_to_db
from app.api.helpers.errors import ForbiddenError
from app.api.helpers.exceptions import ForbiddenException

Choose a reason for hiding this comment

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

'app.api.helpers.exceptions.ForbiddenException' imported but unused

@prateekj117
Copy link
Member Author

@iamareebjamal Done. Please review now.

user.is_moderator(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):
user.is_moderator(kwargs['event_id']) or
user.has_event_access(kwargs['event_id'])):
Copy link
Member

Choose a reason for hiding this comment

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

Revert changes in this file. And create a decorator in this file similar to others and apply that to the functions

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal But these are the simple indentation corrections, I don't see the point of reverting those changes.

Copy link
Member

@iamareebjamal iamareebjamal Nov 8, 2019

Choose a reason for hiding this comment

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

Formatting changes should be done in separate PRs. Someone will be trying to debug something and see the blame and blame you for last modifying and breaking something in a PR for fixing permissions whereas you only indented files

@prateekj117
Copy link
Member Author

@iamareebjamal Please review.

@iamareebjamal
Copy link
Member

Everything is obviously broken. Please test before asking for review

@@ -264,6 +275,7 @@ def export_speakers_csv(event_identifier):

@export_routes.route('/events/<string:event_identifier>/export/sessions/pdf', methods=['GET'],
endpoint='export_sessions_pdf')
@get_event_id
@is_coorganizer
def export_sessions_pdf(event_identifier):
Copy link
Member

Choose a reason for hiding this comment

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

Now this should be event_id and conversion in each function should be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

I will edit the logic accordingly.

@prateekj117
Copy link
Member Author

@iamareebjamal Please review.

iamareebjamal
iamareebjamal previously approved these changes Nov 24, 2019
@iamareebjamal
Copy link
Member

@kushthedude Review. There are a lot of PRs open, but not reviewed. We need to move forward with new Order API and can't until the deck is cleared

if 'event_id' in kwargs and user.has_event_access(kwargs['event_id']):
if user.is_staff or ('event_id' in kwargs and user.has_event_access(kwargs['event_id'])):
if 'event_identifier' in kwargs:
kwargs.pop('event_identifier', None)
Copy link
Member

Choose a reason for hiding this comment

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

Why's this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because then we will also have to pass an additional parameter of event_identifier in the function after using this decorator which is not used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

But this can break a function where they actually are passing event_identifier

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal Already considered this point. Check the implementation of the older is_coorganizer function, it always used to check using event_id only.

Copy link
Member

Choose a reason for hiding this comment

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

That's not what I'm talking about. Consider a function where event_identifier is being received as a parameter and this decorator is applied there

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal Considered this as well. It isn't the case anywhere right now.

Copy link
Member

Choose a reason for hiding this comment

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

Right now isn't good enough, try to create a method with this decorator and see if it fails

Copy link
Member Author

Choose a reason for hiding this comment

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

@iamareebjamal It will fail in case if the function wants event_identifier.

@prateekj117
Copy link
Member Author

Depends on #6610

@prateekj117
Copy link
Member Author

@iamareebjamal Please merge this.

@iamareebjamal
Copy link
Member

How can 6581 depend on 6610?

@iamareebjamal
Copy link
Member

Besides, this has no relation to 6610

@prateekj117
Copy link
Member Author

@iamareebjamal My bad. Wanted to comment this on a other PR.

@iamareebjamal
Copy link
Member

iamareebjamal commented Nov 26, 2019

Not much time to move ahead and be perfect with everything. So, will merge after requested changes are addressed @prateekj117

Co-Authored-By: Areeb Jamal <[email protected]>
else:
kwargs['event_id'] = kwargs['event_identifier']

return f(*args, **kwargs)

Choose a reason for hiding this comment

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

undefined name 'f'

:return:
"""

@wraps(f)

Choose a reason for hiding this comment

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

undefined name 'f'

prateekj117 and others added 2 commits November 27, 2019 03:51
Co-Authored-By: Areeb Jamal <[email protected]>
Co-Authored-By: Areeb Jamal <[email protected]>
@prateekj117
Copy link
Member Author

@iamareebjamal Done.

@iamareebjamal
Copy link
Member

Everything is broken

@iamareebjamal
Copy link
Member

@prateekj117 When can this be finalized

@prateekj117
Copy link
Member Author

@iamareebjamal Done.

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 2
           

Clones removed
==============
+ app/api/exports.py  -11
         

See the complete overview on Codacy

@iamareebjamal
Copy link
Member

Create an issue to fix is_coorganizer which doesn't mutilate method arguments

@iamareebjamal iamareebjamal merged commit 9d8a848 into fossasia:development Nov 27, 2019
codedsun pushed a commit to codedsun/open-event-server that referenced this pull request Dec 22, 2019
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.

Check Authorization level before exporting an event.
4 participants