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: Order of any kind should not be deleted except by admin #6573

Merged
merged 4 commits into from
Dec 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,27 +431,13 @@ def after_update_object(self, order, data, view_kwargs):
send_notif_ticket_purchase_organizer(order.event.owner, order.invoice_number, order_url,
order.event.name, order.identifier)

def before_delete_object(self, order, view_kwargs):
"""
method to check for proper permissions for deleting
:param order:
:param view_kwargs:
:return:
"""
if not has_access('is_coorganizer', event_id=order.event.id):
raise ForbiddenException({'source': ''}, 'Access Forbidden')
elif order.amount and order.amount > 0 and (order.status == 'completed' or order.status == 'placed'):
raise ConflictException({'source': ''}, 'You cannot delete a placed/completed paid order.')
prateekj117 marked this conversation as resolved.
Show resolved Hide resolved

# This is to ensure that the permissions manager runs and hence changes the kwarg from order identifier to id.
decorators = (jwt_required, api.has_permission(
'auth_required', methods="PATCH,DELETE", model=Order),)
Copy link
Member

Choose a reason for hiding this comment

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

You've now removed the option of patching orders

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 Nopes. Tested.

Copy link
Member

Choose a reason for hiding this comment

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

Tested what? Can a user PATCH an order created by itself and only itself?

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 Yes.

if (not has_access('is_coorganizer', event_id=order.event_id)) and (not current_user.id == order.user_id):

decorators = (jwt_required, api.has_permission('is_admin', methods="DELETE", model=Order),)
schema = OrderSchema
data_layer = {'session': db.session,
'model': Order,
'methods': {
'before_update_object': before_update_object,
'before_delete_object': before_delete_object,
'before_get_object': before_get_object,
'after_update_object': after_update_object
}}
Expand Down