-
Couldn't load subscription status.
- Fork 1.9k
fix: Check user permission before exporting #6581
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
Changes from 7 commits
3dccf6a
56d0c94
ae10e8a
9d3a0f7
9c7112e
5f3ab66
dc326f9
81c6553
b7b0676
ba24a32
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 |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| from functools import wraps | ||
| from flask import current_app as app | ||
| 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 flask import request | ||
| from datetime import datetime | ||
| from app.models import db | ||
| from app.models.event import Event | ||
|
|
||
|
|
||
| def second_order_decorator(inner_dec): | ||
|
|
@@ -145,6 +146,30 @@ def decorated_function(*args, **kwargs): | |
| return decorated_function | ||
|
|
||
|
|
||
| @second_order_decorator(jwt_required) | ||
| def to_event_id(func): | ||
| """ | ||
| Get event id from event identifier. | ||
prateekj117 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| :param f: | ||
| :return: | ||
| """ | ||
|
|
||
| @wraps(f) | ||
|
||
| def decorated_function(*args, **kwargs): | ||
|
|
||
| if 'event_identifier' in kwargs: | ||
| if not kwargs['event_identifier'].isdigit(): | ||
| event = db.session.query(Event).filter_by(identifier=kwargs['event_identifier']).first() | ||
prateekj117 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| kwargs['event_id'] = event.id | ||
| else: | ||
| kwargs['event_id'] = kwargs['event_identifier'] | ||
|
|
||
| return f(*args, **kwargs) | ||
|
||
|
|
||
| return decorated_function | ||
|
|
||
|
|
||
|
|
||
| @second_order_decorator(jwt_required) | ||
| def is_coorganizer(f): | ||
| """ | ||
|
|
@@ -157,10 +182,11 @@ def is_coorganizer(f): | |
| def decorated_function(*args, **kwargs): | ||
| user = current_user | ||
|
|
||
| if user.is_staff: | ||
| return f(*args, **kwargs) | ||
| 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) | ||
|
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. Why's this needed? 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. Because then we will also have to pass an additional parameter of 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. But this can break a function where they actually are passing event_identifier 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. @iamareebjamal Already considered this point. Check the implementation of the older 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. 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 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. @iamareebjamal Considered this as well. It isn't the case anywhere right now. 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. Right now isn't good enough, try to create a method with this decorator and see if it fails 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. @iamareebjamal It will fail in case if the function wants event_identifier. |
||
| return f(*args, **kwargs) | ||
|
|
||
prateekj117 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ForbiddenError({'source': ''}, 'Co-organizer access is required.').respond() | ||
|
|
||
| return decorated_function | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.