Skip to content

Commit

Permalink
fix: Check non-deleted events before user deletion (#7448)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamareebjamal authored Nov 15, 2020
1 parent af5d617 commit e631f57
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,13 @@ def before_update_object(self, user, data, view_kwargs):
if data.get('deleted_at') != user.deleted_at:
if has_access('is_user_itself', user_id=user.id) or has_access('is_admin'):
if data.get('deleted_at'):
if len(user.events) != 0:
event_exists = db.session.query(
Event.query.filter_by(deleted_at=None)
.join(Event.users)
.filter(User.id == user.id)
.exists()
).scalar()
if event_exists:
raise ForbiddenError(
{'source': ''},
"Users associated with events cannot be deleted",
Expand Down

0 comments on commit e631f57

Please sign in to comment.